Boost logo

Boost :

Subject: Re: [boost] patch to serialize mersenne_twister
From: joaquin_at_[hidden]
Date: 2008-10-29 12:04:05


Neal Becker escribió:
> joaquin_at_[hidden] wrote:
>
>
>> There was a discussion in the past about how to provide serialization
>> capabilities and the general opinion was that this is better packaged as
>> a separate header when feasible, something like
>>
>> boost/random/mersenne_twister_serialize.hpp
>>
>> or
>>
>> boost/random/mersenne_twister/serialize.hpp
>>
>> or similar. BTW, it'd be good if we could reach a naming consensus for
>> these serialization files. My favorite is:
>>
>> boost/.../xxx.hpp provides serialization capabilities at
>> boost/.../xxx/serialize.hpp
>>
>> Joaquín M López Muñoz
>> Telefónica, Investigación y Desarrollo
>>
>
> Since it wants private access into the class, how would you
> package it as a separate header?
>

Something like this:

* Header boost/random/mersenne_twister.hpp:

namespace boost{namespace random{

template<...> class mersenne_twister;

}}

namespace boost{namespace serialization{

template<class Archive,...>
void serialize(
  Archive&,
  boost::random::mersenne_twister<...>&,
  const unsigned int);

}}

namespace boost{namespace random{

template<...>
class mersenne_twister
{
  //...
private:
  template<class Archive...>
  friend
  void boost::serialization::serialize(
    Archive&,
    boost::random::mersenne_twister<...>&,
    const unsigned int);
};

}}

* Header boost/random/mersenne_twister/serialize.hpp:

namespace boost{namespace serialization{

template<class Archive,...>
void serialize(
  Archive& ar,
  boost::random::mersenne_twister<...>& m,
  const unsigned int)
{
  ar & serialization::make_nvp ("i", m.i);
  ar & serialization::make_nvp ("x", m.x);
}

}}

Joaquín M López Muñoz
Telefónica, Investigación y Desarrollo


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk