Thread: [pygccxml-development] serialization support?
Brought to you by:
mbaas,
roman_yakovenko
From: Neal B. <ndb...@gm...> - 2006-09-13 02:11:22
|
Has any work been done on adding boost::serialization support? |
From: Roman Y. <rom...@gm...> - 2006-09-13 04:58:47
|
On 9/13/06, Neal Becker <ndb...@gm...> wrote: > Has any work been done on adding boost::serialization support? What do you mean? -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
From: Neal B. <ndb...@gm...> - 2006-09-13 10:41:48
|
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. |
From: Roman Y. <rom...@gm...> - 2006-09-13 10:52:28
|
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. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |
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) [...] |
From: Roman Y. <rom...@gm...> - 2006-09-13 11:06:38
|
On 9/13/06, Neal Becker <ndb...@gm...> wrote: > 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) > [...] > Few comments: 1. This implementation will surprize any Python user. You don't preserve references between objects. 2. I think you can make this code to be template on Pickled class. 3. I think this code belongs to goodies. Do you want to work a little bit on it and contribute? ( test, few lines of documentation) from goodies import pickle pickle( module builder, list of classes ) Something like this. -- Roman Yakovenko C++ Python language binding http://www.language-binding.net/ |