Bayeux  3.4.1
Core Foundation library for SuperNEMO
Classes | Public Member Functions | Friends | List of all members
boost::archive::portable_iarchive Class Reference

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

#include <bayeux/boost/archive/portable_iarchive.hpp>

Inheritance diagram for boost::archive::portable_iarchive:

Public Member Functions

 portable_iarchive (std::istream &is, unsigned flags=0)
 Constructor on a stream using ios::binary mode! More...
 
 portable_iarchive (std::streambuf &sb, unsigned flags=0)
 
void load (std::string &s)
 Load narrow strings. More...
 
void load (std::wstring &s)
 Load wide strings. More...
 
void load (bool &b)
 Loading bool type. More...
 
template<typename T >
boost::enable_if< boost::is_integral< T > >::type load (T &t, dummy< 2 >=0)
 Load integer types. More...
 
template<typename T >
boost::enable_if< boost::is_floating_point< T > >::type load (T &t, dummy< 3 >=0)
 Load floating point types. More...
 
template<typename T >
boost::disable_if< boost::is_arithmetic< T > >::type load (T &t, dummy< 4 >=0)
 

Friends

class basic_binary_iarchive< portable_iarchive >
 

Detailed Description

Portable binary input archive using little endian format.

This archive addresses integer size, endianness and floating point types so that data can be transferred across different systems. There may still be constraints as to what systems are compatible and the user will have to take care that e.g. a very large int being saved on a 64 bit machine will result in a portable_archive_exception if loaded into an int on a 32 bit system. A possible workaround to this would be to use fixed types like boost::uint64_t in your serialization structures.

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.

Constructor & Destructor Documentation

◆ portable_iarchive() [1/2]

boost::archive::portable_iarchive::portable_iarchive ( std::istream &  is,
unsigned  flags = 0 
)
inline

Constructor on a stream using ios::binary mode!

We cannot call basic_binary_iprimitive::init which tries to detect if the binary archive stems from a different platform by examining type sizes.

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

◆ portable_iarchive() [2/2]

boost::archive::portable_iarchive::portable_iarchive ( std::streambuf &  sb,
unsigned  flags = 0 
)
inline

Member Function Documentation

◆ load() [1/6]

void boost::archive::portable_iarchive::load ( std::string &  s)
inline

Load narrow strings.

◆ load() [2/6]

void boost::archive::portable_iarchive::load ( std::wstring &  s)
inline

Load 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 generate the output 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.

◆ load() [3/6]

void boost::archive::portable_iarchive::load ( bool &  b)
inline

Loading bool type.

Byte pattern is same as with integer types, so this function is somewhat redundant but treating bool as integer generates a lot of compiler warnings.

Note
If you cannot compile your application and it says something about load(bool) cannot convert your type 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.

◆ load() [4/6]

template<typename T >
boost::enable_if<boost::is_integral<T> >::type boost::archive::portable_iarchive::load ( T &  t,
dummy< 2 >  = 0 
)
inline

Load integer types.

First we load the size information ie. the number of bytes that hold the actual data. Then we retrieve the data and transform it to the original value by using load_little_endian.

◆ load() [5/6]

template<typename T >
boost::enable_if<boost::is_floating_point<T> >::type boost::archive::portable_iarchive::load ( T &  t,
dummy< 3 >  = 0 
)
inline

Load floating point types.

We simply rely on fp_traits to set the bit pattern from the (unsigned) integral type that was stored in 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.

◆ load() [6/6]

template<typename T >
boost::disable_if<boost::is_arithmetic<T> >::type boost::archive::portable_iarchive::load ( T &  t,
dummy< 4 >  = 0 
)
inline

Friends And Related Function Documentation

◆ basic_binary_iarchive< portable_iarchive >

friend class basic_binary_iarchive< portable_iarchive >
friend

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