QxOrm  1.4.9
C++ Object Relational Mapping library
eos::portable_oarchive Class Reference

Portable binary output archive using little endian format. More...

#include <portable_oarchive.hpp>

List of all members.

Classes

struct  dummy

Public Member Functions

 portable_oarchive (std::ostream &os, unsigned flags=0)
 Constructor on a stream using ios::binary mode!
void save (const std::string &s)
 Save narrow strings.
void save (const std::wstring &s)
 Save wide strings.
void save (const bool &b)
 Saving bool type.
template<typename T >
boost::enable_if
< boost::is_integral< T >
>::type 
save (const T &t, dummy< 2 >=0)
 Save integer types.
template<typename T >
boost::enable_if
< boost::is_floating_point< T >
>::type 
save (const T &t, dummy< 3 >=0)
 Save floating point types.
template<typename T >
boost::disable_if
< boost::is_arithmetic< T >
>::type 
save (const T &t, dummy< 4 >=0)

Private Member Functions

void save_signed_char (const signed char &c)
void init (unsigned flags)

Detailed Description

Portable binary output archive using little endian format.

This archive addresses integer size, endianness and floating point types so that data can be transferred across different systems. The archive consists primarily of three different save implementations for integral types, floating point types and string types. Those functions are templates and use enable_if to be correctly selected for overloading.

Note:
The class is based on the portable binary example by Robert Ramey and uses Beman Dawes endian library plus fp_utilities by Johan Rade.

Definition at line 188 of file portable_oarchive.hpp.


Constructor & Destructor Documentation

eos::portable_oarchive::portable_oarchive ( std::ostream &  os,
unsigned  flags = 0 
) [inline]

Constructor on a stream using ios::binary mode!

We cannot call basic_binary_oprimitive::init which stores type sizes to the archive in order to detect transfers to non-compatible platforms.

We could have called basic_binary_oarchive::init which would create the boost::serialization standard archive header containing also the library version. Due to efficiency we stick with our own.

Definition at line 242 of file portable_oarchive.hpp.


Member Function Documentation

void eos::portable_oarchive::init ( unsigned  flags) [inline, private]

Definition at line 210 of file portable_oarchive.hpp.

void eos::portable_oarchive::save ( const std::string &  s) [inline]

Save narrow strings.

Definition at line 263 of file portable_oarchive.hpp.

void eos::portable_oarchive::save ( const std::wstring &  s) [inline]

Save wide strings.

This is rather tricky to get right for true portability as there are so many different character encodings around. However, wide strings that are encoded in one of the Unicode schemes only need to be _transcoded_ which is a lot easier actually.

We expect the input string to be encoded in the system's native format, ie. UTF-16 on Windows and UTF-32 on Linux machines. Don't know about Mac here so I can't really say about that.

Definition at line 281 of file portable_oarchive.hpp.

void eos::portable_oarchive::save ( const bool &  b) [inline]

Saving bool type.

Saving bool directly, not by const reference because of tracking_type's operator (bool).

Note:
If you cannot compile your application and it says something about save(bool) cannot convert your type const A& into bool then you should check your BOOST_CLASS_IMPLEMENTATION setting for A, as portable_archive is not able to handle custom primitive types in a general manner.

Definition at line 299 of file portable_oarchive.hpp.

template<typename T >
boost::enable_if<boost::is_integral<T> >::type eos::portable_oarchive::save ( const T &  t,
dummy< 2 >  = 0 
) [inline]

Save integer types.

First we save the size information ie. the number of bytes that hold the actual data. We subsequently transform the data using store_little_endian and store non-zero bytes to the stream.

Definition at line 314 of file portable_oarchive.hpp.

template<typename T >
boost::enable_if<boost::is_floating_point<T> >::type eos::portable_oarchive::save ( const T &  t,
dummy< 3 >  = 0 
) [inline]

Save floating point types.

We simply rely on fp_traits to extract the bit pattern into an (unsigned) integral type and store that into the stream. Francois Mauger provided standardized behaviour for special values like inf and NaN, that need to be serialized in his application.

Note:
by Johan Rade (author of the floating point utilities library): Be warned that the math::detail::fp_traits<T>::type::get_bits() function is *not* guaranteed to give you all bits of the floating point number. It will give you all bits if and only if there is an integer type that has the same size as the floating point you are copying from. It will not give you all bits for double if there is no uint64_t. It will not give you all bits for long double if sizeof(long double) > 8 or there is no uint64_t.

The member fp_traits<T>::type::coverage will tell you whether all bits are copied. This is a typedef for either math::detail::all_bits or math::detail::not_all_bits.

If the function does not copy all bits, then it will copy the most significant bits. So if you serialize and deserialize the way you describe, and fp_traits<T>::type::coverage is math::detail::not_all_bits, then your floating point numbers will be truncated. This will introduce small rounding off errors.

Definition at line 367 of file portable_oarchive.hpp.

template<typename T >
boost::disable_if<boost::is_arithmetic<T> >::type eos::portable_oarchive::save ( const T &  t,
dummy< 4 >  = 0 
) [inline]

Definition at line 404 of file portable_oarchive.hpp.

void eos::portable_oarchive::save_signed_char ( const signed char &  c) [inline, private]

Definition at line 204 of file portable_oarchive.hpp.


The documentation for this class was generated from the following file: