6 #ifndef MAP_INDEXING_SUITE_JDG20038_HPP
7 # define MAP_INDEXING_SUITE_JDG20038_HPP
10 # include <boost/python/iterator.hpp>
11 # include <boost/python/call_method.hpp>
12 # include <boost/python/tuple.hpp>
14 namespace boost {
namespace python {
17 template <
class Container,
bool NoProxy,
class DerivedPolicies>
18 class map_indexing_suite;
22 template <
class Container,
bool NoProxy>
23 class final_map_derived_policies
24 :
public map_indexing_suite<Container,
25 NoProxy, final_map_derived_policies<Container, NoProxy> > {};
48 = detail::final_map_derived_policies<Container, NoProxy> >
49 class map_indexing_suite
50 :
public indexing_suite<
55 , typename Container::value_type::second_type
56 , typename Container::key_type
57 , typename Container::key_type
63 typedef typename Container::value_type::second_type
data_type;
69 template <
class Class>
74 std::string elem_name =
"map_indexing_suite_";
75 object class_name(cl.attr(
"__name__"));
76 extract<std::string> class_name_extractor(class_name);
77 elem_name += class_name_extractor();
78 elem_name +=
"_entry";
80 typedef typename mpl::if_<
82 , return_internal_reference<>
83 , default_call_policies
84 >::type get_data_return_policy;
86 class_<value_type>(elem_name.c_str())
87 .def(
"__repr__", &DerivedPolicies::print_elem)
88 .def(
"data", &DerivedPolicies::get_data, get_data_return_policy())
89 .def(
"key", &DerivedPolicies::get_key)
96 return "(%s, %s)" % python::make_tuple(e.first, e.second);
110 static typename Container::key_type
119 typename Container::iterator i = container.find(i_);
120 if (i == container.end())
122 PyErr_SetString(PyExc_KeyError,
"Invalid key");
123 throw_error_already_set();
143 return container.size();
149 return container.find(key) != container.end();
155 return container.key_comp()(
a,
b);
161 extract<key_type const&> i(i_);
168 extract<key_type> i(i_);
173 PyErr_SetString(PyExc_TypeError,
"Invalid index type");
174 throw_error_already_set();
181 #endif // MAP_INDEXING_SUITE_JDG20038_HPP