sl@0
|
1 |
// Copyright David Abrahams 2002.
|
sl@0
|
2 |
// Distributed under the Boost Software License, Version 1.0. (See
|
sl@0
|
3 |
// accompanying file LICENSE_1_0.txt or copy at
|
sl@0
|
4 |
// http://www.boost.org/LICENSE_1_0.txt)
|
sl@0
|
5 |
#ifndef OBJECT_SLICES_DWA2002615_HPP
|
sl@0
|
6 |
# define OBJECT_SLICES_DWA2002615_HPP
|
sl@0
|
7 |
|
sl@0
|
8 |
# include <boost/python/detail/prefix.hpp>
|
sl@0
|
9 |
|
sl@0
|
10 |
# include <boost/python/proxy.hpp>
|
sl@0
|
11 |
# include <boost/python/object_core.hpp>
|
sl@0
|
12 |
# include <boost/python/object_protocol.hpp>
|
sl@0
|
13 |
# include <boost/python/handle.hpp>
|
sl@0
|
14 |
# include <utility>
|
sl@0
|
15 |
|
sl@0
|
16 |
namespace boost { namespace python { namespace api {
|
sl@0
|
17 |
|
sl@0
|
18 |
struct const_slice_policies
|
sl@0
|
19 |
{
|
sl@0
|
20 |
typedef std::pair<handle<>, handle<> > key_type;
|
sl@0
|
21 |
static object get(object const& target, key_type const& key);
|
sl@0
|
22 |
};
|
sl@0
|
23 |
|
sl@0
|
24 |
struct slice_policies : const_slice_policies
|
sl@0
|
25 |
{
|
sl@0
|
26 |
static object const& set(object const& target, key_type const& key, object const& value);
|
sl@0
|
27 |
static void del(object const& target, key_type const& key);
|
sl@0
|
28 |
};
|
sl@0
|
29 |
|
sl@0
|
30 |
//
|
sl@0
|
31 |
// implementation
|
sl@0
|
32 |
//
|
sl@0
|
33 |
template <class U>
|
sl@0
|
34 |
object_slice
|
sl@0
|
35 |
object_operators<U>::slice(object_cref start, object_cref finish)
|
sl@0
|
36 |
{
|
sl@0
|
37 |
object_cref2 x = *static_cast<U*>(this);
|
sl@0
|
38 |
return object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
|
sl@0
|
39 |
}
|
sl@0
|
40 |
|
sl@0
|
41 |
template <class U>
|
sl@0
|
42 |
const_object_slice
|
sl@0
|
43 |
object_operators<U>::slice(object_cref start, object_cref finish) const
|
sl@0
|
44 |
{
|
sl@0
|
45 |
object_cref2 x = *static_cast<U const*>(this);
|
sl@0
|
46 |
return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
|
sl@0
|
47 |
}
|
sl@0
|
48 |
|
sl@0
|
49 |
template <class U>
|
sl@0
|
50 |
object_slice
|
sl@0
|
51 |
object_operators<U>::slice(slice_nil, object_cref finish)
|
sl@0
|
52 |
{
|
sl@0
|
53 |
object_cref2 x = *static_cast<U*>(this);
|
sl@0
|
54 |
return object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
|
sl@0
|
55 |
}
|
sl@0
|
56 |
|
sl@0
|
57 |
template <class U>
|
sl@0
|
58 |
const_object_slice
|
sl@0
|
59 |
object_operators<U>::slice(slice_nil, object_cref finish) const
|
sl@0
|
60 |
{
|
sl@0
|
61 |
object_cref2 x = *static_cast<U const*>(this);
|
sl@0
|
62 |
return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
|
sl@0
|
63 |
}
|
sl@0
|
64 |
|
sl@0
|
65 |
template <class U>
|
sl@0
|
66 |
object_slice
|
sl@0
|
67 |
object_operators<U>::slice(slice_nil, slice_nil)
|
sl@0
|
68 |
{
|
sl@0
|
69 |
object_cref2 x = *static_cast<U*>(this);
|
sl@0
|
70 |
return object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
sl@0
|
71 |
}
|
sl@0
|
72 |
|
sl@0
|
73 |
template <class U>
|
sl@0
|
74 |
const_object_slice
|
sl@0
|
75 |
object_operators<U>::slice(slice_nil, slice_nil) const
|
sl@0
|
76 |
{
|
sl@0
|
77 |
object_cref2 x = *static_cast<U const*>(this);
|
sl@0
|
78 |
return const_object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
|
sl@0
|
79 |
}
|
sl@0
|
80 |
|
sl@0
|
81 |
template <class U>
|
sl@0
|
82 |
object_slice
|
sl@0
|
83 |
object_operators<U>::slice(object_cref start, slice_nil)
|
sl@0
|
84 |
{
|
sl@0
|
85 |
object_cref2 x = *static_cast<U*>(this);
|
sl@0
|
86 |
return object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
|
sl@0
|
87 |
}
|
sl@0
|
88 |
|
sl@0
|
89 |
template <class U>
|
sl@0
|
90 |
const_object_slice
|
sl@0
|
91 |
object_operators<U>::slice(object_cref start, slice_nil) const
|
sl@0
|
92 |
{
|
sl@0
|
93 |
object_cref2 x = *static_cast<U const*>(this);
|
sl@0
|
94 |
return const_object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
|
sl@0
|
95 |
}
|
sl@0
|
96 |
# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
sl@0
|
97 |
template <class U>
|
sl@0
|
98 |
template <class T, class V>
|
sl@0
|
99 |
inline const_object_slice
|
sl@0
|
100 |
object_operators<U>::slice(T const& start, V const& end) const
|
sl@0
|
101 |
{
|
sl@0
|
102 |
return this->slice(
|
sl@0
|
103 |
typename slice_bound<T>::type(start)
|
sl@0
|
104 |
, typename slice_bound<V>::type(end));
|
sl@0
|
105 |
}
|
sl@0
|
106 |
|
sl@0
|
107 |
template <class U>
|
sl@0
|
108 |
template <class T, class V>
|
sl@0
|
109 |
inline object_slice
|
sl@0
|
110 |
object_operators<U>::slice(T const& start, V const& end)
|
sl@0
|
111 |
{
|
sl@0
|
112 |
return this->slice(
|
sl@0
|
113 |
typename slice_bound<T>::type(start)
|
sl@0
|
114 |
, typename slice_bound<V>::type(end));
|
sl@0
|
115 |
}
|
sl@0
|
116 |
# endif
|
sl@0
|
117 |
|
sl@0
|
118 |
|
sl@0
|
119 |
inline object const_slice_policies::get(object const& target, key_type const& key)
|
sl@0
|
120 |
{
|
sl@0
|
121 |
return getslice(target, key.first, key.second);
|
sl@0
|
122 |
}
|
sl@0
|
123 |
|
sl@0
|
124 |
inline object const& slice_policies::set(
|
sl@0
|
125 |
object const& target
|
sl@0
|
126 |
, key_type const& key
|
sl@0
|
127 |
, object const& value)
|
sl@0
|
128 |
{
|
sl@0
|
129 |
setslice(target, key.first, key.second, value);
|
sl@0
|
130 |
return value;
|
sl@0
|
131 |
}
|
sl@0
|
132 |
|
sl@0
|
133 |
inline void slice_policies::del(
|
sl@0
|
134 |
object const& target
|
sl@0
|
135 |
, key_type const& key)
|
sl@0
|
136 |
{
|
sl@0
|
137 |
delslice(target, key.first, key.second);
|
sl@0
|
138 |
}
|
sl@0
|
139 |
|
sl@0
|
140 |
}}} // namespace boost::python::api
|
sl@0
|
141 |
|
sl@0
|
142 |
#endif // OBJECT_SLICES_DWA2002615_HPP
|