copyable.hpp 813 Bytes
Newer Older
1
//
Justin Carpentier's avatar
Justin Carpentier committed
2
// Copyright (c) 2016-2021 CNRS INRIA
3
4
//

5
6
#ifndef __pinocchio_python_utils_copyable_hpp__
#define __pinocchio_python_utils_copyable_hpp__
7
8
9

#include <boost/python.hpp>

10
namespace pinocchio
11
12
13
14
15
16
17
18
19
20
{
  namespace python
  {
    
    namespace bp = boost::python;
    
    ///
    /// \brief Add the Python method copy to allow a copy of this by calling the copy constructor.
    ///
    template<class C>
Justin Carpentier's avatar
Justin Carpentier committed
21
22
    struct CopyableVisitor
    : public bp::def_visitor< CopyableVisitor<C> >
23
24
25
    {
      template<class PyClass>
      void visit(PyClass & cl) const
Justin Carpentier's avatar
Justin Carpentier committed
26
      { cl.def("copy",&copy,bp::arg("self"),"Returns a copy of *this."); }
27
28
29
30
31
      
    private:
      static C copy(const C & self) { return C(self); }
    };
  } // namespace python
32
} // namespace pinocchio
33

34
#endif // ifndef __pinocchio_python_utils_copyable_hpp__