6 #ifndef INDEXING_SUITE_JDG20036_HPP
7 # define INDEXING_SUITE_JDG20036_HPP
9 # include <boost/python/class.hpp>
10 # include <boost/python/def_visitor.hpp>
11 # include <boost/python/register_ptr_to_python.hpp>
12 # include "detail/indexing_suite_detail.hpp"
13 # include <boost/python/return_internal_reference.hpp>
14 # include <boost/python/iterator.hpp>
15 # include <boost/mpl/or.hpp>
16 # include <boost/mpl/not.hpp>
18 namespace boost {
namespace python {
99 ,
class DerivedPolicies
100 ,
bool NoProxy = false
101 ,
bool NoSlice = false
102 ,
class Data =
typename Container::value_type
103 ,
class Index =
typename Container::size_type
104 ,
class Key =
typename Container::value_type
107 :
public def_visitor<
122 , mpl::not_<is_class<Data> > >
125 typedef detail::container_element<Container, Index, DerivedPolicies>
128 #if BOOST_WORKAROUND(BOOST_MSVC, == 1200)
129 struct return_policy : return_internal_reference<> {};
131 typedef return_internal_reference<> return_policy;
134 typedef typename mpl::if_<
136 , iterator<Container>
137 , iterator<Container, return_policy> >::type
140 typedef typename mpl::if_<
142 , detail::no_proxy_helper<
145 , container_element_t
147 , detail::proxy_helper<
150 , container_element_t
154 typedef typename mpl::if_<
156 , detail::no_slice_helper<
162 , detail::slice_helper<
172 template <
class Class>
176 proxy_handler::register_container_element();
179 .def(
"__len__", base_size)
180 .def(
"__setitem__", &base_set_item)
181 .def(
"__delitem__", &base_delete_item)
182 .def(
"__getitem__", &base_get_item)
183 .def(
"__contains__", &base_contains)
184 .def(
"__iter__", def_iterator())
187 DerivedPolicies::extension_def(cl);
190 template <
class Class>
201 base_get_item(back_reference<Container&> container, PyObject* i)
203 if (PySlice_Check(i))
204 return slice_handler::base_get_slice(
205 container.get(),
reinterpret_cast<PySliceObject*
>(i));
207 return proxy_handler::base_get_item_(container, i);
211 base_set_item(Container& container, PyObject* i, PyObject*
v)
213 if (PySlice_Check(i))
215 slice_handler::base_set_slice(container,
216 reinterpret_cast<PySliceObject*>(i), v);
220 extract<Data&> elem(v);
227 convert_index(container, i), elem());
232 extract<Data> elem(v);
238 convert_index(container, i), elem());
242 PyErr_SetString(PyExc_TypeError,
"Invalid assignment");
243 throw_error_already_set();
250 base_delete_item(Container& container, PyObject* i)
252 if (PySlice_Check(i))
254 slice_handler::base_delete_slice(
255 container, reinterpret_cast<PySliceObject*>(i));
259 Index
index = DerivedPolicies::convert_index(container, i);
260 proxy_handler::base_erase_index(container, index, mpl::bool_<NoSlice>());
261 DerivedPolicies::delete_item(container, index);
265 base_size(Container& container)
267 return DerivedPolicies::size(container);
271 base_contains(Container& container, PyObject* key)
273 extract<Key const&>
x(key);
277 return DerivedPolicies::contains(container,
x());
284 return DerivedPolicies::contains(container,
x());
293 #endif // INDEXING_SUITE_JDG20036_HPP
static void extension_def(Class &cl)
void visit(Class &cl) const