cisst-saw
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Macros | Functions
cmnSerializer.h File Reference

Declaration of cmnSerializer and functions cmnSerializeRaw. More...

#include <cisstCommon/cmnPortability.h>
#include <cisstCommon/cmnTypeTraits.h>
#include <cisstCommon/cmnGenericObject.h>
#include <cisstCommon/cmnClassRegister.h>
#include <cisstCommon/cmnThrow.h>
#include <string>
#include <vector>
#include <fstream>
#include <cstddef>
#include <cisstCommon/cmnExport.h>

Go to the source code of this file.

Classes

class  cmnSerializeRawImpl< _elementType, bool >
 
class  cmnSerializeRawImpl< _elementType, true >
 
class  cmnSerializer
 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...
 

Macros

#define _cmnSerializer_h
 

Functions

template<class _elementType >
void cmnSerializeRaw (std::ostream &outputStream, const _elementType &data) throw (std::runtime_error)
 
void cmnSerializeSizeRaw (std::ostream &outputStream, const size_t &data) throw (std::runtime_error)
 
void cmnSerializeRaw (std::ostream &outputStream, const std::string &data) throw (std::runtime_error)
 
template<class _elementType >
void cmnSerializeRaw (std::ostream &outputStream, const std::vector< _elementType > &data) throw (std::runtime_error)
 

Detailed Description

Declaration of cmnSerializer and functions cmnSerializeRaw.

Macro Definition Documentation

#define _cmnSerializer_h

Function Documentation

template<class _elementType >
void cmnSerializeRaw ( std::ostream &  outputStream,
const _elementType &  data 
)
throw (std::runtime_error
)
inline

Serialization helper function for a basic type. If the type is derived from cmnGenericObject, it just calls the SerializeRaw member function. Otherwise, it performs a cast to char pointer (char *) using reinterpret_cast and then writes the result to the output stream. If the write operation fails, an exception is thrown (std::runtime_error).

void cmnSerializeRaw ( std::ostream &  outputStream,
const std::string &  data 
)
throw (std::runtime_error
)
inline

Serialization helper function for an STL string. This function first serializes the string size and then writes all the string characters (char) to the output stream. If the write operation fails, an exception is thrown (std::runtime_error).

template<class _elementType >
void cmnSerializeRaw ( std::ostream &  outputStream,
const std::vector< _elementType > &  data 
)
throw (std::runtime_error
)
inline

Serialization helper function for an STL vector. This function first serializes the vector size and then calls cmnSerializeRaw for each element of the vector (thus, it will only work if cmnSerializeRaw is defined for the element type. If the write operation fails, an exception is thrown (std::runtime_error).

void cmnSerializeSizeRaw ( std::ostream &  outputStream,
const size_t &  data 
)
throw (std::runtime_error
)
inline

Serialization helper function for size object. This function converts a size_t object to an unsigned long long int before using cmnSerializeRaw. This operation is required for all size_t as the writer/reader can be both 32 bits or 64 bits programs.

This function should be use to implement the SerializeRaw method of classes derived from cmnGenericObject.