Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/multibody/joint/joints-variant.hpp |
Date: | 2025-02-12 21:03:38 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 19 | 23 | 82.6% |
Branches: | 13 | 30 | 43.3% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2015-2021 CNRS INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_joints_variant_hpp__ | ||
6 | #define __pinocchio_python_joints_variant_hpp__ | ||
7 | |||
8 | #include <boost/algorithm/string/replace.hpp> | ||
9 | |||
10 | #include <boost/python.hpp> | ||
11 | |||
12 | #include "pinocchio/multibody/joint/joint-collection.hpp" | ||
13 | #include "pinocchio/bindings/python/multibody/joint/joints-models.hpp" | ||
14 | #include "pinocchio/bindings/python/multibody/joint/joints-datas.hpp" | ||
15 | #include "pinocchio/bindings/python/utils/printable.hpp" | ||
16 | |||
17 | namespace pinocchio | ||
18 | { | ||
19 | namespace python | ||
20 | { | ||
21 | namespace bp = boost::python; | ||
22 | |||
23 | template<typename T> | ||
24 | 14352 | std::string sanitizedClassname() | |
25 | { | ||
26 |
1/2✓ Branch 2 taken 7176 times.
✗ Branch 3 not taken.
|
14352 | std::string className = boost::replace_all_copy(T::classname(), "<", "_"); |
27 |
1/2✓ Branch 1 taken 7176 times.
✗ Branch 2 not taken.
|
14352 | boost::replace_all(className, ">", ""); |
28 | 14352 | return className; | |
29 | } | ||
30 | |||
31 | template<typename VariantType> | ||
32 | struct JointVariantVisitor : boost::static_visitor<PyObject *> | ||
33 | { | ||
34 | ✗ | static result_type convert(VariantType const & jv) | |
35 | { | ||
36 | ✗ | return apply_visitor(JointVariantVisitor<VariantType>(), jv); | |
37 | } | ||
38 | |||
39 | template<typename T> | ||
40 | ✗ | result_type operator()(T const & t) const | |
41 | { | ||
42 | ✗ | return boost::python::incref(boost::python::object(t).ptr()); | |
43 | } | ||
44 | }; | ||
45 | |||
46 | struct JointDataExposer | ||
47 | { | ||
48 | template<class T> | ||
49 | 3588 | void operator()(T) | |
50 | { | ||
51 | 3588 | expose_joint_data<T>( | |
52 |
3/6✓ Branch 1 taken 1794 times.
✗ Branch 2 not taken.
✓ Branch 5 taken 1794 times.
✗ Branch 6 not taken.
✓ Branch 9 taken 1794 times.
✗ Branch 10 not taken.
|
7176 | bp::class_<T>( |
53 | 3588 | sanitizedClassname<T>().c_str(), sanitizedClassname<T>().c_str(), bp::init<>()) | |
54 |
1/2✓ Branch 1 taken 1794 times.
✗ Branch 2 not taken.
|
3588 | .def(JointDataBasePythonVisitor<T>()) |
55 |
2/4✓ Branch 1 taken 1794 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 390 times.
✗ Branch 5 not taken.
|
3588 | .def(PrintableVisitor<T>())); |
56 | 3588 | bp::implicitly_convertible<T, context::JointData>(); | |
57 | 3588 | } | |
58 | }; | ||
59 | |||
60 | struct JointModelExposer | ||
61 | { | ||
62 | template<class T> | ||
63 | 3588 | void operator()(T) | |
64 | { | ||
65 | 3588 | expose_joint_model<T>( | |
66 |
2/4✓ Branch 3 taken 1794 times.
✗ Branch 4 not taken.
✓ Branch 7 taken 1794 times.
✗ Branch 8 not taken.
|
7176 | bp::class_<T>( |
67 | sanitizedClassname<T>().c_str(), sanitizedClassname<T>().c_str(), bp::no_init) | ||
68 |
1/2✓ Branch 1 taken 1794 times.
✗ Branch 2 not taken.
|
3588 | .def(JointModelBasePythonVisitor<T>()) |
69 |
2/4✓ Branch 1 taken 1794 times.
✗ Branch 2 not taken.
✓ Branch 4 taken 1173 times.
✗ Branch 5 not taken.
|
3588 | .def(PrintableVisitor<T>())); |
70 | 3588 | bp::implicitly_convertible<T, context::JointModel>(); | |
71 | 3588 | } | |
72 | }; | ||
73 | |||
74 | } // namespace python | ||
75 | } // namespace pinocchio | ||
76 | |||
77 | #endif // ifndef __pinocchio_python_joints_variant_hpp__ | ||
78 |