Safir SDK Core
Loading...
Searching...
No Matches
Safir::Dob::Typesystem::ObjectFactory Class Reference

This class is an object factory for all automatically generated DOB classes. More...

#include <Safir/Dob/Typesystem/ObjectFactory.h>

Public Member Functions

ObjectPtr CreateObject (const TypeId typeId) const
 Create a new "empty" object from a typeid.
 
std::vector< std::pair< TypeId, Int64 > > GetRegisteredTypes () const
 GetRegisteredTypes - Get types wich have been registered in the ObjectFactory.
 
Blob deserialization part.
ObjectPtr CreateObject (char const *const blob) const
 Create a new object from a blob.
 

Static Public Member Functions

static ObjectFactoryInstance ()
 Get the instance of the singleton.
 

Registration part.

Stuff for registering classes with the object factory.

typedef ObjectPtr(* CreateObjectCallback) (Int64 handle)
 Function signature of the create callback function.
 
bool RegisterClass (const TypeId typeId, const Int64 checksum, CreateObjectCallback createFunction)
 Register a class with the object factory.
 

Detailed Description

This class is an object factory for all automatically generated DOB classes.

Each generated class automatically registers itself with this class. Users can call the CreateObject(TypeId) routine to create objects of a desired type (this is if they receive the type id from some other application so that they cannot call the Create routine of the class itself directly).

Member Typedef Documentation

◆ CreateObjectCallback

typedef ObjectPtr(* Safir::Dob::Typesystem::ObjectFactory::CreateObjectCallback) (Int64 handle)

Function signature of the create callback function.

This is the signature of the function that the object factory will call to create the object. If handle == 0 then just create an empty object.

Member Function Documentation

◆ CreateObject() [1/2]

ObjectPtr Safir::Dob::Typesystem::ObjectFactory::CreateObject ( char const *const blob) const

Create a new object from a blob.

This method takes a blob and extracts the typeId from it and then calls the appropriate callback to create the object.

Parameters
blob[in] - The blob to deserialize.
Returns
A std::shared_ptr to the object.
Exceptions
IllegalValueExceptionIf the type represented by the blob isn't found in the ObjectFactory.

◆ CreateObject() [2/2]

ObjectPtr Safir::Dob::Typesystem::ObjectFactory::CreateObject ( const TypeId typeId) const

Create a new "empty" object from a typeid.

This method takes a TypeId and calls the appropriate callback to create an object of the desired type.

Parameters
typeId[in] - The TypeId of the object to create.
Returns
A std::shared_ptr to the object.
Exceptions
IllegalValueExceptionIf the type couldn't be found in the ObjectFactory.

◆ GetRegisteredTypes()

std::vector< std::pair< TypeId, Int64 > > Safir::Dob::Typesystem::ObjectFactory::GetRegisteredTypes ( ) const

GetRegisteredTypes - Get types wich have been registered in the ObjectFactory.

Intended for debug and diagnostics.

Returns
A vector of all registered type ids and corresponding checksum.

◆ Instance()

static ObjectFactory & Safir::Dob::Typesystem::ObjectFactory::Instance ( )
static

Get the instance of the singleton.

Returns
The instance of the singleton.

◆ RegisterClass()

bool Safir::Dob::Typesystem::ObjectFactory::RegisterClass ( const TypeId typeId,
const Int64 checksum,
CreateObjectCallback createFunction )

Register a class with the object factory.

Parameters
typeId[in] - The TypeId of the object that should be created using createFunction.
checksum[in] - Checksum of all members and parameters in the class.
createFunction[in] - The function to call to create the object.