5 #ifndef __pinocchio_python_utils_pickle_map_hpp__
6 #define __pinocchio_python_utils_pickle_map_hpp__
8 #include <boost/python.hpp>
9 #include <boost/python/tuple.hpp>
23 template<
typename MapType>
28 return boost::python::make_tuple();
31 static boost::python::tuple
getstate(boost::python::object op)
33 boost::python::extract<const MapType &> get_map(op);
36 const MapType & map = get_map();
37 boost::python::list list;
38 for (
typename MapType::const_iterator
it = map.begin();
it != map.end(); ++
it)
40 list.append(boost::python::make_tuple(
it->first,
it->second));
42 return boost::python::make_tuple(list);
44 return boost::python::make_tuple();
47 static void setstate(bp::object op, bp::tuple tup)
49 typedef typename MapType::key_type key_type;
50 typedef typename MapType::mapped_type mapped_type;
54 bp::extract<MapType &> get_map(op);
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)
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])();
77 #endif // ifndef __pinocchio_python_utils_pickle_map_hpp__