Main Page   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Related Pages   Examples  

vpr::Factory Class Template Reference

Implements generic Factory pattern. More...

#include <Factory.h>

List of all members.

Public Methods

bool registerCreator (const IdentifierType &id, ProductCreator creator)
bool unregisterCreator (const IdentifierType &id)
bool isRegistered (const IdentifierType &id)
AbstractProduct * createObject (const IdentifierType &id)

Protected Types

typedef std::map< IdentifierType,
ProductCreator > 
CreatorMap

Protected Attributes

CreatorMap mCreatorMap


Detailed Description

template<class AbstractProduct, class IdentifierType, typename ProductCreator = AbstractProduct* (*)(), class FactoryErrorPolicy = NullFactoryError<IdentifierType, AbstractProduct>>
class vpr::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >

Implements generic Factory pattern.

AbstractProduct: The base class for the hierarchy for the object factory IndentifierType: The id for indexing the creators (must be sortable) ProductCreator: The callable entity that creates objects. Must support: AbstractProduct* operator(); (ex: functions, functors, classes) default: Simple function of type: AbstractProduct* func() { } FactoryErrorPolicy: The handler for failed lookups. Must support: FactoryErrorImpl<IdentifierType, AbstractProduct> fErrorImpl; AbstractProduct* p = fErrorImpl.onUnknownType(id)

Definition at line 85 of file Factory.h.


Member Typedef Documentation

template<class AbstractProduct, class IdentifierType, typename ProductCreator = AbstractProduct* (*)(), class FactoryErrorPolicy = NullFactoryError<IdentifierType, AbstractProduct>>
typedef std::map<IdentifierType, ProductCreator> vpr::Factory::CreatorMap [protected]
 

Definition at line 118 of file Factory.h.


Member Function Documentation

template<class AbstractProduct, class IdentifierType, typename ProductCreator = AbstractProduct* (*)(), class FactoryErrorPolicy = NullFactoryError<IdentifierType, AbstractProduct>>
bool vpr::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::registerCreator const IdentifierType &    id,
ProductCreator    creator
[inline]
 

Definition at line 88 of file Factory.h.

References mCreatorMap.

00089    {
00090       // XXX: It would probably be better to use CreatorMap::value_type here.
00091       std::pair<const IdentifierType, ProductCreator> p = std::make_pair(id, creator);
00092       return mCreatorMap.insert(p).second;
00093    }

template<class AbstractProduct, class IdentifierType, typename ProductCreator = AbstractProduct* (*)(), class FactoryErrorPolicy = NullFactoryError<IdentifierType, AbstractProduct>>
bool vpr::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::unregisterCreator const IdentifierType &    id [inline]
 

Definition at line 95 of file Factory.h.

References mCreatorMap, and unregisterCreator.

Referenced by unregisterCreator.

00096    {
00097       return (mCreatorMap.erase(id) == 1);   // return (num_erased == 1)
00098    }

template<class AbstractProduct, class IdentifierType, typename ProductCreator = AbstractProduct* (*)(), class FactoryErrorPolicy = NullFactoryError<IdentifierType, AbstractProduct>>
bool vpr::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::isRegistered const IdentifierType &    id [inline]
 

Definition at line 99 of file Factory.h.

References mCreatorMap.

00100    {
00101       return ( mCreatorMap.find(id) != mCreatorMap.end());
00102    }

template<class AbstractProduct, class IdentifierType, typename ProductCreator = AbstractProduct* (*)(), class FactoryErrorPolicy = NullFactoryError<IdentifierType, AbstractProduct>>
AbstractProduct* vpr::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::createObject const IdentifierType &    id [inline]
 

Definition at line 104 of file Factory.h.

References mCreatorMap.

00105    {
00106       typename CreatorMap::const_iterator i = mCreatorMap.find(id);
00107       if(i != mCreatorMap.end())
00108       {
00109          return (i->second)();
00110       }
00111 
00112       return onUnknownType(id);     // Calls template method from FactoryErrorPolicy<>
00113    }


Member Data Documentation

template<class AbstractProduct, class IdentifierType, typename ProductCreator = AbstractProduct* (*)(), class FactoryErrorPolicy = NullFactoryError<IdentifierType, AbstractProduct>>
CreatorMap vpr::Factory::mCreatorMap [protected]
 

Definition at line 119 of file Factory.h.

Referenced by createObject, isRegistered, registerCreator, and unregisterCreator.


The documentation for this class was generated from the following file:
Generated on Sun May 2 14:47:16 2004 for VR Juggler Portable Runtime by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002