10#define CT_FACTORY_BASE
13#include <unordered_map>
69template <
class T,
typename ... Args>
76 T*
create(
const std::string& name, Args... args) {
81 void reg(
const std::string& name, std::function<T*(Args...)> f) {
86 void addAlias(
const std::string& original,
const std::string& alias) {
87 if (!m_creators.count(original)) {
89 "Name '{}' not registered", original);
96 if (m_creators.count(name)) {
105 throw CanteraError(
"Factory::canonicalize",
"No such type: '{}'", name);
110 bool exists(
const std::string& name)
const {
111 return m_creators.count(name) ||
m_synonyms.count(name);
117 const std::string& alias) {
118 if (!m_creators.count(original)) {
120 "Name '{}' not registered", original);
126 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.
void warn_deprecated(const std::string &source, const AnyBase &node, const std::string &message)
A deprecation warning for syntax in an input file.