Create object based on data representation.
More...
#include <ObjectFactory.h>
|
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...
|
|
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
◆ 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] | id | is name representing the class |
[in] | representation | data representing object to be created |
- Returns
- created object
- Exceptions
-
std::logic_error | in 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>
Check if a creator object is registered.
- Parameters
-
[in] | id | is 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] | name | of class to be registered |
- Exceptions
-
std::logic_error | in 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: