Feel++ 0.111.0-preview.14
Finite Element Embedded Library in C++
Feel::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy > Class Template Reference

Implements a generic object Factory. More...

+ Inheritance diagram for Feel::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >:
+ Collaboration diagram for Feel::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >:

Typedefs

typedef IdentifierType identifier_type
 
typedef AbstractProduct product_type
 
typedef ProductCreator creator_type
 
using result_type = typename creator_type::result_type
 
typedef FactoryErrorPolicy< identifier_type, product_type > super
 

Methods

bool registerProduct (const identifier_type &id, creator_type creator)
 Register a product. More...
 
bool unregisterProduct (const identifier_type &id)
 Unregister a product. More...
 
result_type createObject (const identifier_type &id)
 Create an object from a product registered in the Factory using identifier id. More...
 

Additional Inherited Members

- Static Public Member Functions inherited from Feel::FactoryDefaultError< IdentifierType, AbstractProduct >
static std::unique_ptr< AbstractProduct > onUnknownType (IdentifierType id)
 

Detailed Description

template<class AbstractProduct, typename IdentifierType, typename ProductCreator = std::function<std::unique_ptr<AbstractProduct>()>, template< typename, class > class FactoryErrorPolicy = FactoryDefaultError>
class Feel::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >

Implements a generic object Factory.

See also
FactoryDefaultError, FactoryClone, TypeInfo
Author
Christophe Prud'homme

Member Function Documentation

◆ createObject()

template<class AbstractProduct , typename IdentifierType , typename ProductCreator = std::function<std::unique_ptr<AbstractProduct>()>, template< typename, class > class FactoryErrorPolicy = FactoryDefaultError>
result_type Feel::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::createObject ( const identifier_type &  id)

Create an object from a product registered in the Factory using identifier id.

Parameters
ididentifier of the product to instantiate
Returns
the object associate with id

◆ registerProduct()

template<class AbstractProduct , typename IdentifierType , typename ProductCreator = std::function<std::unique_ptr<AbstractProduct>()>, template< typename, class > class FactoryErrorPolicy = FactoryDefaultError>
bool Feel::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::registerProduct ( const identifier_type &  id,
creator_type  creator 
)

Register a product.

A product is composed of an identifier (typically a std::string) and a functor that will create the associated object.

Parameters
ididentifier for the object to be registered
creatorthe functor that will create the registered object
Returns
true if registration went fine, false otherwise

◆ unregisterProduct()

template<class AbstractProduct , typename IdentifierType , typename ProductCreator = std::function<std::unique_ptr<AbstractProduct>()>, template< typename, class > class FactoryErrorPolicy = FactoryDefaultError>
bool Feel::Factory< AbstractProduct, IdentifierType, ProductCreator, FactoryErrorPolicy >::unregisterProduct ( const identifier_type &  id)

Unregister a product.

Parameters
id
See also
registerProduct
Returns
true if unregistration went fine, false otherwise