5 #ifndef HPP_FCL_PYTHON_PICKLE_H
6 #define HPP_FCL_PYTHON_PICKLE_H
8 #include <boost/python.hpp>
11 #include <boost/archive/text_oarchive.hpp>
12 #include <boost/archive/text_iarchive.hpp>
21 return boost::python::make_tuple();
24 static boost::python::tuple
getstate(
const T& obj) {
26 boost::archive::text_oarchive oa(ss);
32 static void setstate(T& obj, boost::python::tuple tup) {
33 if (boost::python::len(tup) == 0 || boost::python::len(tup) > 1) {
35 "Pickle was not able to reconstruct the object from the loaded "
37 "The pickle data structure contains too many elements.");
40 boost::python::object py_obj = tup[0];
41 boost::python::extract<std::string> obj_as_string(py_obj.ptr());
42 if (obj_as_string.check()) {
43 const std::string
str = obj_as_string;
44 std::istringstream is(
str);
45 boost::archive::text_iarchive ia(is, boost::archive::no_codecvt);
49 "Pickle was not able to reconstruct the model from the loaded data.\n"
50 "The entry is not a string.");
57 #endif // ifndef HPP_FCL_PYTHON_PICKLE_H