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


eigenpy
Author(s): Justin Carpentier, Nicolas Mansard
autogenerated on Fri Jun 14 2024 02:15:58