GCC Code Coverage Report


Directory: ./
File: bindings/python/crocoddyl/utils/copyable.hpp
Date: 2025-01-16 08:47:40
Exec Total Coverage
Lines: 6 7 85.7%
Branches: 3 6 50.0%

Line Branch Exec Source
1 ///////////////////////////////////////////////////////////////////////////////
2 // BSD 3-Clause License
3 //
4 // Copyright (C) 2023-2023, Heriot-Watt University
5 // Copyright note valid unless otherwise stated in individual files.
6 // All rights reserved.
7 ///////////////////////////////////////////////////////////////////////////////
8
9 #ifndef BINDINGS_PYTHON_CROCODDYL_UTILS_COPYABLE_HPP_
10 #define BINDINGS_PYTHON_CROCODDYL_UTILS_COPYABLE_HPP_
11
12 #include <boost/python.hpp>
13
14 namespace crocoddyl {
15 namespace python {
16 namespace bp = boost::python;
17
18 ///
19 /// \brief Add the Python method copy to allow a copy of this by calling the
20 /// copy constructor.
21 ///
22 template <class C>
23 struct CopyableVisitor : public bp::def_visitor<CopyableVisitor<C> > {
24 template <class PyClass>
25 2920 void visit(PyClass& cl) const {
26
1/2
✓ Branch 2 taken 1670 times.
✗ Branch 3 not taken.
2920 cl.def("copy", &copy, bp::arg("self"), "Returns a copy of *this.");
27
1/2
✓ Branch 2 taken 1670 times.
✗ Branch 3 not taken.
2920 cl.def("__copy__", &copy, bp::arg("self"), "Returns a copy of *this.");
28
1/2
✓ Branch 2 taken 1670 times.
✗ Branch 3 not taken.
2920 cl.def("__deepcopy__", &deepcopy, bp::args("self", "memo"),
29 "Returns a deep copy of *this.");
30 2920 }
31
32 private:
33 static C copy(const C& self) { return C(self); }
34 145 static C deepcopy(const C& self, bp::dict) { return C(self); }
35 };
36
37 } // namespace python
38 } // namespace crocoddyl
39
40 #endif // BINDINGS_PYTHON_CROCODDYL_UTILS_COPYABLE_HPP_
41