1 |
|
|
// |
2 |
|
|
// Copyright (c) 2016-2023 CNRS INRIA |
3 |
|
|
// |
4 |
|
|
|
5 |
|
|
#ifndef __pinocchio_python_utils_copyable_hpp__ |
6 |
|
|
#define __pinocchio_python_utils_copyable_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 copy to allow a copy of this by calling the copy constructor. |
19 |
|
|
/// |
20 |
|
|
template<class C> |
21 |
|
|
struct CopyableVisitor |
22 |
|
|
: public bp::def_visitor< CopyableVisitor<C> > |
23 |
|
|
{ |
24 |
|
|
template<class PyClass> |
25 |
|
247 |
void visit(PyClass & cl) const |
26 |
|
|
{ |
27 |
✓✗ |
247 |
cl.def("copy",©,bp::arg("self"),"Returns a copy of *this."); |
28 |
✓✗ |
247 |
cl.def("__copy__", ©,bp::arg("self"),"Returns a copy of *this."); |
29 |
✓✗ |
247 |
cl.def("__deepcopy__", &deepcopy,bp::args("self","memo"),"Returns a deep copy of *this."); |
30 |
|
247 |
} |
31 |
|
|
|
32 |
|
|
private: |
33 |
|
7 |
static C copy(const C & self) { return C(self); } |
34 |
|
|
static C deepcopy(const C & self, bp::dict) { return C(self); } |
35 |
|
|
}; |
36 |
|
|
} // namespace python |
37 |
|
|
} // namespace pinocchio |
38 |
|
|
|
39 |
|
|
#endif // ifndef __pinocchio_python_utils_copyable_hpp__ |