Boost logo

Boost Users :

Subject: [Boost-users] [Uuid] Portable binary serialization.
From: Mostafa (mostafa_working_away_at_[hidden])
Date: 2010-03-12 17:16:23


I'm interested in using the portable binary serialization code in
[serialization]/example directory with Boost.Uuid. I've noticed that
there's a fall back template function for unrecognized types in
portable_binary_iarchive.hpp:

101 // default fall through for any types not specified here
102 template<class T>
103 void load(T & t){
104 boost::intmax_t l;
105 load_impl(l, sizeof(T));
106 // use cast to avoid compile time warning
107 t = static_cast<T>(l);
108 }

that relies on the sizeof operator. Short of replacing the sizeof
operator with a templated switch:

//Code Sample 1
//Start code
template <typename T>
std::size_t my_size_of { return sizeof(T); }

tempate <>
std::size_t my_size_of<boost::uuids::uuid> { return
boost::uuids::uuid::static_size(); }
//End code

or using macros ala:

//CodeSample 2
//Start

template <typename T>
std::size_t my_size_of(T const & t) { return sizeof(T); }

tempate <>
std::size_t my_size_of<boost::uuids::uuid>(boost::uuids::uuid const &) {
return boost::uuids::uuid::static_size(); }

#define sizeof(x) my_size_of(x)
#include <boost_portable_binary_serialization>
#undef sizeof
//End

, is their something less instrusive I could do to make it work with
Boost.Uuid?

Thanks,

Mostafa


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net