fix doc example typo
[boost.git] / boost / python / object_slices.hpp
blob748c2e954b2f59094bc597764ecaa8a07e95ff5f
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>
14 # include <utility>
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));
37 // implementation
39 template <class U>
40 object_slice
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())));
47 template <class U>
48 const_object_slice
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())));
55 template <class U>
56 object_slice
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())));
63 template <class U>
64 const_object_slice
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())));
71 template <class U>
72 object_slice
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)));
79 template <class U>
80 const_object_slice
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)));
87 template <class U>
88 object_slice
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)));
95 template <class U>
96 const_object_slice
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)));
102 # if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
103 template <class U>
104 template <class T, class V>
105 inline const_object_slice
106 object_operators<U>::slice(T const& start, V const& end) const
108 return this->slice(
109 typename slice_bound<T>::type(start)
110 , typename slice_bound<V>::type(end));
113 template <class U>
114 template <class T, class V>
115 inline object_slice
116 object_operators<U>::slice(T const& start, V const& end)
118 return this->slice(
119 typename slice_bound<T>::type(start)
120 , typename slice_bound<V>::type(end));
122 # endif
125 inline object const_slice_policies::get(object const& target, key_type const& key)
127 return getslice(target, key.first, key.second);
130 inline object const& slice_policies::set(
131 object const& target
132 , key_type const& key
133 , object const& value)
135 setslice(target, key.first, key.second, value);
136 return value;
139 inline void slice_policies::del(
140 object const& target
141 , key_type const& key)
143 delslice(target, key.first, key.second);
146 }}} // namespace boost::python::api
148 #endif // OBJECT_SLICES_DWA2002615_HPP