pinocchio 4.1.0
A fast and flexible implementation of Rigid Body Dynamics algorithms and their analytical derivatives
Loading...
Searching...
No Matches
std-map.hpp
1//
2// Copyright (c) 2020 INRIA
3//
4
5#pragma once
6
7#include <boost/python/suite/indexing/map_indexing_suite.hpp>
8
9namespace pinocchio
10{
11 namespace python
12 {
13 namespace details
14 {
15 template<typename Container>
17 : public boost::python::def_visitor<overload_base_get_item_for_std_map<Container>>
18 {
19 typedef typename Container::value_type value_type;
20 typedef typename Container::value_type::second_type data_type;
21 typedef typename Container::key_type key_type;
22 typedef typename Container::key_type index_type;
23
24 template<class Class>
25 void visit(Class & cl) const
26 {
27 cl.def("__getitem__", &base_get_item);
28 }
29
30 private:
31 static boost::python::object
32 base_get_item(boost::python::back_reference<Container &> container, PyObject * i_)
33 {
34 namespace bp = ::boost::python;
35
36 index_type idx = convert_index(container.get(), i_);
37 typename Container::iterator i = container.get().find(idx);
38 if (i == container.get().end())
39 {
40 PyErr_SetString(PyExc_KeyError, "Invalid key");
41 bp::throw_error_already_set();
42 }
43
44 typename bp::to_python_indirect<data_type &, bp::detail::make_reference_holder> convert;
45 return bp::object(bp::handle<>(convert(i->second)));
46 }
47
48 static index_type convert_index(Container & /*container*/, PyObject * i_)
49 {
50 namespace bp = ::boost::python;
51 bp::extract<key_type const &> i(i_);
52 if (i.check())
53 {
54 return i();
55 }
56 else
57 {
58 bp::extract<key_type> i(i_);
59 if (i.check())
60 return i();
61 }
62
63 PyErr_SetString(PyExc_TypeError, "Invalid index type");
64 bp::throw_error_already_set();
65 return index_type();
66 }
67 };
68
69 } // namespace details
70 } // namespace python
71} // namespace pinocchio
Specialized containers.
Main pinocchio namespace.
Definition treeview.dox:11