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 |
|
✗ |
void visit(PyClass& cl) const { |
26 |
|
✗ |
cl.def("copy", ©, bp::arg("self"), "Returns a copy of *this."); |
27 |
|
✗ |
cl.def("__copy__", ©, bp::arg("self"), "Returns a copy of *this."); |
28 |
|
✗ |
cl.def("__deepcopy__", &deepcopy, bp::args("self", "memo"), |
29 |
|
|
"Returns a deep copy of *this."); |
30 |
|
|
} |
31 |
|
|
|
32 |
|
|
private: |
33 |
|
✗ |
static C copy(const C& self) { return C(self); } |
34 |
|
✗ |
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 |
|
|
|