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>
22 template <
class Container,
bool NoProxy>
25 NoProxy, final_map_derived_policies<Container, NoProxy> > {};
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
120 if (i == container.end())
122 PyErr_SetString(PyExc_KeyError,
"Invalid key");
123 throw_error_already_set();
129 set_item(Container& container, index_type i, data_type
const& v)
143 return container.size();
147 contains(Container& container, key_type
const& key)
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 static void set_item(Container &container, index_type i, data_type const &v)
Container::key_type index_type
static bool compare_index(Container &container, index_type a, index_type b)
Container::key_type key_type
static data_type & get_item(Container &container, index_type i_)
static object print_elem(typename Container::value_type const &e)
static Container::key_type get_key(typename Container::value_type &e)
static mpl::if_< is_class< data_type >, data_type &, data_type >::type get_data(typename Container::value_type &e)
Container::value_type::second_type data_type
Container::size_type size_type
Container::value_type value_type
static void delete_item(Container &container, index_type i)
static size_t size(Container &container)
Container::difference_type difference_type
static bool contains(Container &container, key_type const &key)
static index_type convert_index(Container &container, PyObject *i_)
static void extension_def(Class &cl)