9 #ifndef CT_FACTORY_BASE
10 #define CT_FACTORY_BASE
14 #include <unordered_map>
70 template <
class T,
typename ... Args>
77 T*
create(
const std::string& name, Args... args) {
82 void reg(
const std::string& name, std::function<T*(Args...)> f) {
87 void addAlias(
const std::string& original,
const std::string& alias) {
88 if (!m_creators.count(original)) {
90 "Name '{}' not registered", original);
97 if (m_creators.count(name)) {
106 throw CanteraError(
"Factory::canonicalize",
"No such type: '{}'", name);
111 bool exists(
const std::string& name)
const {
112 return m_creators.count(name) ||
m_synonyms.count(name);
118 const std::string& alias) {
119 if (!m_creators.count(original)) {
121 "Name '{}' not registered", original);
127 std::unordered_map<std::string, std::function<T*(Args...)>> m_creators;
Base class for exceptions thrown by Cantera classes.
Base class for factories.
virtual void deleteFactory()=0
Virtual abstract function that deletes the factory.
static std::vector< FactoryBase * > s_vFactoryRegistry
statically held list of Factories.
virtual ~FactoryBase()
destructor
FactoryBase()
Constructor.
static void deleteFactories()
static function that deletes all factories in the internal registry maintained in a static variable
Factory class that supports registering functions to create objects.
void addDeprecatedAlias(const std::string &original, const std::string &alias)
Add a deprecated alias for an existing registered type.
bool exists(const std::string &name) const
Returns true if name is registered with this factory.
std::string canonicalize(const std::string &name)
Get the canonical name registered for a type.
T * create(const std::string &name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
void addAlias(const std::string &original, const std::string &alias)
Add an alias for an existing registered type.
std::unordered_map< std::string, std::string > m_deprecated_names
Map of deprecated synonyms to canonical names.
std::unordered_map< std::string, std::string > m_synonyms
Map of synonyms to canonical names.
void reg(const std::string &name, std::function< T *(Args...)> f)
Register a new object construction function.
Definitions for the classes that are thrown when Cantera experiences an error condition (also contain...
This file contains definitions for utility functions and text for modules, inputfiles,...
Namespace for the Cantera kernel.