Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/utils/pickle-vector.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 13 | 13 | 100.0% |
Branches: | 16 | 30 | 53.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2019-2020 CNRS INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_utils_pickle_vector_hpp__ | ||
6 | #define __pinocchio_python_utils_pickle_vector_hpp__ | ||
7 | |||
8 | #include <boost/python.hpp> | ||
9 | #include <boost/python/tuple.hpp> | ||
10 | #include <boost/python/stl_iterator.hpp> | ||
11 | |||
12 | namespace pinocchio | ||
13 | { | ||
14 | namespace python | ||
15 | { | ||
16 | /// | ||
17 | /// \brief Create a pickle interface for the std::vector and aligned vector | ||
18 | /// | ||
19 | /// \tparam VecType Vector Type to pickle | ||
20 | /// | ||
21 | template<typename VecType> | ||
22 | struct PickleVector : boost::python::pickle_suite | ||
23 | { | ||
24 | 2 | static boost::python::tuple getinitargs(const VecType &) | |
25 | { | ||
26 | 2 | return boost::python::make_tuple(); | |
27 | } | ||
28 | |||
29 | 2 | static boost::python::tuple getstate(boost::python::object op) | |
30 | { | ||
31 | return boost::python::make_tuple( | ||
32 |
3/6✓ Branch 2 taken 1 times.
✗ Branch 3 not taken.
✓ Branch 5 taken 1 times.
✗ Branch 6 not taken.
✓ Branch 8 taken 1 times.
✗ Branch 9 not taken.
|
4 | boost::python::list(boost::python::extract<const VecType &>(op)())); |
33 | } | ||
34 | |||
35 | 2 | static void setstate(boost::python::object op, boost::python::tuple tup) | |
36 | { | ||
37 |
1/2✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
|
2 | if (boost::python::len(tup) > 0) |
38 | { | ||
39 |
2/4✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
|
2 | VecType & o = boost::python::extract<VecType &>(op)(); |
40 |
4/8✓ Branch 1 taken 1 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1 times.
✗ Branch 5 not taken.
✓ Branch 7 taken 1 times.
✗ Branch 8 not taken.
✓ Branch 11 taken 1 times.
✗ Branch 12 not taken.
|
4 | boost::python::stl_input_iterator<typename VecType::value_type> begin(tup[0]), end; |
41 |
3/4✓ Branch 1 taken 101 times.
✗ Branch 2 not taken.
✓ Branch 3 taken 100 times.
✓ Branch 4 taken 1 times.
|
202 | while (begin != end) |
42 | { | ||
43 |
2/4✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 100 times.
✗ Branch 5 not taken.
|
200 | o.push_back(*begin); |
44 |
1/2✓ Branch 1 taken 100 times.
✗ Branch 2 not taken.
|
200 | ++begin; |
45 | } | ||
46 | } | ||
47 | } | ||
48 | |||
49 | 910 | static bool getstate_manages_dict() | |
50 | { | ||
51 | 910 | return true; | |
52 | } | ||
53 | }; | ||
54 | } // namespace python | ||
55 | } // namespace pinocchio | ||
56 | |||
57 | #endif // ifndef __pinocchio_python_utils_pickle_vector_hpp__ | ||
58 |