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 PROXY_DWA2002615_HPP
6 # define PROXY_DWA2002615_HPP
7 # include <boost/python/detail/prefix.hpp>
8 # include <boost/python/object_core.hpp>
9 # include <boost/python/object_operators.hpp>
11 namespace boost
{ namespace python
{ namespace api
{
13 template <class Policies
>
14 class proxy
: public object_operators
<proxy
<Policies
> >
16 typedef typename
Policies::key_type key_type
;
18 # if !defined(BOOST_MSVC) || BOOST_MSVC >= 1300
19 typedef proxy
const& assignment_self
;
21 typedef proxy assignment_self
;
24 proxy(object
const& target
, key_type
const& key
);
25 operator object() const;
27 // to support a[b] = c[d]
28 proxy
const& operator=(assignment_self
) const;
31 inline proxy
const& operator=(T
const& rhs
) const
33 Policies::set(m_target
, m_key
, object(rhs
));
37 public: // implementation detail
47 inline void del(proxy
<T
> const& x
)
56 template <class Policies
>
57 inline proxy
<Policies
>::proxy(object
const& target
, key_type
const& key
)
58 : m_target(target
), m_key(key
)
61 template <class Policies
>
62 inline proxy
<Policies
>::operator object() const
64 return Policies::get(m_target
, m_key
);
67 // to support a[b] = c[d]
68 template <class Policies
>
69 inline proxy
<Policies
> const& proxy
<Policies
>::operator=(typename
proxy::assignment_self rhs
) const
71 return *this = python::object(rhs
);
74 # define BOOST_PYTHON_PROXY_INPLACE(op) \
75 template <class Policies, class R> \
76 proxy<Policies> const& operator op(proxy<Policies> const& lhs, R const& rhs) \
79 return lhs = (old op rhs); \
81 BOOST_PYTHON_PROXY_INPLACE(+=)
82 BOOST_PYTHON_PROXY_INPLACE(-=)
83 BOOST_PYTHON_PROXY_INPLACE(*=)
84 BOOST_PYTHON_PROXY_INPLACE(/=)
85 BOOST_PYTHON_PROXY_INPLACE(%=)
86 BOOST_PYTHON_PROXY_INPLACE(<<=)
87 BOOST_PYTHON_PROXY_INPLACE(>>=)
88 BOOST_PYTHON_PROXY_INPLACE(&=)
89 BOOST_PYTHON_PROXY_INPLACE(^=)
90 BOOST_PYTHON_PROXY_INPLACE(|=)
91 # undef BOOST_PYTHON_PROXY_INPLACE
93 template <class Policies
>
94 inline void proxy
<Policies
>::del() const
96 Policies::del(m_target
, m_key
);
99 }}} // namespace boost::python::api
101 #endif // PROXY_DWA2002615_HPP