cisst-saw
Loading...
Searching...
No Matches
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. More...

Macros

#define _cmnSerializer_h

Functions

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

Detailed Description

Declaration of cmnSerializer and functions cmnSerializeRaw.

Macro Definition Documentation

◆ _cmnSerializer_h

#define _cmnSerializer_h

Function Documentation

◆ cmnSerializeRaw() [1/3]

template<class _elementType>
void cmnSerializeRaw ( std::ostream & outputStream,
const _elementType & data )
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).

◆ cmnSerializeRaw() [2/3]

void cmnSerializeRaw ( std::ostream & outputStream,
const std::string & data )
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).

◆ cmnSerializeRaw() [3/3]

template<class _elementType>
void cmnSerializeRaw ( std::ostream & outputStream,
const std::vector< _elementType > & data )
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).

◆ cmnSerializeSizeRaw()

void cmnSerializeSizeRaw ( std::ostream & outputStream,
const size_t & data )
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.