GCC Code Coverage Report
Directory: ./ Exec Total Coverage
File: include/pinocchio/bindings/python/multibody/joint/joints-variant.hpp Lines: 14 14 100.0 %
Date: 2023-08-09 08:43:58 Branches: 13 26 50.0 %

Line Branch Exec Source
1
//
2
// Copyright (c) 2015-2021 CNRS INRIA
3
//
4
5
#ifndef __pinocchio_python_joints_variant_hpp__
6
#define __pinocchio_python_joints_variant_hpp__
7
8
#include <boost/algorithm/string/replace.hpp>
9
10
#include <boost/python.hpp>
11
12
#include "pinocchio/multibody/joint/joint-collection.hpp"
13
#include "pinocchio/bindings/python/multibody/joint/joints-models.hpp"
14
#include "pinocchio/bindings/python/multibody/joint/joints-datas.hpp"
15
#include "pinocchio/bindings/python/utils/printable.hpp"
16
17
namespace pinocchio
18
{
19
  namespace python
20
  {
21
    namespace bp = boost::python;
22
23
    template<typename T>
24
3192
    std::string sanitizedClassname()
25
    {
26
3192
        std::string className = boost::replace_all_copy(T::classname(), "<", "_");
27
3192
        boost::replace_all(className, ">", "");
28
3192
        return className;
29
    }
30
31
    template<typename VariantType>
32
    struct JointVariantVisitor : boost::static_visitor<PyObject *>
33
    {
34
      static result_type convert(VariantType const & jv)
35
      {
36
        return apply_visitor(JointVariantVisitor<VariantType>(), jv);
37
      }
38
39
      template<typename T>
40
      result_type operator()(T const & t) const
41
      {
42
        return boost::python::incref(boost::python::object(t).ptr());
43
      }
44
    };
45
46
    struct JointDataExposer
47
    {
48
      template<class T>
49
798
      void operator()(T)
50
      {
51
798
        expose_joint_data<T>(
52
            bp::class_<T>(sanitizedClassname<T>().c_str(),
53
                          sanitizedClassname<T>().c_str(),
54
                          bp::init<>())
55
            .def(JointDataDerivedPythonVisitor<T>())
56


1596
            .def(PrintableVisitor<T>())
57
        );
58
798
        bp::implicitly_convertible<T,pinocchio::JointData>();
59
798
      }
60
    };
61
62
    struct JointModelExposer
63
    {
64
      template<class T>
65
798
      void operator()(T)
66
      {
67
798
        expose_joint_model<T>(
68
            bp::class_<T>(sanitizedClassname<T>().c_str(),
69
                          sanitizedClassname<T>().c_str(),
70
                          bp::no_init)
71
            .def(JointModelDerivedPythonVisitor<T>())
72


1596
            .def(PrintableVisitor<T>())
73
        );
74
798
        bp::implicitly_convertible<T,pinocchio::JointModel>();
75
798
      }
76
    };
77
78
79
  } // namespace python
80
} // namespace pinocchio
81
82
#endif // ifndef __pinocchio_python_joints_variant_hpp__