8#ifndef FMTPYTHONPICKLE_H_INCLUDED
9#define FMTPYTHONPICKLE_H_INCLUDED
10 #include <boost/serialization/serialization.hpp>
11 #include <boost/serialization/export.hpp>
12 #include <boost/iostreams/stream.hpp>
13 #include <boost/iostreams/filtering_streambuf.hpp>
14 #include <boost/iostreams/filter/zlib.hpp>
15 #include <boost/iostreams/copy.hpp>
22#if defined FMTWITHPYTHON
24 #include <boost/python.hpp>
30 class FMT_pickle_suite :
public boost::python::pickle_suite
33 static const char* getname()
35 return typeid(T).name();
37 static boost::python::tuple getinitargs(
const T&)
39 return(boost::python::make_tuple());
41 static boost::python::object getstate(
const T& target)
45 boost::archive::binary_oarchive oa(os);
46 oa << boost::serialization::make_nvp(getname(), target);
48 std::stringstream compressed;
49 boost::iostreams::filtering_streambuf<boost::iostreams::input> out;
50 out.push(boost::iostreams::zlib_compressor());
52 boost::iostreams::copy(out, compressed);
53 return boost::python::make_tuple(compressed.str());
55 static void setstate(T& target, boost::python::tuple state)
57 boost::python::extract<std::string> input(state[0]);
58 std::stringstream compressed(input);
59 std::stringstream decompressed;
60 boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
61 in.push(boost::iostreams::zlib_decompressor());
63 boost::iostreams::copy(in, decompressed);
65 boost::archive::binary_iarchive ia(decompressed);
66 ia >> boost::serialization::make_nvp(getname(), target);
Definition: PYdefinitions.hpp:14