IQRF Gateway Daemon
Public Member Functions | List of all members
ObjectFactory< T, R > Class Template Reference

Create object based on data representation. More...

#include <ObjectFactory.h>

Public Member Functions

template<typename S >
void registerClass (const std::string &id)
 Template function to register object creator function. More...
 
bool hasClass (const std::string &id)
 Check if a creator object is registered. More...
 
std::unique_ptr< T > createObject (const std::string &id, R &representation)
 Create object based on data representation. More...
 

Detailed Description

template<typename T, typename R>
class ObjectFactory< T, R >

Create object based on data representation.

Allows registering object creator functions for classes created from their representations. Typically used for parsing incomming messages. The messages are preparsed to get type of class to be parsed and the type is passed together with the message to createObject method. The method creates an object via matching object creator and message data representation

Member Function Documentation

◆ createObject()

template<typename T, typename R>
std::unique_ptr<T> ObjectFactory< T, R >::createObject ( const std::string &  id,
R &  representation 
)
inline

Create object based on data representation.

Parameters
[in]idis name representing the class
[in]representationdata representing object to be created
Returns
created object
Exceptions
std::logic_errorin case of creator is not registered for passed id Crreates an object via matching object creator and message data representation

◆ hasClass()

template<typename T, typename R>
bool ObjectFactory< T, R >::hasClass ( const std::string &  id)
inline

Check if a creator object is registered.

Parameters
[in]idis name representing the class
Returns
true if registered else false

Check registrar map if object creator for class named id is registered if yes return true else false

◆ registerClass()

template<typename T, typename R>
template<typename S >
void ObjectFactory< T, R >::registerClass ( const std::string &  id)
inline

Template function to register object creator function.

Parameters
[in]nameof class to be registered
Exceptions
std::logic_errorin case of duplicity

Stores to registrar map pair id and object creator function for class type S. In case id is already used the exception std::logic_error is thrown


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