source: NonGTP/Boost/boost/python/object_slices.hpp @ 857

Revision 857, 4.0 KB checked in by igarcia, 19 years ago (diff)
RevLine 
[857]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
7
8# include <boost/python/detail/prefix.hpp>
9
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>
15
16namespace boost { namespace python { namespace api {
17
18struct const_slice_policies
19{
20    typedef std::pair<handle<>, handle<> > key_type;
21    static object get(object const& target, key_type const& key);
22};
23 
24struct slice_policies : const_slice_policies
25{
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);
28};
29
30//
31// implementation
32//
33template <class U>
34object_slice
35object_operators<U>::slice(object_cref start, object_cref finish)
36{
37    object_cref2 x = *static_cast<U*>(this);
38    return object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
39}
40
41template <class U>
42const_object_slice
43object_operators<U>::slice(object_cref start, object_cref finish) const
44{
45    object_cref2 x = *static_cast<U const*>(this);
46    return const_object_slice(x, std::make_pair(borrowed(start.ptr()), borrowed(finish.ptr())));
47}
48
49template <class U>
50object_slice
51object_operators<U>::slice(slice_nil, object_cref finish)
52{
53    object_cref2 x = *static_cast<U*>(this);
54    return object_slice(x, std::make_pair(allow_null((PyObject*)0), borrowed(finish.ptr())));
55}
56
57template <class U>
58const_object_slice
59object_operators<U>::slice(slice_nil, object_cref finish) const
60{
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())));
63}
64
65template <class U>
66object_slice
67object_operators<U>::slice(slice_nil, slice_nil)
68{
69    object_cref2 x = *static_cast<U*>(this);
70    return object_slice(x, std::make_pair(allow_null((PyObject*)0), allow_null((PyObject*)0)));
71}
72
73template <class U>
74const_object_slice
75object_operators<U>::slice(slice_nil, slice_nil) const
76{
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)));
79}
80
81template <class U>
82object_slice
83object_operators<U>::slice(object_cref start, slice_nil)
84{
85    object_cref2 x = *static_cast<U*>(this);
86    return object_slice(x, std::make_pair(borrowed(start.ptr()), allow_null((PyObject*)0)));
87}
88
89template <class U>
90const_object_slice
91object_operators<U>::slice(object_cref start, slice_nil) const
92{
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)));
95}
96# if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
97template <class U>
98template <class T, class V>
99inline const_object_slice
100object_operators<U>::slice(T const& start, V const& end) const
101{
102    return this->slice(
103        typename slice_bound<T>::type(start)
104        , typename slice_bound<V>::type(end));
105}
106
107template <class U>
108template <class T, class V>
109inline object_slice
110object_operators<U>::slice(T const& start, V const& end)
111{
112    return this->slice(
113        typename slice_bound<T>::type(start)
114        , typename slice_bound<V>::type(end));
115}
116# endif
117
118
119inline object const_slice_policies::get(object const& target, key_type const& key)
120{
121    return getslice(target, key.first, key.second);
122}
123
124inline object const& slice_policies::set(
125    object const& target
126    , key_type const& key
127    , object const& value)
128{
129    setslice(target, key.first, key.second, value);
130    return value;
131}
132
133inline void slice_policies::del(
134    object const& target
135    , key_type const& key)
136{
137    delslice(target, key.first, key.second);
138}
139
140}}} // namespace boost::python::api
141
142#endif // OBJECT_SLICES_DWA2002615_HPP
Note: See TracBrowser for help on using the repository browser.