Util--  1.1
Public Member Functions | Friends | List of all members
utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId > Class Template Reference

Generic Factory implementation. More...

#include <utilmm/types/factory.hh>

Inheritance diagram for utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >:
Inheritance graph
[legend]
Collaboration diagram for utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >:
Collaboration graph
[legend]

Public Member Functions

bool add (id_param id, creator_param creator)
 Add a new production method. More...
 
bool remove (id_param id)
 Remove a production method. More...
 
bool make_alias (id_param from, id_param to)
 Alias creation. More...
 
Result create (id_param id)
 Creation method. More...
 
bool check_entry (id_param id) const
 Check for entry. More...
 
ProductCreator const & get_creator (id_param id) const
 Creation method access. More...
 

Friends

template<class Ty >
class singleton::wrapper
 

Detailed Description

template<class AbstractProduct, typename IdentifierType, typename Result, typename ProductCreator, template< typename, class, typename > class FactoryErrorPolicy, class OrderId>
class utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >

Generic Factory implementation.

This class offers a generic implementation of thze factory design pattern.

A factory is a producer of classes of a special base type. The production will depend on the request.

Parameters
AbstractProductBase type for the produced instances.
IdentifierTypeType of the production method identifiers.
ResultType of the result (AbstractProduct*).
ProductCreatorType of the creation methods (Result(*)()).
FactoryErrorPolicyError management policy (utilmm::factory_toolbox::error)
OrderIdAn order between IdentifierType (std::less<IdentifierType>)
Note
this class is a singleton
See Also
utilmm::singleton::use
Author
Frédéric Py fpy@l.nosp@m.aas..nosp@m.fr

Member Function Documentation

template<class AbstractProduct , typename IdentifierType , typename Result , typename ProductCreator , template< typename, class, typename > class FactoryErrorPolicy, class OrderId >
bool utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::add ( id_param  id,
creator_param  creator 
)
inline

Add a new production method.

This method add a new production method to the factory.

Parameters
idIdentifier for the production method
creatorProduction method.
Return values
trueif the new creation method was added
falseif there was already a creation method with id

After this operation client can request for product having id as identifeir

Referenced by utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::make_alias().

template<class AbstractProduct , typename IdentifierType , typename Result , typename ProductCreator , template< typename, class, typename > class FactoryErrorPolicy, class OrderId >
bool utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::check_entry ( id_param  id) const
inline

Check for entry.

Parameters
idan identifer

This function test if there's a creation method attched to id

Return values
trueIf thered's a creation method attched to id
falseelse
template<class AbstractProduct , typename IdentifierType , typename Result , typename ProductCreator , template< typename, class, typename > class FactoryErrorPolicy, class OrderId >
Result utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::create ( id_param  id)
inline

Creation method.

Parameters
idan identifer

Create a new product using the cration method attched to id

Returns
The created product
Note
If there's no creation method attched to id this function will call FactoryErrorPolicy::on_unknown_id
template<class AbstractProduct , typename IdentifierType , typename Result , typename ProductCreator , template< typename, class, typename > class FactoryErrorPolicy, class OrderId >
ProductCreator const& utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::get_creator ( id_param  id) const
inline

Creation method access.

Parameters
idAn identifier

This function get the creation mathod attched to id

Returns
A creation method
Note
In case there's no crezation method attached to id this function will call FactoryErrorPolicy::on_unknown_type
template<class AbstractProduct , typename IdentifierType , typename Result , typename ProductCreator , template< typename, class, typename > class FactoryErrorPolicy, class OrderId >
bool utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::make_alias ( id_param  from,
id_param  to 
)
inline

Alias creation.

Make an alias identifer for a creation method

Parameters
fromThe alias identifier
toan identifer

This method will try to create an alias to cration method named to

Return values
trueif the alias was created
falseelse

References utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::add().

template<class AbstractProduct , typename IdentifierType , typename Result , typename ProductCreator , template< typename, class, typename > class FactoryErrorPolicy, class OrderId >
bool utilmm::factory< AbstractProduct, IdentifierType, Result, ProductCreator, FactoryErrorPolicy, OrderId >::remove ( id_param  id)
inline

Remove a production method.

This method allow user to remove a creation method from the factory

Parameters
idThe identifier of the creation method to remove
Return values
trueif the creation method was removed.
falseif there was no creation method attached to id

Friends And Related Function Documentation

template<class AbstractProduct , typename IdentifierType , typename Result , typename ProductCreator , template< typename, class, typename > class FactoryErrorPolicy, class OrderId >
template<class Ty >
friend class singleton::wrapper
friend

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

Generated on Tue Oct 9 2018 10:12:46 for Util-- by doxygen 1.8.6
SourceForge.net Project Page