EventAnalysis
1.3.0
|
Template factory class. More...
#include <Factory.h>
Public Member Functions | |
bool | RegisterBuilder (const std::string &builderName, T *(*objectBuilder)(ConstructorArgs...)) |
Register a builder for a class. More... | |
std::unique_ptr< T > | CreateObject (const std::string &name, ConstructorArgs... arguments) |
Create an object. More... | |
const std::vector< std::string > & | GetListOfRegisteredBuilders () |
Gets a vector containing the names of available registered builders. More... | |
Static Public Member Functions | |
static Factory & | GetInstance () |
Getter method for singleton pointer. More... | |
Private Types | |
typedef std::map< std::string, T *(*)(ConstructorArgs...)> | BuildersMap |
Private Member Functions | |
Factory () | |
Private Attributes | |
std::string | _factoryName |
BuildersMap | _builders |
std::vector< std::string > | _builderNames |
Template factory class.
This class is a generic factory, that can build all the derived classes of a given base class using constructors with any set of arguments. The first template argument is the base class of the objects built by the factory. Variadic template arguments are the constructor arguments. Actual object build is done by means of builder functions, each constructing instances of a given derived class. Builders must be registered providing a suitable builder function with a name (which can be the name of the built class itself).
|
private |
|
private |
std::unique_ptr< T > EA::Factory< T, ConstructorArgs >::CreateObject | ( | const std::string & | name, |
ConstructorArgs... | arguments | ||
) |
Create an object.
The builder is fetched by its name. If the desired builder is not available, the NULL pointer will be returned.
name | The name of the builder for the desired object. |
|
static |
Getter method for singleton pointer.
const std::vector< std::string > & EA::Factory< T, ConstructorArgs >::GetListOfRegisteredBuilders | ( | ) |
Gets a vector containing the names of available registered builders.
bool EA::Factory< T, ConstructorArgs >::RegisterBuilder | ( | const std::string & | builderName, |
T *(*)(ConstructorArgs...) | objectBuilder | ||
) |
Register a builder for a class.
builderName | The name of the builder. |
objectBuilder | Pointer to a builder function for the class. |
|
private |
|
private |
|
private |