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

Revision 857, 2.1 KB checked in by igarcia, 19 years ago (diff)
Line 
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
14namespace boost { namespace python { namespace api {
15
16struct const_item_policies
17{
18    typedef object key_type;
19    static object get(object const& target, object const& key);
20};
21 
22struct 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//
31template <class U>
32inline object_item
33object_operators<U>::operator[](object_cref key)
34{
35    object_cref2 x = *static_cast<U*>(this);
36    return object_item(x, key);
37}
38
39template <class U>
40inline const_object_item
41object_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
48template <class U>
49template <class T>
50inline const_object_item
51object_operators<U>::operator[](T const& key) const
52{
53    return (*this)[object(key)];
54}
55
56template <class U>
57template <class T>
58inline object_item
59object_operators<U>::operator[](T const& key)
60{
61    return (*this)[object(key)];
62}
63# endif
64
65
66inline object const_item_policies::get(object const& target, object const& key)
67{
68    return getitem(target, key);
69}
70
71inline 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
80inline 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
Note: See TracBrowser for help on using the repository browser.