CFEL - ASG Software Suite
2.5.0
CASS
|
Factory for creating shared_pointers of classes derived from a base class. More...
#include <generic_factory.hpp>
Public Types | |
typedef Factory< Base > & | reference |
define a reference to this factory More... | |
typedef std::tr1::function< shared_pointer()> | instanciator_t |
define how the instanctiator function should look like More... | |
typedef std::map< std::string, instanciator_t > | instanciatorMap_t |
define the map of instanciator functions More... | |
Public Member Functions | |
shared_pointer | create (const typename instanciatorMap_t::key_type &type) |
create an instance of the requested derived type More... | |
template<class Derived > | |
char | addType (const typename instanciatorMap_t::key_type &type) |
register a derived type to the map More... | |
template<class Derived > | |
char | addSingletonType (const typename instanciatorMap_t::key_type &type) |
register a derived singleton type to the map More... | |
Static Public Member Functions | |
static reference | instance () |
get an instance of the factory More... | |
Private Types | |
typedef Base::shared_pointer | shared_pointer |
define a shared pointer of the base class More... | |
Private Attributes | |
instanciatorMap_t | _iMap |
map human readable names to instanciators for the object More... | |
Factory for creating shared_pointers of classes derived from a base class.
One can use this class to facilitate the factory pattern. Instead of having to add possible instanciatable derived classes at one point, one can use this factory and let the derived class register itself to the factory. To do this one can either use the helper struct cass::Registrar or call the static member function Factory::addType.
Base | The type of the base class. |
Definition at line 80 of file generic_factory.hpp.
typedef std::tr1::function<shared_pointer()> cass::Factory< Base >::instanciator_t |
define how the instanctiator function should look like
Definition at line 90 of file generic_factory.hpp.
typedef std::map<std::string,instanciator_t> cass::Factory< Base >::instanciatorMap_t |
define the map of instanciator functions
Definition at line 93 of file generic_factory.hpp.
typedef Factory<Base>& cass::Factory< Base >::reference |
define a reference to this factory
Definition at line 87 of file generic_factory.hpp.
|
private |
define a shared pointer of the base class
Definition at line 83 of file generic_factory.hpp.
|
inline |
register a derived singleton type to the map
Derived | The type of the derived class |
type | the Key that the type should have in the instanciator map |
Definition at line 149 of file generic_factory.hpp.
References cass::Factory< Base >::_iMap.
|
inline |
register a derived type to the map
Derived | The type of the derived class |
type | the Key that the type should have in the instanciator map |
Definition at line 137 of file generic_factory.hpp.
References cass::Factory< Base >::_iMap.
|
inline |
create an instance of the requested derived type
looks up whether the requested type has been registered, if not throws an invalid_argument exception. If type is part of the map, then use the instanciator to create the instance. Return the instance in a shared_ptr object of the base class.
type | The type of the derived class that should be instanciated |
Definition at line 122 of file generic_factory.hpp.
References cass::Factory< Base >::_iMap.
Referenced by cass::TestInput::load().
|
inlinestatic |
get an instance of the factory
static function to make this a singleton. Creates a static instance of this class and returns a reference to it.
Definition at line 106 of file generic_factory.hpp.
|
private |
map human readable names to instanciators for the object
Definition at line 157 of file generic_factory.hpp.
Referenced by cass::Factory< Base >::addSingletonType(), cass::Factory< Base >::addType(), and cass::Factory< Base >::create().