1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/proxy.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,101 @@
1.4 +// Copyright David Abrahams 2002.
1.5 +// Distributed under the Boost Software License, Version 1.0. (See
1.6 +// accompanying file LICENSE_1_0.txt or copy at
1.7 +// http://www.boost.org/LICENSE_1_0.txt)
1.8 +#ifndef PROXY_DWA2002615_HPP
1.9 +# define PROXY_DWA2002615_HPP
1.10 +# include <boost/python/detail/prefix.hpp>
1.11 +# include <boost/python/object_core.hpp>
1.12 +# include <boost/python/object_operators.hpp>
1.13 +
1.14 +namespace boost { namespace python { namespace api {
1.15 +
1.16 +template <class Policies>
1.17 +class proxy : public object_operators<proxy<Policies> >
1.18 +{
1.19 + typedef typename Policies::key_type key_type;
1.20 +
1.21 +# if !defined(BOOST_MSVC) || BOOST_MSVC >= 1300
1.22 + typedef proxy const& assignment_self;
1.23 +# else
1.24 + typedef proxy assignment_self;
1.25 +# endif
1.26 + public:
1.27 + proxy(object const& target, key_type const& key);
1.28 + operator object() const;
1.29 +
1.30 + // to support a[b] = c[d]
1.31 + proxy const& operator=(assignment_self) const;
1.32 +
1.33 + template <class T>
1.34 + inline proxy const& operator=(T const& rhs) const
1.35 + {
1.36 + Policies::set(m_target, m_key, object(rhs));
1.37 + return *this;
1.38 + }
1.39 +
1.40 + public: // implementation detail
1.41 + void del() const;
1.42 +
1.43 + private:
1.44 + object m_target;
1.45 + key_type m_key;
1.46 +};
1.47 +
1.48 +
1.49 +template <class T>
1.50 +inline void del(proxy<T> const& x)
1.51 +{
1.52 + x.del();
1.53 +}
1.54 +
1.55 +//
1.56 +// implementation
1.57 +//
1.58 +
1.59 +template <class Policies>
1.60 +inline proxy<Policies>::proxy(object const& target, key_type const& key)
1.61 + : m_target(target), m_key(key)
1.62 +{}
1.63 +
1.64 +template <class Policies>
1.65 +inline proxy<Policies>::operator object() const
1.66 +{
1.67 + return Policies::get(m_target, m_key);
1.68 +}
1.69 +
1.70 +// to support a[b] = c[d]
1.71 +template <class Policies>
1.72 +inline proxy<Policies> const& proxy<Policies>::operator=(typename proxy::assignment_self rhs) const
1.73 +{
1.74 + return *this = python::object(rhs);
1.75 +}
1.76 +
1.77 +# define BOOST_PYTHON_PROXY_INPLACE(op) \
1.78 +template <class Policies, class R> \
1.79 +proxy<Policies> const& operator op(proxy<Policies> const& lhs, R const& rhs) \
1.80 +{ \
1.81 + object old(lhs); \
1.82 + return lhs = (old op rhs); \
1.83 +}
1.84 +BOOST_PYTHON_PROXY_INPLACE(+=)
1.85 +BOOST_PYTHON_PROXY_INPLACE(-=)
1.86 +BOOST_PYTHON_PROXY_INPLACE(*=)
1.87 +BOOST_PYTHON_PROXY_INPLACE(/=)
1.88 +BOOST_PYTHON_PROXY_INPLACE(%=)
1.89 +BOOST_PYTHON_PROXY_INPLACE(<<=)
1.90 +BOOST_PYTHON_PROXY_INPLACE(>>=)
1.91 +BOOST_PYTHON_PROXY_INPLACE(&=)
1.92 +BOOST_PYTHON_PROXY_INPLACE(^=)
1.93 +BOOST_PYTHON_PROXY_INPLACE(|=)
1.94 +# undef BOOST_PYTHON_PROXY_INPLACE
1.95 +
1.96 +template <class Policies>
1.97 +inline void proxy<Policies>::del() const
1.98 +{
1.99 + Policies::del(m_target, m_key);
1.100 +}
1.101 +
1.102 +}}} // namespace boost::python::api
1.103 +
1.104 +#endif // PROXY_DWA2002615_HPP