cisst-saw
|
Serialization utility class.This class allows to serialize objects of different types (all derived from cmnGenericObject) as well as the information required to deserialize them (see cmnDeSerializer) to and from an STL output stream. More...
#include <cmnSerializer.h>
Public Types | |
typedef unsigned long long int | TypeId |
Public Member Functions | |
cmnSerializer (std::ostream &outputStream) | |
~cmnSerializer () | |
bool | ServicesSerialized (const cmnClassServicesBase *servicesPointer) const |
void | Reset (void) |
void | Serialize (const cmnGenericObject &object, const bool serializeObject=true) |
void | SerializeServices (const cmnClassServicesBase *servicesPointer) |
![]() | |
virtual | ~cmnGenericObject (void) |
virtual const cmnClassServicesBase * | Services (void) const =0 |
bool | ReconstructFrom (const cmnGenericObject &other) |
std::string | ToString (void) const |
virtual void | ToStream (std::ostream &outputStream) const |
virtual void | ToStreamRaw (std::ostream &outputStream, const char delimiter= ' ', bool headerOnly=false, const std::string &headerPrefix="") const |
virtual bool | FromStreamRaw (std::istream &inputStream, const char delimiter= ' ') |
virtual void | SerializeRaw (std::ostream &outputStream) const |
virtual void | DeSerializeRaw (std::istream &inputStream) |
virtual cmnLogger::StreamBufType * | GetLogMultiplexer (void) const |
virtual size_t | ScalarNumber (void) const |
virtual bool | ScalarNumberIsFixed (void) const |
virtual double | Scalar (const size_t CMN_UNUSED(index)) const throw (std::out_of_range) |
virtual std::string | ScalarDescription (const size_t CMN_UNUSED(index), const std::string &CMN_UNUSED(userDescription)) const |
Serialization utility class.
This class allows to serialize objects of different types (all derived from cmnGenericObject) as well as the information required to deserialize them (see cmnDeSerializer) to and from an STL output stream.
The result is a sequence of class informations (i.e. class name as a string and unique identifier) and objects. Each object is sent preceeded by its unique class identifier and class information is preceeded by a 0. This allows cmnDeSerializer to determine what is currently deserialized.
The unique identifer used is the address of the object cmnClassServices associated to each class.
When an object needs to be serialized, the method Serialize will first verify that the class information (name and identifier) has already been serialized. If this is not the case, it will serialize the class information and then the object itself.
typedef unsigned long long int cmnSerializer::TypeId |
Type used to identify objects over the network. It uses the services pointer but as the sender or receiver could be a 32 or 64 bits OS, we use a data type that can handle both.
cmnSerializer::cmnSerializer | ( | std::ostream & | outputStream | ) |
Constructor.
outputStream | any stream derived from std::ostream . The output stream must be created with the open flag std::ostream::binary . |
cmnSerializer::~cmnSerializer | ( | ) |
Destructor
void cmnSerializer::Reset | ( | void | ) |
Reset the list of types already sent.
void cmnSerializer::Serialize | ( | const cmnGenericObject & | object, |
const bool | serializeObject = true |
||
) |
Serialize an object. This method will first verify that the information (cmnClassServices) related to the class of the object has been serialized using SerializeServices. Once this is done, it will serialize the class identifier (pointer on the class information, see cmnClassServices and cmnClassRegister) and finally call the object's method SerializeRaw
.
object | An object of a class derived from cmnGenericObject. The class of the object must have the virtual method SerializeRaw re-defined to properly serialize the content of the object. |
serializeObject | If true, object content is serialized. If false, only class services is serialized and object content is not serialized. True by default. |
void cmnSerializer::SerializeServices | ( | const cmnClassServicesBase * | servicesPointer | ) |
Serialize the class information if needed. This method will write the class name (as an STL string) and the type identifier used on the serialization end to the output stream. The type identifier used is the address of the class services object (cmnClassServices). To avoid sending the same information multiple times, this class (cmnSerializer) maintains a list of the class identifier already sent.
It is important to note that a regular user doesn't need to use this method as the Serialize method performs this task. It is provided for advanced users who need or want to serialize all the class information first and then serialize their objects. This can be used to avoid time delays while serializing and de-serializing objects.
servicesPointer | Pointer on object cmnClassServices. Use cmnClassRegister::FindClassServices, className::Services() or object.Services() to retrieve the correct pointer. |
bool cmnSerializer::ServicesSerialized | ( | const cmnClassServicesBase * | servicesPointer | ) | const |
Returns true if the services have already been serialized.