Templates::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy > Class Template Reference

Implementation of a generic object factory. More...

#include <factory.h>

List of all members.

Public Member Functions

 Factory ()
 Default constructor.
bool registerObject (IdentifierType id, ProductCreator creator)
 Registers the selected object.
bool unregisterObject (const IdentifierType &id) const
 Unregisters the selected object.
AbstractProduct * createObject (const IdentifierType &id) const
 Creates an instance of the selected object.
std::vector< IdentifierType > registeredObjects () const
 Returns a vector of all registered object IDs.

Private Types

typedef std::map
< IdentifierType,
ProductCreator > 
IdToProductMap
 Type of container used to store object IDs.

Private Attributes

IdToProductMap _associations
 Container used to store object IDs.


Detailed Description

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

Implementation of a generic object factory.

Implements "object factory" design pattern - creates instances of objects according to the given object identifier.


Member Typedef Documentation

template<class AbstractProduct, typename IdentifierType, typename ProductCreator = AbstractProduct *(*)(), template< typename, class > class FactoryErrorPolicy = Templates::DefaultFactoryError>
typedef std::map<IdentifierType, ProductCreator> Templates::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::IdToProductMap [private]

Type of container used to store object IDs.


Constructor & Destructor Documentation

template<class AbstractProduct, typename IdentifierType, typename ProductCreator = AbstractProduct *(*)(), template< typename, class > class FactoryErrorPolicy = Templates::DefaultFactoryError>
Templates::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::Factory (  )  [inline]

Default constructor.


Member Function Documentation

template<class AbstractProduct, typename IdentifierType, typename ProductCreator = AbstractProduct *(*)(), template< typename, class > class FactoryErrorPolicy = Templates::DefaultFactoryError>
bool Templates::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::registerObject ( IdentifierType  id,
ProductCreator  creator 
) [inline]

Registers the selected object.

Parameters:
[in] id Selected object ID.
[in] creator Creator that will be used to create instances.
Returns:
True if the registration was successfull, false otherwise.
Each ID can be registered only once (if someone tries to register the same object twice, this function will return false).

template<class AbstractProduct, typename IdentifierType, typename ProductCreator = AbstractProduct *(*)(), template< typename, class > class FactoryErrorPolicy = Templates::DefaultFactoryError>
bool Templates::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::unregisterObject ( const IdentifierType &  id  )  const [inline]

Unregisters the selected object.

Parameters:
[in] id Selected object ID.
Returns:
True if the registration was successfull, false otherwise.

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

Creates an instance of the selected object.

Parameters:
[in] id Selected object ID.
Returns:
Instance of the selected object.
Object instance is allocated on the heap, so you have to delete the allocated memory manually.

template<class AbstractProduct, typename IdentifierType, typename ProductCreator = AbstractProduct *(*)(), template< typename, class > class FactoryErrorPolicy = Templates::DefaultFactoryError>
std::vector<IdentifierType> Templates::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::registeredObjects (  )  const [inline]

Returns a vector of all registered object IDs.


Member Data Documentation

template<class AbstractProduct, typename IdentifierType, typename ProductCreator = AbstractProduct *(*)(), template< typename, class > class FactoryErrorPolicy = Templates::DefaultFactoryError>
IdToProductMap Templates::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::_associations [private]

Container used to store object IDs.


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

Generated on Sat Dec 20 19:21:24 2008 for PGR2008 by  doxygen 1.5.6