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