|
Boost : |
From: Neal Becker (ndbecker2_at_[hidden])
Date: 2005-08-26 13:52:38
I think this is OK now. Here is addition to mersenne_twister.hpp:
friend class boost::serialization::access;
template<class Archive>
inline void save (Archive &ar, const unsigned int) const {
for (int j = 0; j < state_size; ++j) {
UIntType x = compute (j);
ar << boost::serialization::make_nvp("item", const_cast<const
UIntType&>(x));
}
}
template<class Archive>
inline void load (Archive &ar, const unsigned int) {
for (int j = 0; j < state_size; ++j) {
ar >> boost::serialization::make_nvp ("item", x[j]);
}
i = state_size;
}
template<class Archive>
void serialize(Archive & ar, const unsigned int file_version) {
boost::serialization::split_member(ar, *this, file_version);
}
Also:
#include <boost/serialization/split_member.hpp>
#include <boost/serialization/nvp.hpp>
Here is a simple test that passes:
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <boost/random.hpp>
typedef boost::mt19937 rng_t;
int main() {
rng_t rng1;
std::ostringstream os;
boost::archive::text_oarchive oa(os);
oa << const_cast<const rng_t&>(rng1);
std::string st (os.str());
std::istringstream is (st);
boost::archive::text_iarchive ia (is);
rng_t rng2;
ia >> rng2;
// std::cout << rng2;
assert (rng1 == rng2);
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk