Go to the documentation of this file.
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;
std::unordered_map< std::string, std::string > m_deprecated_names
Map of deprecated synonyms to canonical names.
static std::vector< FactoryBase * > s_vFactoryRegistry
statically held list of Factories.
virtual void deleteFactory()=0
Virtual abstract function that deletes the factory.
bool exists(const std::string &name) const
Returns true if name is registered with this factory.
void addAlias(const std::string &original, const std::string &alias)
Add an alias for an existing registered 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 reg(const std::string &name, std::function< T *(Args...)> f)
Register a new object construction function.
virtual ~FactoryBase()
destructor
static void deleteFactories()
static function that deletes all factories in the internal registry maintained in a static variable
void addDeprecatedAlias(const std::string &original, const std::string &alias)
Add a deprecated alias for an existing registered type.
Base class for factories.
std::unordered_map< std::string, std::string > m_synonyms
Map of synonyms to canonical names.
Factory class that supports registering functions to create objects.
FactoryBase()
Constructor.
Base class for exceptions thrown by Cantera classes.
Namespace for the Cantera kernel.
std::string canonicalize(const std::string &name)
Get the canonical name registered for a type.