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