Directory: | ./ |
---|---|
File: | include/pinocchio/bindings/python/utils/comparable.hpp |
Date: | 2024-08-27 18:20:05 |
Exec | Total | Coverage | |
---|---|---|---|
Lines: | 3 | 3 | 100.0% |
Branches: | 2 | 4 | 50.0% |
Line | Branch | Exec | Source |
---|---|---|---|
1 | // | ||
2 | // Copyright (c) 2020 INRIA | ||
3 | // | ||
4 | |||
5 | #ifndef __pinocchio_python_utils_comparable_hpp__ | ||
6 | #define __pinocchio_python_utils_comparable_hpp__ | ||
7 | |||
8 | #include <boost/python.hpp> | ||
9 | |||
10 | namespace pinocchio | ||
11 | { | ||
12 | namespace python | ||
13 | { | ||
14 | |||
15 | namespace bp = boost::python; | ||
16 | |||
17 | /// | ||
18 | /// \brief Add the Python method == and != to allow a comparison of this. | ||
19 | /// | ||
20 | template<class C, bool has_comparison_operators = true> | ||
21 | struct ComparableVisitor | ||
22 | : public bp::def_visitor<ComparableVisitor<C, has_comparison_operators>> | ||
23 | { | ||
24 | template<class PyClass> | ||
25 | 160 | void visit(PyClass & cl) const | |
26 | { | ||
27 |
2/4✓ Branch 2 taken 80 times.
✗ Branch 3 not taken.
✓ Branch 6 taken 80 times.
✗ Branch 7 not taken.
|
160 | cl.def(bp::self == bp::self).def(bp::self != bp::self); |
28 | 160 | } | |
29 | }; | ||
30 | |||
31 | template<class C> | ||
32 | struct ComparableVisitor<C, false> : public bp::def_visitor<ComparableVisitor<C, false>> | ||
33 | { | ||
34 | template<class PyClass> | ||
35 | void visit(PyClass &) const | ||
36 | { | ||
37 | } | ||
38 | }; | ||
39 | } // namespace python | ||
40 | } // namespace pinocchio | ||
41 | |||
42 | #endif // ifndef __pinocchio_python_utils_comparable_hpp__ | ||
43 |