Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/utils/copyable.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 9 | 9 | 100.0% |
Branches: | 3 | 6 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2016-2023 CNRS INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_utils_copyable_hpp__ | ||
6 | #define __pinocchio_python_utils_copyable_hpp__ | ||
7 | |||
8 | #include <eigenpy/eigenpy.hpp> | ||
9 | |||
10 | namespace pinocchio | ||
11 | { | ||
12 | namespace python | ||
13 | { | ||
14 | |||
15 | namespace bp = boost::python; | ||
16 | |||
17 | /// | ||
18 | /// \brief Add the Python method copy to allow a copy of this by calling the copy constructor. | ||
19 | /// | ||
20 | template<class C> | ||
21 | struct CopyableVisitor : public bp::def_visitor<CopyableVisitor<C>> | ||
22 | { | ||
23 | template<class PyClass> | ||
24 | 1742 | void visit(PyClass & cl) const | |
25 | { | ||
26 |
1/2✓ Branch 2 taken 1145 times.
✗ Branch 3 not taken.
|
1742 | cl.def("copy", ©, bp::arg("self"), "Returns a copy of *this."); |
27 |
1/2✓ Branch 2 taken 1145 times.
✗ Branch 3 not taken.
|
1742 | cl.def("__copy__", ©, bp::arg("self"), "Returns a copy of *this."); |
28 |
1/2✓ Branch 2 taken 1145 times.
✗ Branch 3 not taken.
|
1742 | cl.def( |
29 | "__deepcopy__", &deepcopy, bp::args("self", "memo"), "Returns a deep copy of *this."); | ||
30 | 1742 | } | |
31 | |||
32 | private: | ||
33 | 26 | static C copy(const C & self) | |
34 | { | ||
35 | 26 | return C(self); | |
36 | } | ||
37 | 1 | static C deepcopy(const C & self, bp::dict) | |
38 | { | ||
39 | 1 | return C(self); | |
40 | } | ||
41 | }; | ||
42 | } // namespace python | ||
43 | } // namespace pinocchio | ||
44 | |||
45 | #endif // ifndef __pinocchio_python_utils_copyable_hpp__ | ||
46 |