[C++-sig] Combining Boost Serialization with Boost Python

Neal Becker ndbecker2 at gmail.com
Thu Mar 15 13:28:19 CET 2012


I have used this myself for some time.
Here is an example:

typedef boost::mt19937 rng_t;

struct mt_pickle_suite : bp::pickle_suite {
    
  static bp::object getstate (const rng_t& rng) {
    std::ostringstream os;
    boost::archive::binary_oarchive oa(os);
    oa << rng;
    return bp::str (os.str());
  }

  static void
  setstate(rng_t& rng, bp::object entries) {
    bp::str s = bp::extract<bp::str> (entries)();
    std::string st = bp::extract<std::string> (s)();
    std::istringstream is (st);
    
    boost::archive::binary_iarchive ia (is);
    ia >> rng;
  }
};



More information about the Cplusplus-sig mailing list