CFEL - ASG Software Suite  2.5.0
CASS
Public Types | Public Member Functions | Static Public Member Functions | Private Types | Private Attributes | List of all members
cass::Factory< Base > Class Template Reference

Factory for creating shared_pointers of classes derived from a base class. More...

#include <generic_factory.hpp>

+ Collaboration diagram for cass::Factory< Base >:

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_tinstanciatorMap_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...
 

Detailed Description

template<class Base>
class cass::Factory< Base >

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.

Note
The base class whose derived class should be instanciated through this factory need to typedef what the shared pointer to them looks like.
Template Parameters
BaseThe type of the base class.
Author
Lutz Foucar

Definition at line 80 of file generic_factory.hpp.

Member Typedef Documentation

template<class Base>
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.

template<class Base>
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.

template<class Base>
typedef Factory<Base>& cass::Factory< Base >::reference

define a reference to this factory

Definition at line 87 of file generic_factory.hpp.

template<class Base>
typedef Base::shared_pointer cass::Factory< Base >::shared_pointer
private

define a shared pointer of the base class

Definition at line 83 of file generic_factory.hpp.

Member Function Documentation

template<class Base>
template<class Derived >
char cass::Factory< Base >::addSingletonType ( const typename instanciatorMap_t::key_type &  type)
inline

register a derived singleton type to the map

Template Parameters
DerivedThe type of the derived class
Parameters
typethe Key that the type should have in the instanciator map

Definition at line 149 of file generic_factory.hpp.

References cass::Factory< Base >::_iMap.

template<class Base>
template<class Derived >
char cass::Factory< Base >::addType ( const typename instanciatorMap_t::key_type &  type)
inline

register a derived type to the map

Template Parameters
DerivedThe type of the derived class
Parameters
typethe Key that the type should have in the instanciator map

Definition at line 137 of file generic_factory.hpp.

References cass::Factory< Base >::_iMap.

template<class Base>
shared_pointer cass::Factory< Base >::create ( const typename instanciatorMap_t::key_type &  type)
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.

Returns
shared_ptr object of the base class.
Parameters
typeThe 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().

template<class Base>
static reference cass::Factory< Base >::instance ( )
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.

Note
if one wants to use this factory in the multithreadded part, one has to think about mutexing it.
Returns
reference to this instance

Definition at line 106 of file generic_factory.hpp.

Member Data Documentation

template<class Base>
instanciatorMap_t cass::Factory< Base >::_iMap
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().


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