OpenTwin 0.1
OpenTwin
 
Loading...
Searching...
No Matches
ot::FactoryTemplate< ValueType > Class Template Reference

The FactoryTemplate may be used to quickly create default factories that are only used for item creation without any further logic. More...

#include "FactoryTemplate.h"

Public Types

typedef std::function< ValueType *()> ConstructorFunctionType
 Constructor type definition.
 

Public Member Functions

void registerConstructor (const std::string &_key, ConstructorFunctionType _constructor)
 Will register the prvided constructor under the given key. If a constructor for the given key already exists a warning log will be generated and the request will be ignored.
 
void deregisterConstructor (const std::string &_key)
 Remove the constructor for the given key.
 
ValueType * createFromKey (const std::string &_key)
 Call the constructor for the given key and return the created instance.
 
ValueType * createFromJSON (const ConstJsonObject &_jsonObject, const char *_typeKey)
 Creates an instance according to the key in the provided JSON object. If the key is empty the request will be ignored. If the created instance inherits from Serializable the setFromJsonObject method will be called.
 
ValueType * createFromJSON (const ConstJsonObject &_jsonObject, const std::string &_typeKey)
 [/ref ValueType* createFromJSON(const ConstJsonObject& _jsonObject, const char* _typeKey) "x"].
 

Protected Member Functions

 FactoryTemplate ()
 Protected constructor.
 
 ~FactoryTemplate ()
 Protected destructor.
 

Detailed Description

template<class ValueType>
class ot::FactoryTemplate< ValueType >

The FactoryTemplate may be used to quickly create default factories that are only used for item creation without any further logic.

Note
Note that the createFromJson() methods will call setFromJsonObject() if the created item inherits from Serializable. The key for creating an object is a std::string.
Template Parameters
ValueTypeValue type (e.g. MyClass).

Member Typedef Documentation

◆ ConstructorFunctionType

template<class ValueType >
typedef std::function<ValueType*()> ot::FactoryTemplate< ValueType >::ConstructorFunctionType

Constructor type definition.

Constructor & Destructor Documentation

◆ FactoryTemplate()

template<class ValueType >
ot::FactoryTemplate< ValueType >::FactoryTemplate ( )
inlineprotected

Protected constructor.

◆ ~FactoryTemplate()

template<class ValueType >
ot::FactoryTemplate< ValueType >::~FactoryTemplate ( )
inlineprotected

Protected destructor.

Member Function Documentation

◆ createFromJSON() [1/2]

template<class ValueType >
ValueType * ot::FactoryTemplate< ValueType >::createFromJSON ( const ConstJsonObject & _jsonObject,
const char * _typeKey )

Creates an instance according to the key in the provided JSON object. If the key is empty the request will be ignored. If the created instance inherits from Serializable the setFromJsonObject method will be called.

Parameters
_jsonObjectThe JSON object containing the key and optionally additional information.
_typeKeyThe JSON object key by which the constructor key may be retreived.

◆ createFromJSON() [2/2]

template<class ValueType >
ValueType * ot::FactoryTemplate< ValueType >::createFromJSON ( const ConstJsonObject & _jsonObject,
const std::string & _typeKey )

◆ createFromKey()

template<class ValueType >
ValueType * ot::FactoryTemplate< ValueType >::createFromKey ( const std::string & _key)

Call the constructor for the given key and return the created instance.

Parameters
_keyThe constructor key.

◆ deregisterConstructor()

template<class ValueType >
void ot::FactoryTemplate< ValueType >::deregisterConstructor ( const std::string & _key)

Remove the constructor for the given key.

Parameters
_keyThe constructor key.

◆ registerConstructor()

template<class ValueType >
void ot::FactoryTemplate< ValueType >::registerConstructor ( const std::string & _key,
ConstructorFunctionType _constructor )

Will register the prvided constructor under the given key. If a constructor for the given key already exists a warning log will be generated and the request will be ignored.

Parameters
_keyThe constructor key.
_constructorThe constructor.

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