]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
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 | template <class U> | |
48 | template <class T> | |
49 | inline const_object_item | |
50 | object_operators<U>::operator[](T const& key) const | |
51 | { | |
52 | return (*this)[object(key)]; | |
53 | } | |
54 | ||
55 | template <class U> | |
56 | template <class T> | |
57 | inline object_item | |
58 | object_operators<U>::operator[](T const& key) | |
59 | { | |
60 | return (*this)[object(key)]; | |
61 | } | |
62 | ||
63 | inline object const_item_policies::get(object const& target, object const& key) | |
64 | { | |
65 | return getitem(target, key); | |
66 | } | |
67 | ||
68 | inline object const& item_policies::set( | |
69 | object const& target | |
70 | , object const& key | |
71 | , object const& value) | |
72 | { | |
73 | setitem(target, key, value); | |
74 | return value; | |
75 | } | |
76 | ||
77 | inline void item_policies::del( | |
78 | object const& target | |
79 | , object const& key) | |
80 | { | |
81 | delitem(target, key); | |
82 | } | |
83 | ||
84 | }}} // namespace boost::python::api | |
85 | ||
86 | #endif // OBJECT_ITEMS_DWA2002615_HPP |