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

#include <nrt/Core/Model/ComponentFactory.H>

template<typename IDtype = std::string, typename Creator = std::function<std::shared_ptr<nrt::Component>(nrt::Component * parent, std::string const & instanceName)>, class MetaDataType = std::map<std::string, std::string>>
class nrt::ComponentFactory< IDtype, Creator, MetaDataType >

A factory for objects that derive from nrt::Component.

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
IDtypetype used to represent IDs (typically, std:string)
Creatorfunction that creates the new Component and adds it as a sub-comp of the parent
MetaDataTypetype used to represent metadata

Definition at line 62 of file ComponentFactory.H.

Inheritance diagram for nrt::ComponentFactory< IDtype, Creator, MetaDataType >:
nrt::Singleton< ComponentFactory< IDtype, Creator, MetaDataType > >

Public Member Functions

void registerType (IDtype const &id, Creator creator, MetaDataType const &metaData=MetaDataType())
 Register a new product creator (and associated meta-data) under a new ID. More...
 
std::result_of< Creator(nrt::Component
*, std::string const &)>::type 
create (IDtype const &id, nrt::Component *parent, std::string const &instanceName)
 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< ComponentFactory< IDtype, Creator, MetaDataType > >
static ComponentFactory
< IDtype, Creator,
MetaDataType > & 
instance ()
 Get the global, unique instance of the class T. More...
 
- Protected Member Functions inherited from nrt::Singleton< ComponentFactory< IDtype, Creator, MetaDataType > >
 Singleton ()
 Only classes that inherit from Singleton can construct it via its protected default constructor.
 

Member Function Documentation

template<typename IDtype , class Creator , class MetaDataType >
void nrt::ComponentFactory< IDtype, Creator, MetaDataType >::registerType ( IDtype const &  id,
Creator  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 48 of file ComponentFactoryImpl.H.

References nrt::splitString().


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