pinocchio
3.7.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
pickle.hpp
1
//
2
// Copyright (c) 2023 INRIA
3
//
4
5
#ifndef __pinocchio_python_utils_pickle_hpp__
6
#define __pinocchio_python_utils_pickle_hpp__
7
8
#include <pinocchio/bindings/python/fwd.hpp>
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__
pinocchio
Main pinocchio namespace.
Definition
treeview.dox:11
pinocchio::ContactSolverBaseTpl
Definition
contact-solver-base.hpp:20
pinocchio::python::PickleFromStringSerialization
Definition
pickle.hpp:18
include
pinocchio
bindings
python
utils
pickle.hpp
Generated by
1.9.8