1 // Copyright David Abrahams 2002.
2 // Distributed under the Boost Software License, Version 1.0. (See
3 // accompanying file LICENSE_1_0.txt or copy at
4 // http://www.boost.org/LICENSE_1_0.txt)
5 #ifndef OBJECT_SLICES_DWA2002615_HPP
6 # define OBJECT_SLICES_DWA2002615_HPP
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/proxy.hpp>
11 # include <boost/python/object_core.hpp>
12 # include <boost/python/object_protocol.hpp>
13 # include <boost/python/handle.hpp>
16 namespace boost { namespace python { namespace api {
18 struct const_slice_policies
20 typedef std::pair<handle<>, handle<> > key_type;
21 static object get(object const& target, key_type const& key);
24 struct slice_policies : const_slice_policies
26 static object const& set(object const& target, key_type const& key, object const& value);
27 static void del(object const& target, key_type const& key);
30 template <class T, class U>
31 inline slice_policies::key_type slice_key(T x, U y)
33 return slice_policies::key_type(handle<>(x), handle<>(y));
41 object_operators<U>::slice(object_cref start, object_cref finish)
43 object_cref2 x = *static_cast<U*>(this);
44 return object_slice(x, api::slice_key(borrowed(start.ptr()), borrowed(finish.ptr())));
49 object_operators<U>::slice(object_cref start, object_cref finish) const
51 object_cref2 x = *static_cast<U const*>(this);
52 return const_object_slice(x, api::slice_key(borrowed(start.ptr()), borrowed(finish.ptr())));
57 object_operators<U>::slice(slice_nil, object_cref finish)
59 object_cref2 x = *static_cast<U*>(this);
60 return object_slice(x, api::slice_key(allow_null((PyObject*)0), borrowed(finish.ptr())));
65 object_operators<U>::slice(slice_nil, object_cref finish) const
67 object_cref2 x = *static_cast<U const*>(this);
68 return const_object_slice(x, api::slice_key(allow_null((PyObject*)0), borrowed(finish.ptr())));
73 object_operators<U>::slice(slice_nil, slice_nil)
75 object_cref2 x = *static_cast<U*>(this);
76 return object_slice(x, api::slice_key(allow_null((PyObject*)0), allow_null((PyObject*)0)));
81 object_operators<U>::slice(slice_nil, slice_nil) const
83 object_cref2 x = *static_cast<U const*>(this);
84 return const_object_slice(x, api::slice_key(allow_null((PyObject*)0), allow_null((PyObject*)0)));
89 object_operators<U>::slice(object_cref start, slice_nil)
91 object_cref2 x = *static_cast<U*>(this);
92 return object_slice(x, api::slice_key(borrowed(start.ptr()), allow_null((PyObject*)0)));
97 object_operators<U>::slice(object_cref start, slice_nil) const
99 object_cref2 x = *static_cast<U const*>(this);
100 return const_object_slice(x, api::slice_key(borrowed(start.ptr()), allow_null((PyObject*)0)));
104 template <class T, class V>
105 inline const_object_slice
106 object_operators<U>::slice(T const& start, V const& end) const
109 typename slice_bound<T>::type(start)
110 , typename slice_bound<V>::type(end));
114 template <class T, class V>
116 object_operators<U>::slice(T const& start, V const& end)
119 typename slice_bound<T>::type(start)
120 , typename slice_bound<V>::type(end));
123 inline object const_slice_policies::get(object const& target, key_type const& key)
125 return getslice(target, key.first, key.second);
128 inline object const& slice_policies::set(
130 , key_type const& key
131 , object const& value)
133 setslice(target, key.first, key.second, value);
137 inline void slice_policies::del(
139 , key_type const& key)
141 delslice(target, key.first, key.second);
144 }}} // namespace boost::python::api
146 #endif // OBJECT_SLICES_DWA2002615_HPP