46 template <
typename Base,
47 typename constructorArg,
48 typename SharedPointer = std::shared_ptr<Base>>
54 std::string className;
82 fromName(
const std::string& name, constructorArg params)
84 if (subTypes()->find(name) == subTypes()->end())
86 ARMARX_DEBUG <<
"factory does not manage a type of name " << name;
91 ARMARX_DEBUG <<
"done initializing object for name " << name;
94 result->className = name;
104 static std::vector<std::string>
107 std::vector<std::string> result;
108 typename std::map<std::string, initialisationFunction>::iterator it =
111 for (; it != subTypes()->end(); ++it)
113 result.push_back(it->first);
126 return "AbstractFactoryMethod";
147 ARMARX_VERBOSE <<
typeid(Base).name() <<
"Registering factory '" << name
150 (*subTypes())[name] = init;
160 Base::registerClass(name, init);
171 static std::shared_ptr<std::map<std::string, initialisationFunction>>
174 static std::shared_ptr<std::map<std::string, initialisationFunction>> subTypes(
175 new std::map<std::string, initialisationFunction>);
A template that can be used as a superclass of a class hierarchy that wants to provide a factory meth...
SharedPointerType(* initialisationFunction)(constructorArg)
The function pointer type of subclass initialisation functions.
std::string getClassName()
getClassName returns the name that this instance was generated with.
constructorArg ConstructorArg
static void registerClass(const std::string &name, initialisationFunction init)
Statically called by subclasses to register their name and initialisation function so they can be fou...
SharedPointer SharedPointerType
static SharedPointerType fromName(const std::string &name, constructorArg params)
Function which can be used to retrieve an object specified by string name.
static std::string getName()
Returns the class's name.
static std::vector< std::string > getAvailableClasses()
getAvailableClasses retrieves a list of all registered classes as their string-representation.
static SharedPointerType createInstance(constructorArg)
Initialisation function which needs to be provided by every subclass.
#define ARMARX_DEBUG
The logging level for output that is only interesting while debugging.
#define ARMARX_VERBOSE
The logging level for verbose information.
This file offers overloads of toIce() and fromIce() functions for STL container types.
std::string GetTypeString(const std::type_info &tinf, bool withoutNamespaceSpecifier=false)
SubClassRegistry(const std::string &name, initialisationFunction init)