Re: [pygccxml-development] serialization support?
Brought to you by:
mbaas,
roman_yakovenko
From: Neal B. <ndb...@gm...> - 2006-09-13 10:57:36
|
On Wednesday 13 September 2006 6:52 am, Roman Yakovenko wrote: > On 9/13/06, Neal Becker <ndb...@gm...> wrote: > > On Wednesday 13 September 2006 12:58 am, Roman Yakovenko wrote: > > > On 9/13/06, Neal Becker <ndb...@gm...> wrote: > > > > Has any work been done on adding boost::serialization support? > > > > > > What do you mean? > > > > Automatic generation of pickle support. Probably using > > boost::serialization. > > That what I thought. No we don't work on this functionality. Moreover > I think, that Py++ > can not implement it. The primary reason is that Py++ deals with class > interface > and not with its state. Py++ can provide some convinience API that > will make the task > to be easier to implement. Tell me what you need and I will check how > I can integrate > your ideas. The technique I have used is not really elegant, but works. First serialize with boost::serializatoin into a string, then pickle the string: struct mt_pickle_suite : python::pickle_suite { static python::object getstate (const rng_t& rng) { std::ostringstream os; boost::archive::binary_oarchive oa(os); oa << rng; return python::str (os.str()); } static void setstate(rng_t& rng, python::object entries) { python::str s = python::extract<python::str> (entries)(); std::string st = python::extract<std::string> (s)(); std::istringstream is (st); boost::archive::binary_iarchive ia (is); ia >> rng; } }; [...] class_<rng_t> ("rng", "Mersenne Twister", python::init<rng_t::result_type>( (python::arg ("seed")=4357), "__init__(seed=4357)\n" "Construct with optional seed\n" "@param seed: initial seed\n" )) .def_pickle(mt_pickle_suite()) .def ("getstate", &mt_pickle_suite::getstate) .def ("setstate", &mt_pickle_suite::setstate) [...] |