Template for object factory. More...
#include "utl/ObjectFactory.h"
Public Types | |
typedef CreatType | CreatorType |
typedef IdentType | IdentifierType |
typedef RegistryType::const_iterator | Iterator |
typedef ObjPtrType | ObjectPtrType |
Public Member Functions | |
ObjectFactory () | |
~ObjectFactory () | |
Static Public Member Functions | |
static Iterator | Begin () |
Begin iterator over the internal map (read only) More... | |
static ObjectPtrType | Create (const IdentifierType &id) |
Create an object (0-argument constructor) More... | |
template<typename ArgumentType > | |
static ObjectPtrType | Create (const IdentifierType &id, const ArgumentType &arg) |
Create an object (1-argument constructor) More... | |
template<typename Argument1Type , typename Argument2Type > | |
static ObjectPtrType | Create (const IdentifierType &id, const Argument1Type &arg1, const Argument2Type &arg2) |
Create an object (2-argument constructor) More... | |
static Iterator | End () |
End iterator over the internal map (read only) More... | |
static unsigned int | GetNumberOfCreators () |
Get number of object types know to this factory. More... | |
static bool | Register (const IdentifierType &id, const CreatorType &creator) |
Register a factory function with an ID. More... | |
Private Types | |
typedef std::map< IdentType, CreatType > | RegistryType |
Private Member Functions | |
ObjectFactory (const ObjectFactory &objectFactory) | |
ObjectFactory & | operator= (const ObjectFactory &objectFactory) |
Static Private Attributes | |
static RegistryType * | fgRegistry = nullptr |
Template for object factory.
The implementation relies on static objects to implement a mono-state like structure without having to instantiate the factory.
The template allows for factory functions or functors with 0, 1, and 2 arguments. It is trivial to add more creation functions to allow for more arguments. It is checked at compile time that the CreatorType and the form of the Create call match.
The design is inspired by the object factory in the book Modern C++ Design by Andrei Alexandrescu.
Definition at line 71 of file ObjectFactory.h.
typedef CreatType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::CreatorType |
Definition at line 79 of file ObjectFactory.h.
typedef IdentType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::IdentifierType |
Definition at line 78 of file ObjectFactory.h.
typedef RegistryType::const_iterator utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::Iterator |
Definition at line 80 of file ObjectFactory.h.
typedef ObjPtrType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::ObjectPtrType |
Definition at line 77 of file ObjectFactory.h.
|
private |
Definition at line 74 of file ObjectFactory.h.
utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::ObjectFactory | ( | ) |
utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::~ObjectFactory | ( | ) |
|
private |
|
inlinestatic |
Begin iterator over the internal map (read only)
Definition at line 153 of file ObjectFactory.h.
Referenced by fwk::RunController::GetRegisteredModuleNames(), and main().
|
inlinestatic |
Create an object (0-argument constructor)
Definition at line 104 of file ObjectFactory.h.
Referenced by fwk::RunController::GetModule(), fwk::RunController::GetRegisteredModuleNames(), fwk::RunController::HasModule(), io::CorsikaShowerFile::SetHeaderTrailer(), evt::ShowerSimData::SetPrimaryParticle(), testParticlePropertiesFactory::testCreate(), and utl::UnregisteredParticlePropertyPolicy::Unregistered().
|
inlinestatic |
Create an object (1-argument constructor)
Definition at line 120 of file ObjectFactory.h.
|
inlinestatic |
Create an object (2-argument constructor)
Definition at line 136 of file ObjectFactory.h.
|
inlinestatic |
End iterator over the internal map (read only)
Definition at line 163 of file ObjectFactory.h.
Referenced by fwk::RunController::GetRegisteredModuleNames(), and main().
|
inlinestatic |
Get number of object types know to this factory.
Definition at line 98 of file ObjectFactory.h.
Referenced by fwk::RunController::GetNumberOfRegisteredModules(), and utl::UnregisteredParticlePropertyPolicy::Unregistered().
|
private |
|
inlinestatic |
Register a factory function with an ID.
Definition at line 89 of file ObjectFactory.h.
|
staticprivate |
Definition at line 174 of file ObjectFactory.h.