Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT > Class Template Reference

A class which can track a set of subclass types (with shared base class FamilyT), generating new instances on demand based on some form of identifier (the NameT template parameter). More...

#include <FamilyFactory.h>

Inheritance diagram for FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >:

Detailed Description

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
class FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >

A class which can track a set of subclass types (with shared base class FamilyT), generating new instances on demand based on some form of identifier (the NameT template parameter).

Register your class via registerType() or registerFactory(), and then instantiate it later with a call to create(). Note that you have a variety of options to control how the product is constructed via your choice of the FactoryBaseT and FactoryT template parameters.

The FactoryBaseT defines the interface, exposing available factory functor calls which return the shared base class. The FactoryT is a template template parameter which indicates the factory to be created for each call to registerType(). This should take the type to be produced as its template parameter, and implement the interface expected by FactoryBaseT.

By default, FamilyFactory looks for a type named 'Factory' within the FactoryBaseT namespace. This parameter would be ignored if you only ever call registerFactory, and pass your own factory instances.

A cute way to automatically trigger type registration is to define a static member of your class, and then call registerType() or registerFactory() for its initialization.

See Factories.h for some basic factory types.

Definition at line 30 of file FamilyFactory.h.

List of all members.

Classes

struct  FactoryType
 allows indirect access to create factory classes More...

Public Types

typedef FamilyT FamilyType
 allows indirect access to the product family type
typedef NameT NameType
 allows indirect access to the product class name type
typedef FactoryBaseT FactoryBaseType
 allows indirect access to the factory base class

Public Member Functions

 FamilyFactory ()
 default constructor
virtual ~FamilyFactory ()
 destructor
template<typename N >
void getTypeNames (std::set< N > &types) const
 clears types and fills in the currently registered type identifiers
unsigned int getNumTypes () const
 returns the number of currently registered type identifiers
template<typename T >
const NameT & registerType (const NameT &type)
 creates a factory for the specified type from FactoryT and registers it as type
const NameT & registerFactory (const NameT &type, FactoryBaseT *f)
 registers the specified factory for producing objects known by type; FamilyFactory assumes responsibilty for deallocation of f
FamilyT * create (const NameT &type) const
 requests a new instance of the specified type be created, without passing any arguments to the factory
template<typename A1 >
FamilyT * create (const NameT &type, const A1 &a1) const
 requests a new instance of the specified type be created, passing a single argument to the factory
template<typename A1 , typename A2 >
FamilyT * create (const NameT &type, const A1 &a1, const A2 &a2) const
 requests a new instance of the specified type be created, passing two arguments to the factory
template<typename A1 , typename A2 , typename A3 >
FamilyT * create (const NameT &type, const A1 &a1, const A2 &a2, const A3 &a3) const
 requests a new instance of the specified type be created, passing three arguments to the factory

Static Public Member Functions

static FamilyFactorygetRegistry ()
 returns a singleton factory for the current template arguments... be careful that clients use the same templates as those used to register

Protected Types

typedef std::map< NameT,
FactoryBaseT * > 
factories_t
 type of factories

Protected Member Functions

FactoryBaseT * lookupFactory (const NameT &type) const
 utility function to see if type has been registered and return it, or NULL if not found

Protected Attributes

factories_t factories
 storage for type identifier to factory mapping

Member Typedef Documentation

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef std::map<NameT,FactoryBaseT*> FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::factories_t [protected]

type of factories

Definition at line 90 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef FactoryBaseT FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::FactoryBaseType

allows indirect access to the factory base class

Reimplemented in InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >.

Definition at line 37 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef FamilyT FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::FamilyType

allows indirect access to the product family type

Reimplemented in InstanceTracker< FamilyT, ClassNameT, FactoryBaseT, FactoryT >.

Definition at line 33 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
typedef NameT FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::NameType

allows indirect access to the product class name type

Definition at line 35 of file FamilyFactory.h.


Constructor & Destructor Documentation

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::FamilyFactory (  ) 

default constructor

Definition at line 42 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
virtual FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::~FamilyFactory (  )  [virtual]

destructor

Definition at line 45 of file FamilyFactory.h.


Member Function Documentation

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
template<typename A1 , typename A2 , typename A3 >
FamilyT* FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::create ( const NameT &  type,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3 
) const

requests a new instance of the specified type be created, passing three arguments to the factory

Note that the factory interface chosen by FactoryBaseT may not actually provide such a call!

Definition at line 83 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
template<typename A1 , typename A2 >
FamilyT* FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::create ( const NameT &  type,
const A1 &  a1,
const A2 &  a2 
) const

requests a new instance of the specified type be created, passing two arguments to the factory

Note that the factory interface chosen by FactoryBaseT may not actually provide such a call!

Definition at line 78 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
template<typename A1 >
FamilyT* FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::create ( const NameT &  type,
const A1 &  a1 
) const

requests a new instance of the specified type be created, passing a single argument to the factory

Note that the factory interface chosen by FactoryBaseT may not actually provide such a call!

Definition at line 73 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
FamilyT* FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::create ( const NameT &  type  )  const

requests a new instance of the specified type be created, without passing any arguments to the factory

Note that the factory interface chosen by FactoryBaseT may not actually provide such a call!

Definition at line 68 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
unsigned int FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::getNumTypes (  )  const

returns the number of currently registered type identifiers

Definition at line 58 of file FamilyFactory.h.

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
static FamilyFactory& FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::getRegistry (  )  [static]

returns a singleton factory for the current template arguments... be careful that clients use the same templates as those used to register

Definition at line 52 of file FamilyFactory.h.

template<class FamilyT , typename NameT , class FactoryBaseT , template< class U > class FactoryT>
template<typename N >
void FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::getTypeNames ( std::set< N > &  types  )  const

clears types and fills in the currently registered type identifiers

Definition at line 96 of file FamilyFactory.h.

template<class FamilyT , typename NameT, class FactoryBaseT , template< class U > class FactoryT>
FactoryBaseT * FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::lookupFactory ( const NameT &  type  )  const [protected]

utility function to see if type has been registered and return it, or NULL if not found

Definition at line 114 of file FamilyFactory.h.

Referenced by FamilyFactory< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::create().

template<class FamilyT , typename NameT, class FactoryBaseT, template< class U > class FactoryT>
const NameT & FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::registerFactory ( const NameT &  type,
FactoryBaseT *  f 
)

registers the specified factory for producing objects known by type; FamilyFactory assumes responsibilty for deallocation of f

Definition at line 103 of file FamilyFactory.h.

Referenced by DataEvent< T >::registerDataType(), and FamilyFactory< FamilyT, ClassNameT, FactoryBaseT, FactoryT >::registerType().

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
template<typename T >
const NameT& FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::registerType ( const NameT &  type  ) 

creates a factory for the specified type from FactoryT and registers it as type

Definition at line 61 of file FamilyFactory.h.

Referenced by DataEvent< T >::registerDataType().


Member Data Documentation

template<class FamilyT, typename NameT = std::string, class FactoryBaseT = Factory0Arg<FamilyT>, template< class U > class FactoryT = FactoryBaseT::template Factory>
factories_t FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::factories [protected]

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

Tekkotsu v5.1CVS
Generated Mon May 9 04:59:07 2016 by Doxygen 1.6.3