GCC Code Coverage Report


Directory: ./
File: include/pinocchio/bindings/python/utils/pickle.hpp
Date: 2025-02-12 21:03:38
Exec Total Coverage
Lines: 17 19 89.5%
Branches: 15 38 39.5%

Line Branch Exec Source
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 2 static bp::tuple getinitargs(const Derived &)
20 {
21 2 return bp::make_tuple();
22 }
23
24 2 static bp::tuple getstate(const Derived & obj)
25 {
26
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 const std::string str(obj.saveToString());
27
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
6 return bp::make_tuple(bp::str(str));
28 2 }
29
30 2 static void setstate(Derived & obj, bp::tuple tup)
31 {
32
5/10
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 2 times.
✗ Branch 4 not taken.
✓ Branch 6 taken 2 times.
✗ Branch 7 not taken.
✗ Branch 8 not taken.
✓ Branch 9 taken 2 times.
✗ Branch 10 not taken.
✓ Branch 11 taken 2 times.
2 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
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 bp::object py_obj = tup[0];
40
1/2
✓ Branch 2 taken 2 times.
✗ Branch 3 not taken.
2 boost::python::extract<std::string> obj_as_string(py_obj.ptr());
41
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 if (obj_as_string.check())
42 {
43
2/4
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 2 times.
✗ Branch 5 not taken.
2 const std::string str = obj_as_string;
44
1/2
✓ Branch 1 taken 2 times.
✗ Branch 2 not taken.
2 obj.loadFromString(str);
45 2 }
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 2 }
53
54 195 static bool getstate_manages_dict()
55 {
56 195 return true;
57 }
58 };
59 } // namespace python
60 } // namespace pinocchio
61
62 #endif // ifndef __pinocchio_python_utils_pickle_hpp__
63