std-map.hpp
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 INRIA
3 //
4 
5 #ifndef __pinocchio_python_utils_map_hpp__
6 #define __pinocchio_python_utils_map_hpp__
7 
8 #include <boost/python/suite/indexing/map_indexing_suite.hpp>
9 
10 namespace pinocchio
11 {
12  namespace python
13  {
14  namespace details
15  {
16  template<typename Container>
18  : public boost::python::def_visitor< overload_base_get_item_for_std_map<Container> >
19  {
21  typedef typename Container::value_type::second_type data_type;
22  typedef typename Container::key_type key_type;
23  typedef typename Container::key_type index_type;
24 
25  template <class Class>
26  void visit(Class& cl) const
27  {
28  cl
29  .def("__getitem__", &base_get_item);
30  }
31 
32  private:
33 
34  static boost::python::object
35  base_get_item(boost::python::back_reference<Container&> container, PyObject* i_)
36  {
37  namespace bp = ::boost::python;
38 
39  index_type idx = convert_index(container.get(), i_);
40  typename Container::iterator i = container.get().find(idx);
41  if (i == container.get().end())
42  {
43  PyErr_SetString(PyExc_KeyError, "Invalid key");
44  bp::throw_error_already_set();
45  }
46 
47  typename bp::to_python_indirect<data_type&,bp::detail::make_reference_holder> convert;
48  return bp::object(bp::handle<>(convert(i->second)));
49  }
50 
51  static index_type
52  convert_index(Container& /*container*/, PyObject* i_)
53  {
54  namespace bp = ::boost::python;
55  bp::extract<key_type const&> i(i_);
56  if (i.check())
57  {
58  return i();
59  }
60  else
61  {
62  bp::extract<key_type> i(i_);
63  if (i.check())
64  return i();
65  }
66 
67  PyErr_SetString(PyExc_TypeError, "Invalid index type");
68  bp::throw_error_already_set();
69  return index_type();
70  }
71  };
72 
73  }
74  }
75 }
76 
77 #endif // ifndef __pinocchio_python_utils_map_hpp__
static index_type convert_index(Container &, PyObject *i_)
Definition: std-map.hpp:52
Scalar value_type
Definition: eigen_plugin.hpp:2
static boost::python::object base_get_item(boost::python::back_reference< Container & > container, PyObject *i_)
Definition: std-map.hpp:35
Main pinocchio namespace.
Definition: timings.cpp:30


pinocchio
Author(s):
autogenerated on Tue Jun 1 2021 02:45:04