List of all members | Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Member Functions | Static Private Attributes
utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy > Class Template Reference

Template for object factory. More...

#include "utl/ObjectFactory.h"

Inheritance diagram for utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >:
Inheritance graph
[legend]

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)
 
ObjectFactoryoperator= (const ObjectFactory &objectFactory)
 

Static Private Attributes

static RegistryTypefgRegistry = nullptr
 

Detailed Description

template<class ObjPtrType, typename IdentType, typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
class utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >

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.

Author
Lukas Nellen
Date
10 Mar 2004

Definition at line 71 of file ObjectFactory.h.

Member Typedef Documentation

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
typedef CreatType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::CreatorType

Definition at line 79 of file ObjectFactory.h.

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
typedef IdentType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::IdentifierType

Definition at line 78 of file ObjectFactory.h.

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
typedef RegistryType::const_iterator utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::Iterator

Definition at line 80 of file ObjectFactory.h.

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
typedef ObjPtrType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::ObjectPtrType

Definition at line 77 of file ObjectFactory.h.

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
typedef std::map<IdentType, CreatType> utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::RegistryType
private

Definition at line 74 of file ObjectFactory.h.

Constructor & Destructor Documentation

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::ObjectFactory ( )
template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::~ObjectFactory ( )
template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::ObjectFactory ( const ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy > &  objectFactory)
private

Member Function Documentation

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
static Iterator utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::Begin ( )
inlinestatic

Begin iterator over the internal map (read only)

Definition at line 153 of file ObjectFactory.h.

Referenced by fwk::RunController::GetRegisteredModuleNames(), and main().

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
static ObjectPtrType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::Create ( const IdentifierType id)
inlinestatic
template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
template<typename ArgumentType >
static ObjectPtrType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::Create ( const IdentifierType id,
const ArgumentType &  arg 
)
inlinestatic

Create an object (1-argument constructor)

Definition at line 120 of file ObjectFactory.h.

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
template<typename Argument1Type , typename Argument2Type >
static ObjectPtrType utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::Create ( const IdentifierType id,
const Argument1Type &  arg1,
const Argument2Type &  arg2 
)
inlinestatic

Create an object (2-argument constructor)

Definition at line 136 of file ObjectFactory.h.

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
static Iterator utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::End ( )
inlinestatic

End iterator over the internal map (read only)

Definition at line 163 of file ObjectFactory.h.

Referenced by fwk::RunController::GetRegisteredModuleNames(), and main().

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
static unsigned int utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::GetNumberOfCreators ( )
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().

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
ObjectFactory& utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::operator= ( const ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy > &  objectFactory)
private
template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
static bool utl::ObjectFactory< ObjPtrType, IdentType, CreatType, FactoryErrorPolicy >::Register ( const IdentifierType id,
const CreatorType creator 
)
inlinestatic

Register a factory function with an ID.

Definition at line 89 of file ObjectFactory.h.

Member Data Documentation

template<class ObjPtrType , typename IdentType , typename CreatType = ObjPtrType (*)(), class FactoryErrorPolicy = FactoryErrorIgnore<IdentType, ObjPtrType>>
ObjectFactory< ObjectPtrType, IdentifierType, CreatorType, FactoryErrorPolicy >::RegistryType * utl::ObjectFactory< ObjectPtrType, IdentifierType, CreatorType, FactoryErrorPolicy >::fgRegistry = nullptr
staticprivate

Definition at line 174 of file ObjectFactory.h.


The documentation for this class was generated from the following file:

, generated on Tue Sep 26 2023.