pickle.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2023 INRIA
3 //
4 
5 #ifndef __pinocchio_python_utils_pickle_hpp__
6 #define __pinocchio_python_utils_pickle_hpp__
7 
9 
10 namespace pinocchio
11 {
12  namespace python
13  {
14  namespace bp = boost::python;
15 
16  template<typename Derived>
17  struct PickleFromStringSerialization : bp::pickle_suite
18  {
19  static bp::tuple getinitargs(const Derived &)
20  {
21  return bp::make_tuple();
22  }
23 
24  static bp::tuple getstate(const Derived & obj)
25  {
26  const std::string str(obj.saveToString());
27  return bp::make_tuple(bp::str(str));
28  }
29 
30  static void setstate(Derived & obj, bp::tuple tup)
31  {
32  if (bp::len(tup) == 0 || bp::len(tup) > 1)
33  {
34  throw eigenpy::Exception(
35  "Pickle was not able to reconstruct the object from the loaded data.\n"
36  "The pickle data structure contains too many elements.");
37  }
38 
39  bp::object py_obj = tup[0];
40  boost::python::extract<std::string> obj_as_string(py_obj.ptr());
41  if (obj_as_string.check())
42  {
43  const std::string str = obj_as_string;
44  obj.loadFromString(str);
45  }
46  else
47  {
48  throw eigenpy::Exception(
49  "Pickle was not able to reconstruct the model from the loaded data.\n"
50  "The entry is not a string.");
51  }
52  }
53 
54  static bool getstate_manages_dict()
55  {
56  return true;
57  }
58  };
59  } // namespace python
60 } // namespace pinocchio
61 
62 #endif // ifndef __pinocchio_python_utils_pickle_hpp__
boost::python
pinocchio::python::PickleFromStringSerialization
Definition: pickle.hpp:17
pinocchio::python::PickleFromStringSerialization::getinitargs
static bp::tuple getinitargs(const Derived &)
Definition: pickle.hpp:19
pinocchio::python::PickleFromStringSerialization::getstate_manages_dict
static bool getstate_manages_dict()
Definition: pickle.hpp:54
pinocchio::python::PickleFromStringSerialization::getstate
static bp::tuple getstate(const Derived &obj)
Definition: pickle.hpp:24
python
eigenpy::Exception
fwd.hpp
str
str
pinocchio::python::PickleFromStringSerialization::setstate
static void setstate(Derived &obj, bp::tuple tup)
Definition: pickle.hpp:30
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Sun Dec 22 2024 03:41:12