Cantera 2.6.0
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
Factory< T, Args > Class Template Reference

Factory class that supports registering functions to create objects. More...

#include <FactoryBase.h>

Inheritance diagram for Factory< T, Args >:
[legend]
Collaboration diagram for Factory< T, Args >:
[legend]

Public Member Functions

T * create (const std::string &name, Args... args)
 Create an object using the object construction function corresponding to "name" and the provided constructor arguments. More...
 
void reg (const std::string &name, std::function< T *(Args...)> f)
 Register a new object construction function. More...
 
void addAlias (const std::string &original, const std::string &alias)
 Add an alias for an existing registered type. More...
 
std::string canonicalize (const std::string &name)
 Get the canonical name registered for a type. More...
 
bool exists (const std::string &name) const
 Returns true if name is registered with this factory. More...
 
- Public Member Functions inherited from FactoryBase
virtual ~FactoryBase ()
 destructor More...
 

Protected Member Functions

void addDeprecatedAlias (const std::string &original, const std::string &alias)
 Add a deprecated alias for an existing registered type. More...
 
- Protected Member Functions inherited from FactoryBase
 FactoryBase ()
 Constructor. More...
 
virtual void deleteFactory ()=0
 Virtual abstract function that deletes the factory. More...
 

Private Attributes

std::unordered_map< std::string, std::function< T *(Args...)> > m_creators
 
std::unordered_map< std::string, std::string > m_synonyms
 Map of synonyms to canonical names. More...
 
std::unordered_map< std::string, std::string > m_deprecated_names
 Map of deprecated synonyms to canonical names. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from FactoryBase
static void deleteFactories ()
 static function that deletes all factories in the internal registry maintained in a static variable More...
 

Detailed Description

template<class T, typename ... Args>
class Cantera::Factory< T, Args >

Factory class that supports registering functions to create objects.

Template arguments for the class are the base type created by the factory, followed by the types of any arguments which need to be passed to the functions used to create objects, that is, arguments to the constructor.

Definition at line 70 of file FactoryBase.h.

Constructor & Destructor Documentation

◆ ~Factory()

virtual ~Factory ( )
inlinevirtual

Definition at line 72 of file FactoryBase.h.

Member Function Documentation

◆ create()

T * create ( const std::string &  name,
Args...  args 
)
inline

Create an object using the object construction function corresponding to "name" and the provided constructor arguments.

Definition at line 76 of file FactoryBase.h.

Referenced by Cantera::newThermo(), and Cantera::newThermoPhase().

◆ reg()

void reg ( const std::string &  name,
std::function< T *(Args...)>  f 
)
inline

Register a new object construction function.

Definition at line 81 of file FactoryBase.h.

◆ addAlias()

void addAlias ( const std::string &  original,
const std::string &  alias 
)
inline

Add an alias for an existing registered type.

Definition at line 86 of file FactoryBase.h.

References Factory< T, Args >::m_synonyms.

◆ canonicalize()

std::string canonicalize ( const std::string &  name)
inline

Get the canonical name registered for a type.

Definition at line 95 of file FactoryBase.h.

References Factory< T, Args >::m_deprecated_names, Factory< T, Args >::m_synonyms, and Cantera::warn_deprecated().

Referenced by ThermoPhase::getParameters(), and Transport::parameters().

◆ exists()

bool exists ( const std::string &  name) const
inline

Returns true if name is registered with this factory.

Definition at line 110 of file FactoryBase.h.

References Factory< T, Args >::m_synonyms.

◆ addDeprecatedAlias()

void addDeprecatedAlias ( const std::string &  original,
const std::string &  alias 
)
inlineprotected

Add a deprecated alias for an existing registered type.

Definition at line 116 of file FactoryBase.h.

References Factory< T, Args >::m_deprecated_names.

Member Data Documentation

◆ m_creators

std::unordered_map<std::string, std::function<T*(Args...)> > m_creators
private

Definition at line 126 of file FactoryBase.h.

◆ m_synonyms

std::unordered_map<std::string, std::string> m_synonyms
private

Map of synonyms to canonical names.

Definition at line 129 of file FactoryBase.h.

Referenced by Factory< T, Args >::addAlias(), Factory< T, Args >::canonicalize(), and Factory< T, Args >::exists().

◆ m_deprecated_names

std::unordered_map<std::string, std::string> m_deprecated_names
private

Map of deprecated synonyms to canonical names.

Use of these names will show a deprecation warning.

Definition at line 133 of file FactoryBase.h.

Referenced by Factory< T, Args >::addDeprecatedAlias(), and Factory< T, Args >::canonicalize().


The documentation for this class was generated from the following file: