diff -r 000000000000 -r e4d67989cc36 ossrv_pub/boost_apis/boost/python/proxy.hpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/ossrv_pub/boost_apis/boost/python/proxy.hpp Tue Feb 02 02:01:42 2010 +0200 @@ -0,0 +1,101 @@ +// Copyright David Abrahams 2002. +// Distributed under the Boost Software License, Version 1.0. (See +// accompanying file LICENSE_1_0.txt or copy at +// http://www.boost.org/LICENSE_1_0.txt) +#ifndef PROXY_DWA2002615_HPP +# define PROXY_DWA2002615_HPP +# include +# include +# include + +namespace boost { namespace python { namespace api { + +template +class proxy : public object_operators > +{ + typedef typename Policies::key_type key_type; + +# if !defined(BOOST_MSVC) || BOOST_MSVC >= 1300 + typedef proxy const& assignment_self; +# else + typedef proxy assignment_self; +# endif + public: + proxy(object const& target, key_type const& key); + operator object() const; + + // to support a[b] = c[d] + proxy const& operator=(assignment_self) const; + + template + inline proxy const& operator=(T const& rhs) const + { + Policies::set(m_target, m_key, object(rhs)); + return *this; + } + + public: // implementation detail + void del() const; + + private: + object m_target; + key_type m_key; +}; + + +template +inline void del(proxy const& x) +{ + x.del(); +} + +// +// implementation +// + +template +inline proxy::proxy(object const& target, key_type const& key) + : m_target(target), m_key(key) +{} + +template +inline proxy::operator object() const +{ + return Policies::get(m_target, m_key); +} + +// to support a[b] = c[d] +template +inline proxy const& proxy::operator=(typename proxy::assignment_self rhs) const +{ + return *this = python::object(rhs); +} + +# define BOOST_PYTHON_PROXY_INPLACE(op) \ +template \ +proxy const& operator op(proxy const& lhs, R const& rhs) \ +{ \ + object old(lhs); \ + return lhs = (old op rhs); \ +} +BOOST_PYTHON_PROXY_INPLACE(+=) +BOOST_PYTHON_PROXY_INPLACE(-=) +BOOST_PYTHON_PROXY_INPLACE(*=) +BOOST_PYTHON_PROXY_INPLACE(/=) +BOOST_PYTHON_PROXY_INPLACE(%=) +BOOST_PYTHON_PROXY_INPLACE(<<=) +BOOST_PYTHON_PROXY_INPLACE(>>=) +BOOST_PYTHON_PROXY_INPLACE(&=) +BOOST_PYTHON_PROXY_INPLACE(^=) +BOOST_PYTHON_PROXY_INPLACE(|=) +# undef BOOST_PYTHON_PROXY_INPLACE + +template +inline void proxy::del() const +{ + Policies::del(m_target, m_key); +} + +}}} // namespace boost::python::api + +#endif // PROXY_DWA2002615_HPP