22 template<
class T,
class ... Args>
37 CreatorType creator) {
38 if (creators.find(name) != creators.end()) {
39 THROW(
"Class named " << name <<
" for base class " <<
40 T::getClassName() <<
" already registered with the factory.");
43 creators[
name] = creator;
52 auto constructor = [&](Args... args) {
54 pointer.reset(
new C(args...));
63 if (creators.find(name) == creators.end()) {
64 THROW(
"Could not find class named " << name <<
" for base class " <<
68 return creators[
name](args...);
77 std::map<std::string, CreatorType> creators;
bool registerClass(const std::string &name, CreatorType creator)
Definition: FactoryRegistry.hpp:36
Definition: FactoryRegistry.hpp:23
PointerType createInstance(const std::string &name, Args... args)
Creates a new instance of the class with the given name and arguments.
Definition: FactoryRegistry.hpp:62
std::shared_ptr< T > PointerType
Definition: FactoryRegistry.hpp:30
#define THROW(message)
Definition: Exception.hpp:27
std::function< PointerType(Args...)> CreatorType
Definition: FactoryRegistry.hpp:31
std::string name
Definition: EquationParameterFactory.cpp:39
Various utilities for mpi and cuda.
Definition: Factory.hpp:3
static FactoryRegistry & getInstance()
Gets the singleton instance of this class.
Definition: FactoryRegistry.hpp:72
bool registerClassWithOnlyConstructor(const std::string &name)
Definition: FactoryRegistry.hpp:51