iLab Neuromorphic Robotics Toolkit  0.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
nrt::Factory< Product, IDtype, ProductCreator, MetaDataType > Class Template Reference

#include <nrt/Core/Design/Factory.H>

template<class Product, typename IDtype, class ProductCreator = std::function<Product*()>, class MetaDataType = std::map<std::string, std::string>>
class nrt::Factory< Product, IDtype, ProductCreator, MetaDataType >

A generic factory.

The factory holds a collection of product creators, and each is given an ID. One can then create products for any of the registered IDs. In addition, one can store and later retrieve some metadata with each product creator.

Template Parameters
Productproduct type
IDtypetype used to represent IDs (typically, std:string)
ProductCreatorhow Product is created
MetaDataTypetype used to represent metadata
Examples:
tests/test-Factory.C.

Definition at line 61 of file Factory.H.

Inheritance diagram for nrt::Factory< Product, IDtype, ProductCreator, MetaDataType >:
nrt::Singleton< Factory< Product, IDtype, ProductCreator, MetaDataType > >

Public Member Functions

void registerType (IDtype const &id, ProductCreator creator, MetaDataType const &metaData=MetaDataType())
 Register a new product creator (and associated meta-data) under a new ID. More...
 
std::result_of< ProductCreator()>
::type 
create (IDtype const &id)
 Create a product for a given ID.
 
bool isRegistered (IDtype const &id)
 Check whether an ID has been registered.
 
MetaDataType const & getMetaData (IDtype const &id)
 Return the metadata for a given ID.
 
std::vector< IDtype > getIDs ()
 Return a list of all registered IDs.
 

Additional Inherited Members

- Static Public Member Functions inherited from nrt::Singleton< Factory< Product, IDtype, ProductCreator, MetaDataType > >
static Factory< Product,
IDtype, ProductCreator,
MetaDataType > & 
instance ()
 Get the global, unique instance of the class T. More...
 
- Protected Member Functions inherited from nrt::Singleton< Factory< Product, IDtype, ProductCreator, MetaDataType > >
 Singleton ()
 Only classes that inherit from Singleton can construct it via its protected default constructor.
 

Member Function Documentation

template<class Product , typename IDtype , class ProductCreator , class MetaDataType >
void nrt::Factory< Product, IDtype, ProductCreator, MetaDataType >::registerType ( IDtype const &  id,
ProductCreator  creator,
MetaDataType const &  metaData = MetaDataType() 
)

Register a new product creator (and associated meta-data) under a new ID.

Note
A copy of metaData is stored in the factory, so if your meta-data is large, you may want to define MetaDataType as an std::shared_ptr

Definition at line 50 of file FactoryImpl.H.

References nrt::splitString().


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