|
A template that can be used as a superclass of a class hierarchy that wants to provide a factory method which allows instantiation of objects based on a string identifier. More...
#include <ArmarXCore/core/system/AbstractFactoryMethod.h>
Classes | |
struct | SubClassRegistry |
A helper struct to allow static initialisation of the subclass lookup table. More... | |
Public Types | |
using | BaseFactory = Base |
using | ConstructorArg = constructorArg |
typedef SharedPointerType(* | initialisationFunction) (constructorArg) |
The function pointer type of subclass initialisation functions. More... | |
using | SharedPointerType = SharedPointer |
Public Member Functions | |
std::string | getClassName () |
getClassName returns the name that this instance was generated with. More... | |
Static Public Member Functions | |
static SharedPointerType | createInstance (constructorArg) |
Initialisation function which needs to be provided by every subclass. More... | |
static SharedPointerType | fromName (const std::string &name, constructorArg params) |
Function which can be used to retrieve an object specified by string name. More... | |
static std::vector< std::string > | getAvailableClasses () |
getAvailableClasses retrieves a list of all registered classes as their string-representation. More... | |
static std::string | getName () |
Returns the class's name. More... | |
static void | registerClass (const std::string &name, initialisationFunction init) |
Statically called by subclasses to register their name and initialisation function so they can be found by fromName. More... | |
A template that can be used as a superclass of a class hierarchy that wants to provide a factory method which allows instantiation of objects based on a string identifier.
The first template argument is the base class of your class hierarchy. The second argument is the parameter type for the initialisation function each subclass has to provide. If you need multiple constructor arguments it is recommended to use a boost::tuple.
Definition at line 46 of file AbstractFactoryMethod.h.
using BaseFactory = Base |
Definition at line 54 of file AbstractFactoryMethod.h.
using ConstructorArg = constructorArg |
Definition at line 55 of file AbstractFactoryMethod.h.
typedef SharedPointerType(* initialisationFunction(constructorArg) |
The function pointer type of subclass initialisation functions.
This matches the createInstance method.
Definition at line 71 of file AbstractFactoryMethod.h.
using SharedPointerType = SharedPointer |
Definition at line 56 of file AbstractFactoryMethod.h.
|
inlinestatic |
Initialisation function which needs to be provided by every subclass.
It calls the constructor and returns a shared_ptr to the resulting object.
Definition at line 127 of file AbstractFactoryMethod.h.
|
inlinestatic |
Function which can be used to retrieve an object specified by string name.
Definition at line 76 of file AbstractFactoryMethod.h.
|
inlinestatic |
getAvailableClasses retrieves a list of all registered classes as their string-representation.
Definition at line 99 of file AbstractFactoryMethod.h.
|
inline |
getClassName returns the name that this instance was generated with.
Definition at line 62 of file AbstractFactoryMethod.h.
|
inlinestatic |
Returns the class's name.
This is used to identify the class which the user requests an instance of.
Definition at line 117 of file AbstractFactoryMethod.h.
|
inlinestatic |
Statically called by subclasses to register their name and initialisation function so they can be found by fromName.
Definition at line 138 of file AbstractFactoryMethod.h.