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_PROTOCOL_DWA2002615_HPP |
6 | # define OBJECT_PROTOCOL_DWA2002615_HPP |
7 | |
8 | # include <boost/python/detail/prefix.hpp> |
9 | |
10 | # include <boost/python/object_protocol_core.hpp> |
11 | # include <boost/python/object_core.hpp> |
12 | |
13 | # include <boost/detail/workaround.hpp> |
14 | |
15 | namespace boost { namespace python { namespace api { |
16 | |
17 | # if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590)) |
18 | // attempt to use SFINAE to prevent functions accepting T const& from |
19 | // coming up as ambiguous with the one taking a char const* when a |
20 | // string literal is passed |
21 | # define BOOST_PYTHON_NO_ARRAY_ARG(T) , T (*)() = 0 |
22 | # else |
23 | # define BOOST_PYTHON_NO_ARRAY_ARG(T) |
24 | # endif |
25 | |
26 | template <class Target, class Key> |
27 | object getattr(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key)) |
28 | { |
29 | return getattr(target: object(target), key: object(key)); |
30 | } |
31 | |
32 | template <class Target, class Key, class Default> |
33 | object getattr(Target const& target, Key const& key, Default const& default_ BOOST_PYTHON_NO_ARRAY_ARG(Key)) |
34 | { |
35 | return getattr(target: object(target), key: object(key), default_: object(default_)); |
36 | } |
37 | |
38 | |
39 | template <class Key, class Value> |
40 | void setattr(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key)) |
41 | { |
42 | setattr(target, key: object(key), value: object(value)); |
43 | } |
44 | |
45 | template <class Key> |
46 | void delattr(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key)) |
47 | { |
48 | delattr(target, key: object(key)); |
49 | } |
50 | |
51 | template <class Target, class Key> |
52 | object getitem(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key)) |
53 | { |
54 | return getitem(target: object(target), key: object(key)); |
55 | } |
56 | |
57 | |
58 | template <class Key, class Value> |
59 | void setitem(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key)) |
60 | { |
61 | setitem(target, key: object(key), value: object(value)); |
62 | } |
63 | |
64 | template <class Key> |
65 | void delitem(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key)) |
66 | { |
67 | delitem(target, key: object(key)); |
68 | } |
69 | |
70 | template <class Target, class Begin, class End> |
71 | object getslice(Target const& target, Begin const& begin, End const& end) |
72 | { |
73 | return getslice(target: object(target), begin: object(begin), end: object(end)); |
74 | } |
75 | |
76 | template <class Begin, class End, class Value> |
77 | void setslice(object const& target, Begin const& begin, End const& end, Value const& value) |
78 | { |
79 | setslice(target, begin: object(begin), end: object(end), value: object(value)); |
80 | } |
81 | |
82 | template <class Begin, class End> |
83 | void delslice(object const& target, Begin const& begin, End const& end) |
84 | { |
85 | delslice(target, begin: object(begin), end: object(end)); |
86 | } |
87 | |
88 | }}} // namespace boost::python::api |
89 | |
90 | #endif // OBJECT_PROTOCOL_DWA2002615_HPP |
91 | |