Tekkotsu Homepage
Demos
Overview
Downloads
Dev. Resources
Reference
Credits

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

#include <FamilyFactory.h>

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

List of all members.


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.


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
void getTypeNames (std::set< NameT > &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

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

Classes

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

Member Typedef Documentation

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.

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 std::map<NameT,FactoryBaseT*> FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::factories_t [protected]

type of factories

Definition at line 87 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 (  )  [inline]

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 (  )  [inline, virtual]

destructor

Definition at line 45 of file FamilyFactory.h.


Member Function Documentation

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

clears types and fills in the currently registered type identifiers

Definition at line 92 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 [inline]

returns the number of currently registered type identifiers

Definition at line 55 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 T>
const NameT& FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::registerType ( const NameT &  type  )  [inline]

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

Definition at line 58 of file FamilyFactory.h.

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

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 
) [inline]

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

Definition at line 99 of file FamilyFactory.h.

Referenced by DataEvent< T, TID >::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>
FamilyT* FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::create ( const NameT &  type  )  const [inline]

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 65 of file FamilyFactory.h.

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

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 [inline]

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 70 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 [inline]

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 75 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, typename A3>
FamilyT* FamilyFactory< FamilyT, NameT, FactoryBaseT, FactoryT >::create ( const NameT &  type,
const A1 &  a1,
const A2 &  a2,
const A3 &  a3 
) const [inline]

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 80 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 [inline, protected]

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

Definition at line 110 of file FamilyFactory.h.

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


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 v4.0
Generated Thu Nov 22 00:58:24 2007 by Doxygen 1.5.4