| Directory: | ./ |
|---|---|
| File: | include/multicontact-api/bindings/python/utils/printable.hpp |
| Date: | 2025-04-05 01:06:26 |
| Exec | Total | Coverage | |
|---|---|---|---|
| Lines: | 4 | 4 | 100.0% |
| Branches: | 2 | 4 | 50.0% |
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | // Copyright (c) 2015-2018, CNRS | ||
| 2 | // Authors: Justin Carpentier <jcarpent@laas.fr> | ||
| 3 | |||
| 4 | #ifndef __multicontact_api_python_utils_printable_hpp__ | ||
| 5 | #define __multicontact_api_python_utils_printable_hpp__ | ||
| 6 | |||
| 7 | #include "multicontact-api/bindings/python/fwd.hpp" | ||
| 8 | |||
| 9 | namespace multicontact_api { | ||
| 10 | namespace python { | ||
| 11 | |||
| 12 | namespace bp = boost::python; | ||
| 13 | |||
| 14 | /// | ||
| 15 | /// \brief Set the Python method __str__ and __repr__ to use the overloading | ||
| 16 | /// operator<<. | ||
| 17 | /// | ||
| 18 | template <class C> | ||
| 19 | struct PrintableVisitor : public bp::def_visitor<PrintableVisitor<C> > { | ||
| 20 | template <class PyClass> | ||
| 21 | 9 | void visit(PyClass& cl) const { | |
| 22 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | cl.def(bp::self_ns::str(bp::self_ns::self)) |
| 23 |
1/2✓ Branch 2 taken 9 times.
✗ Branch 3 not taken.
|
9 | .def(bp::self_ns::repr(bp::self_ns::self)); |
| 24 | 9 | } | |
| 25 | }; | ||
| 26 | |||
| 27 | } // namespace python | ||
| 28 | } // namespace multicontact_api | ||
| 29 | |||
| 30 | #endif // ifndef __multicontact_api_python_utils_printable_hpp__ | ||
| 31 |