pickle-map.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2019-2020 CNRS INRIA
3 //
4 
5 #ifndef __pinocchio_python_utils_pickle_map_hpp__
6 #define __pinocchio_python_utils_pickle_map_hpp__
7 
8 #include <boost/python.hpp>
9 #include <boost/python/tuple.hpp>
10 
11 namespace pinocchio
12 {
13  namespace python
14  {
15  namespace bp = boost::python;
23  template<typename MapType>
24  struct PickleMap : boost::python::pickle_suite
25  {
26  static boost::python::tuple getinitargs(const MapType &)
27  {
28  return boost::python::make_tuple();
29  }
30 
31  static boost::python::tuple getstate(boost::python::object op)
32  {
33  boost::python::extract<const MapType &> get_map(op);
34  if (get_map.check())
35  {
36  const MapType & map = get_map();
37  boost::python::list list;
38  for (typename MapType::const_iterator it = map.begin(); it != map.end(); ++it)
39  {
40  list.append(boost::python::make_tuple(it->first, it->second));
41  }
42  return boost::python::make_tuple(list);
43  }
44  return boost::python::make_tuple();
45  }
46 
47  static void setstate(bp::object op, bp::tuple tup)
48  {
49  typedef typename MapType::key_type key_type;
50  typedef typename MapType::mapped_type mapped_type;
51 
52  if (bp::len(tup) > 0)
53  {
54  bp::extract<MapType &> get_map(op);
55  if (get_map.check())
56  {
57  MapType & map = get_map();
58  boost::python::list list = bp::extract<boost::python::list>(tup[0])();
59  for (boost::python::ssize_t k = 0; k < boost::python::len(list); ++k)
60  {
61  boost::python::tuple entry = bp::extract<boost::python::tuple>(list[k])();
62  key_type key = bp::extract<key_type>(entry[0])();
63  map[key] = bp::extract<mapped_type>(entry[1])();
64  }
65  }
66  }
67  }
68 
69  static bool getstate_manages_dict()
70  {
71  return true;
72  }
73  };
74  } // namespace python
75 } // namespace pinocchio
76 
77 #endif // ifndef __pinocchio_python_utils_pickle_map_hpp__
boost::python
pinocchio::python::PickleMap::getstate
static boost::python::tuple getstate(boost::python::object op)
Definition: pickle-map.hpp:31
python
inverse-kinematics-3d.it
int it
Definition: inverse-kinematics-3d.py:17
pinocchio::python::PickleMap::getstate_manages_dict
static bool getstate_manages_dict()
Definition: pickle-map.hpp:69
pinocchio::python::PickleMap::setstate
static void setstate(bp::object op, bp::tuple tup)
Definition: pickle-map.hpp:47
pinocchio::python::PickleMap::getinitargs
static boost::python::tuple getinitargs(const MapType &)
Definition: pickle-map.hpp:26
pinocchio::python::PickleMap
Create a pickle interface for the std::map and aligned map.
Definition: pickle-map.hpp:24
pinocchio
Main pinocchio namespace.
Definition: timings.cpp:27


pinocchio
Author(s):
autogenerated on Fri Nov 1 2024 02:41:47