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_ITEMS_DWA2002615_HPP
|
---|
6 | # define OBJECT_ITEMS_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 |
|
---|
14 | namespace boost { namespace python { namespace api {
|
---|
15 |
|
---|
16 | struct const_item_policies
|
---|
17 | {
|
---|
18 | typedef object key_type;
|
---|
19 | static object get(object const& target, object const& key);
|
---|
20 | };
|
---|
21 |
|
---|
22 | struct item_policies : const_item_policies
|
---|
23 | {
|
---|
24 | static object const& set(object const& target, object const& key, object const& value);
|
---|
25 | static void del(object const& target, object const& key);
|
---|
26 | };
|
---|
27 |
|
---|
28 | //
|
---|
29 | // implementation
|
---|
30 | //
|
---|
31 | template <class U>
|
---|
32 | inline object_item
|
---|
33 | object_operators<U>::operator[](object_cref key)
|
---|
34 | {
|
---|
35 | object_cref2 x = *static_cast<U*>(this);
|
---|
36 | return object_item(x, key);
|
---|
37 | }
|
---|
38 |
|
---|
39 | template <class U>
|
---|
40 | inline const_object_item
|
---|
41 | object_operators<U>::operator[](object_cref key) const
|
---|
42 | {
|
---|
43 | object_cref2 x = *static_cast<U const*>(this);
|
---|
44 | return const_object_item(x, key);
|
---|
45 | }
|
---|
46 |
|
---|
47 | # if !defined(BOOST_MSVC) || BOOST_MSVC > 1300
|
---|
48 | template <class U>
|
---|
49 | template <class T>
|
---|
50 | inline const_object_item
|
---|
51 | object_operators<U>::operator[](T const& key) const
|
---|
52 | {
|
---|
53 | return (*this)[object(key)];
|
---|
54 | }
|
---|
55 |
|
---|
56 | template <class U>
|
---|
57 | template <class T>
|
---|
58 | inline object_item
|
---|
59 | object_operators<U>::operator[](T const& key)
|
---|
60 | {
|
---|
61 | return (*this)[object(key)];
|
---|
62 | }
|
---|
63 | # endif
|
---|
64 |
|
---|
65 |
|
---|
66 | inline object const_item_policies::get(object const& target, object const& key)
|
---|
67 | {
|
---|
68 | return getitem(target, key);
|
---|
69 | }
|
---|
70 |
|
---|
71 | inline object const& item_policies::set(
|
---|
72 | object const& target
|
---|
73 | , object const& key
|
---|
74 | , object const& value)
|
---|
75 | {
|
---|
76 | setitem(target, key, value);
|
---|
77 | return value;
|
---|
78 | }
|
---|
79 |
|
---|
80 | inline void item_policies::del(
|
---|
81 | object const& target
|
---|
82 | , object const& key)
|
---|
83 | {
|
---|
84 | delitem(target, key);
|
---|
85 | }
|
---|
86 |
|
---|
87 | }}} // namespace boost::python::api
|
---|
88 |
|
---|
89 | #endif // OBJECT_ITEMS_DWA2002615_HPP
|
---|