18 :
public boost::python::def_visitor<overload_base_get_item_for_std_map<Container>>
20 typedef typename Container::value_type value_type;
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;
26 void visit(Class & cl)
const 28 cl.def(
"__getitem__", &base_get_item);
32 static boost::python::object
33 base_get_item(boost::python::back_reference<Container &>
container, PyObject * i_)
35 namespace bp = ::boost::python;
37 index_type idx = convert_index(
container.get(), i_);
38 typename Container::iterator i =
container.get().find(idx);
41 PyErr_SetString(PyExc_KeyError,
"Invalid key");
42 bp::throw_error_already_set();
45 typename bp::to_python_indirect<data_type &, bp::detail::make_reference_holder> convert;
46 return bp::object(bp::handle<>(convert(i->second)));
49 static index_type convert_index(Container & , PyObject * i_)
51 namespace bp = ::boost::python;
52 bp::extract<key_type const &> i(i_);
59 bp::extract<key_type> i(i_);
64 PyErr_SetString(PyExc_TypeError,
"Invalid index type");
65 bp::throw_error_already_set();