|
9 | 9 |
|
10 | 10 | # include <boost/python/suite/indexing/indexing_suite.hpp> |
11 | 11 | # include <boost/python/iterator.hpp> |
| 12 | +# include <boost/python/call_method.hpp> |
| 13 | +# include <boost/python/tuple.hpp> |
12 | 14 |
|
13 | 15 | namespace boost { namespace python { |
14 | 16 |
|
@@ -55,25 +57,60 @@ namespace boost { namespace python { |
55 | 57 | , typename Container::key_type |
56 | 58 | , typename Container::key_type |
57 | 59 | > |
58 | | - { |
| 60 | + { |
59 | 61 | public: |
60 | 62 |
|
61 | 63 | typedef typename Container::mapped_type data_type; |
62 | 64 | typedef typename Container::key_type key_type; |
63 | 65 | typedef typename Container::key_type index_type; |
64 | 66 | typedef typename Container::size_type size_type; |
65 | 67 | typedef typename Container::difference_type difference_type; |
66 | | - |
| 68 | + |
67 | 69 | template <class Class> |
68 | 70 | static void |
69 | 71 | extension_def(Class& cl) |
70 | 72 | { |
71 | | -// cl |
72 | | -// .def("append", &base_append) |
73 | | -// .def("extend", &base_extend) |
74 | | -// ; |
| 73 | + // Wrap the map's element (value_type) |
| 74 | + std::string elem_name = "map_indexing_suite_"; |
| 75 | + elem_name += cl.ptr()->ob_type->tp_name; // the class name |
| 76 | + elem_name += "_entry"; |
| 77 | + |
| 78 | + typedef typename mpl::if_< |
| 79 | + is_class<typename Container::mapped_type> |
| 80 | + , return_internal_reference<> |
| 81 | + , default_call_policies |
| 82 | + >::type get_data_return_policy; |
| 83 | + |
| 84 | + class_<typename Container::value_type>(elem_name.c_str()) |
| 85 | + .def("__repr__", &DerivedPolicies::print_elem) |
| 86 | + .def("data", &DerivedPolicies::get_data, get_data_return_policy()) |
| 87 | + .def("key", &DerivedPolicies::get_key) |
| 88 | + ; |
75 | 89 | } |
76 | 90 |
|
| 91 | + static object |
| 92 | + print_elem(typename Container::value_type const& e) |
| 93 | + { |
| 94 | + return "(%s, %s)" % make_tuple(e.first, e.second); |
| 95 | + } |
| 96 | + |
| 97 | + static |
| 98 | + typename mpl::if_< |
| 99 | + is_class<typename Container::mapped_type> |
| 100 | + , typename Container::mapped_type& |
| 101 | + , typename Container::mapped_type |
| 102 | + >::type |
| 103 | + get_data(typename Container::value_type& e) |
| 104 | + { |
| 105 | + return e.second; |
| 106 | + } |
| 107 | + |
| 108 | + static typename Container::key_type |
| 109 | + get_key(typename Container::value_type& e) |
| 110 | + { |
| 111 | + return e.first; |
| 112 | + } |
| 113 | + |
77 | 114 | static data_type& |
78 | 115 | get_item(Container& container, index_type i_) |
79 | 116 | { |
|
0 commit comments