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
8 # include <boost/python/detail/prefix.hpp>
10 # include <boost/python/object_protocol_core.hpp>
11 # include <boost/python/object_core.hpp>
13 # include <boost/detail/workaround.hpp>
15 namespace boost { namespace python { namespace api {
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
23 # define BOOST_PYTHON_NO_ARRAY_ARG(T)
26 template <class Target, class Key>
27 object getattr(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
29 return getattr(object(target), object(key));
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))
35 return getattr(object(target), object(key), object(default_));
39 template <class Key, class Value>
40 void setattr(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key))
42 setattr(target, object(key), object(value));
46 void delattr(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
48 delattr(target, object(key));
51 template <class Target, class Key>
52 object getitem(Target const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
54 return getitem(object(target), object(key));
58 template <class Key, class Value>
59 void setitem(object const& target, Key const& key, Value const& value BOOST_PYTHON_NO_ARRAY_ARG(Key))
61 setitem(target, object(key), object(value));
65 void delitem(object const& target, Key const& key BOOST_PYTHON_NO_ARRAY_ARG(Key))
67 delitem(target, object(key));
70 template <class Target, class Begin, class End>
71 object getslice(Target const& target, Begin const& begin, End const& end)
73 return getslice(object(target), object(begin), object(end));
76 template <class Begin, class End, class Value>
77 void setslice(object const& target, Begin const& begin, End const& end, Value const& value)
79 setslice(target, object(begin), object(end), object(value));
82 template <class Begin, class End>
83 void delslice(object const& target, Begin const& begin, End const& end)
85 delslice(target, object(begin), object(end));
88 }}} // namespace boost::python::api
90 #endif // OBJECT_PROTOCOL_DWA2002615_HPP