iCub-main
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
iCub::learningmachine::FactoryT< K, T > Class Template Reference

A template class for the factory pattern. More...

#include <FactoryT.h>

Public Member Functions

void registerPrototype (T *prototype)
 Registers a prototype object that can be used to create clones.
 
Tcreate (const K &key)
 Creates a new object given a specific type of key.
 
std::vector< K > getKeys ()
 Returns a vector of the registered keys.
 

Static Public Member Functions

static FactoryT< K, T > & instance ()
 An instance retrieval method that follows the Singleton pattern.
 

Detailed Description

template<class K, class T>
class iCub::learningmachine::FactoryT< K, T >

A template class for the factory pattern.

The factory should be used to create concrete instances of abstract, registered classes.

Author
Arjan Gijsberts

Definition at line 41 of file FactoryT.h.

Member Function Documentation

◆ create()

template<class K , class T >
T * iCub::learningmachine::FactoryT< K, T >::create ( const K &  key)
inline

Creates a new object given a specific type of key.

The receiving end takes ownership of the returned pointer.

Parameters
keya key that identifies the type of machine
Returns
a copied object of the specified type
Exceptions
runtimeerror if no object has been registered with the same key

Definition at line 127 of file FactoryT.h.

◆ getKeys()

template<class K , class T >
std::vector< K > iCub::learningmachine::FactoryT< K, T >::getKeys ( )
inline

Returns a vector of the registered keys.

Returns
vector of registered keys

Definition at line 143 of file FactoryT.h.

◆ instance()

template<class K , class T >
static FactoryT< K, T > & iCub::learningmachine::FactoryT< K, T >::instance ( )
inlinestatic

An instance retrieval method that follows the Singleton pattern.

Note that this implementation should not be considered thread safe and that problems may arise. However, due to the nature of the expected use this will not be likely to result in problems.

See http://www.oaklib.org/docs/oak/singleton.html for more information.

Returns
the singleton factory instance

Definition at line 86 of file FactoryT.h.

◆ registerPrototype()

template<class K , class T >
void iCub::learningmachine::FactoryT< K, T >::registerPrototype ( T prototype)
inline

Registers a prototype object that can be used to create clones.

Strictly speaking, for this application the object only has to be able to return a new object of its own type, regardless of the internal state of that object.

Parameters
prototypethe prototype object
Exceptions
runtimeerror if the name of the prototype is empty
runtimeerror if another object is registered with the same name

Definition at line 101 of file FactoryT.h.


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