pinocchio
4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Toggle main menu visibility
Loading...
Searching...
No Matches
pickle-map.hpp
1
//
2
// Copyright (c) 2019-2020 CNRS INRIA
3
//
4
5
#pragma once
6
7
#include <boost/python.hpp>
8
#include <boost/python/tuple.hpp>
9
10
namespace
pinocchio
11
{
12
namespace
python
13
{
14
namespace
bp = boost::python;
22
template
<
typename
MapType>
23
struct
PickleMap
: boost::python::pickle_suite
24
{
25
static
boost::python::tuple getinitargs(
const
MapType &)
26
{
27
return
boost::python::make_tuple();
28
}
29
30
static
boost::python::tuple getstate(boost::python::object op)
31
{
32
boost::python::extract<const MapType &> get_map(op);
33
if
(get_map.check())
34
{
35
const
MapType & map = get_map();
36
boost::python::list list;
37
for
(
typename
MapType::const_iterator it = map.begin(); it != map.end(); ++it)
38
{
39
list.append(boost::python::make_tuple(it->first, it->second));
40
}
41
return
boost::python::make_tuple(list);
42
}
43
return
boost::python::make_tuple();
44
}
45
46
static
void
setstate(bp::object op, bp::tuple tup)
47
{
48
typedef
typename
MapType::key_type key_type;
49
typedef
typename
MapType::mapped_type mapped_type;
50
51
if
(bp::len(tup) > 0)
52
{
53
bp::extract<MapType &> get_map(op);
54
if
(get_map.check())
55
{
56
MapType & map = get_map();
57
boost::python::list list = bp::extract<boost::python::list>(tup[0])();
58
for
(boost::python::ssize_t k = 0; k < boost::python::len(list); ++k)
59
{
60
boost::python::tuple entry = bp::extract<boost::python::tuple>(list[k])();
61
key_type key = bp::extract<key_type>(entry[0])();
62
map[key] = bp::extract<mapped_type>(entry[1])();
63
}
64
}
65
}
66
}
67
68
static
bool
getstate_manages_dict()
69
{
70
return
true
;
71
}
72
};
73
}
// namespace python
74
}
// namespace pinocchio
pinocchio
Main pinocchio namespace.
Definition
treeview.dox:11
pinocchio::python::PickleMap
Create a pickle interface for the std::map and aligned map.
Definition
pickle-map.hpp:24
include
pinocchio
bindings
python
utils
pickle-map.hpp
Generated by
1.17.0