First public contribution.
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);
35 object_operators<U>::slice(object_cref start, object_cref finish)
37 object_cref2 x = *static_cast<U*>(this);
38 return object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
43 object_operators<U>::slice(object_cref start, object_cref finish) const
45 object_cref2 x = *static_cast<U const*>(this);
46 return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
51 object_operators<U>::slice(slice_nil, object_cref finish)
53 object_cref2 x = *static_cast<U*>(this);
54 return object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
59 object_operators<U>::slice(slice_nil, object_cref finish) const
61 object_cref2 x = *static_cast<U const*>(this);
62 return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
67 object_operators<U>::slice(slice_nil, slice_nil)
69 object_cref2 x = *static_cast<U*>(this);
70 return object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
75 object_operators<U>::slice(slice_nil, slice_nil) const
77 object_cref2 x = *static_cast<U const*>(this);
78 return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
83 object_operators<U>::slice(object_cref start, slice_nil)
85 object_cref2 x = *static_cast<U*>(this);
86 return object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
91 object_operators<U>::slice(object_cref start, slice_nil) const
93 object_cref2 x = *static_cast<U const*>(this);
94 return const_object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
96 # if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
98 template <class T, class V>
99 inline const_object_slice
100 object_operators<U>::slice(T const& start, V const& end) const
103 typename slice_bound<T>::type(start)
104 , typename slice_bound<V>::type(end));
108 template <class T, class V>
110 object_operators<U>::slice(T const& start, V const& end)
113 typename slice_bound<T>::type(start)
114 , typename slice_bound<V>::type(end));
119 inline object const_slice_policies::get(object const& target, key_type const& key)
121 return getslice(target, key.first, key.second);
124 inline object const& slice_policies::set(
126 , key_type const& key
127 , object const& value)
129 setslice(target, key.first, key.second, value);
133 inline void slice_policies::del(
135 , key_type const& key)
137 delslice(target, key.first, key.second);
140 }}} // namespace boost::python::api
142 #endif // OBJECT_SLICES_DWA2002615_HPP