9 #ifndef CT_FACTORY_BASE 10 #define CT_FACTORY_BASE 14 #include <unordered_map> 70 template <
class T,
typename ... Args>
77 T*
create(std::string name, Args... args) {
79 return m_creators.at(name)(args...);
80 }
catch (std::out_of_range&) {
82 return m_creators.at(
m_synonyms.at(name))(args...);
88 throw CanteraError(
"Factory::create",
"No such type: '{}'", name);
94 void reg(
const std::string& name, std::function<T*(Args...)> f) {
99 std::unordered_map<std::string, std::function<T*(Args...)>> m_creators;
virtual ~FactoryBase()
destructor
FactoryBase()
Constructor.
void warn_deprecated(const std::string &method, const std::string &extra)
Print a warning indicating that method is deprecated.
Base class for factories.
This file contains definitions for utility functions and text for modules, inputfiles, logs, textlogs, (see Input File Handling, Diagnostic Output, and Writing messages to the screen).
virtual void deleteFactory()=0
Virtual abstract function that deletes the factory.
std::unordered_map< std::string, std::string > m_deprecated_names
Map of deprecated synonyms to canonical names.
T * create(std::string name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
static void deleteFactories()
static function that deletes all factories in the internal registry maintained in a static variable ...
Base class for exceptions thrown by Cantera classes.
Factory class that supports registering functions to create objects.
void reg(const std::string &name, std::function< T *(Args...)> f)
Register a new object construction function.
static std::vector< FactoryBase * > s_vFactoryRegistry
statically held list of Factories.
Namespace for the Cantera kernel.
std::unordered_map< std::string, std::string > m_synonyms
Map of synonyms to canonical names.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...