10#define CT_FACTORY_BASE
13#include <unordered_map>
68template <
class T,
typename ... Args>
75 T*
create(
const string& name, Args... args) {
80 void reg(
const string& name, function<T*(Args...)> f) {
85 void addAlias(
const string& original,
const string& alias) {
86 if (!m_creators.count(original)) {
88 "Name '{}' not registered", original);
95 if (m_creators.count(name)) {
101 fmt::format(
"Model name '{}' is deprecated. Use '{}' instead.",
105 throw CanteraError(
"Factory::canonicalize",
"No such type: '{}'", name);
111 return m_creators.count(name) ||
m_synonyms.count(name);
117 const string& alias) {
118 if (!m_creators.count(original)) {
120 "Name '{}' not registered", original);
126 std::unordered_map<string, 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 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.
T * create(const string &name, Args... args)
Create an object using the object construction function corresponding to "name" and the provided cons...
void reg(const string &name, function< T *(Args...)> f)
Register a new object construction function.
std::unordered_map< string, string > m_synonyms
Map of synonyms to canonical names.
std::unordered_map< string, string > m_deprecated_names
Map of deprecated synonyms to canonical names.
bool exists(const string &name) const
Returns true if name is registered with this factory.
void addAlias(const string &original, const string &alias)
Add an alias for an existing registered type.
string canonicalize(const string &name)
Get the canonical name registered for a type.
void addDeprecatedAlias(const string &original, const string &alias)
Add a deprecated alias for an existing registered type.
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 and logging,...
Namespace for the Cantera kernel.
void warn_deprecated(const string &source, const AnyBase &node, const string &message)
A deprecation warning for syntax in an input file.