Back to home page

EIC code displayed by LXR

 
 

    


Warning, file /include/boost/python/proxy.hpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 // Copyright David Abrahams 2002.
0002 // Distributed under the Boost Software License, Version 1.0. (See
0003 // accompanying file LICENSE_1_0.txt or copy at
0004 // http://www.boost.org/LICENSE_1_0.txt)
0005 #ifndef PROXY_DWA2002615_HPP
0006 # define PROXY_DWA2002615_HPP
0007 # include <boost/python/detail/prefix.hpp>
0008 # include <boost/python/object_core.hpp>
0009 # include <boost/python/object_operators.hpp>
0010 
0011 namespace boost { namespace python { namespace api {
0012 
0013 template <class Policies>
0014 class proxy : public object_operators<proxy<Policies> >
0015 {
0016     typedef typename Policies::key_type key_type;
0017     
0018     typedef proxy const& assignment_self;
0019  public:
0020     proxy(object const& target, key_type const& key);
0021     operator object() const;
0022 
0023     // to support a[b] = c[d]
0024     proxy const& operator=(assignment_self) const;
0025     
0026     template <class T>
0027     inline proxy const& operator=(T const& rhs) const
0028     {
0029         Policies::set(m_target, m_key, object(rhs));
0030         return *this;
0031     }
0032 
0033  public: // implementation detail
0034     void del() const;
0035         
0036  private:
0037     object m_target;
0038     key_type m_key;
0039 };
0040 
0041 
0042 template <class T>
0043 inline void del(proxy<T> const& x)
0044 {
0045     x.del();
0046 }
0047 
0048 //
0049 // implementation
0050 //
0051 
0052 template <class Policies>
0053 inline proxy<Policies>::proxy(object const& target, key_type const& key)
0054     : m_target(target), m_key(key)
0055 {}
0056 
0057 template <class Policies>
0058 inline proxy<Policies>::operator object() const
0059 {
0060     return Policies::get(m_target, m_key);
0061 }
0062 
0063 // to support a[b] = c[d]
0064 template <class Policies>
0065 inline proxy<Policies> const& proxy<Policies>::operator=(typename proxy::assignment_self rhs) const
0066 {
0067     return *this = python::object(rhs);
0068 }
0069 
0070 # define BOOST_PYTHON_PROXY_INPLACE(op)                                         \
0071 template <class Policies, class R>                                              \
0072 proxy<Policies> const& operator op(proxy<Policies> const& lhs, R const& rhs)    \
0073 {                                                                               \
0074     object old(lhs);                                                            \
0075     return lhs = (old op rhs);                                                  \
0076 } 
0077 BOOST_PYTHON_PROXY_INPLACE(+=)
0078 BOOST_PYTHON_PROXY_INPLACE(-=)
0079 BOOST_PYTHON_PROXY_INPLACE(*=)
0080 BOOST_PYTHON_PROXY_INPLACE(/=)
0081 BOOST_PYTHON_PROXY_INPLACE(%=)
0082 BOOST_PYTHON_PROXY_INPLACE(<<=)
0083 BOOST_PYTHON_PROXY_INPLACE(>>=)
0084 BOOST_PYTHON_PROXY_INPLACE(&=)
0085 BOOST_PYTHON_PROXY_INPLACE(^=)
0086 BOOST_PYTHON_PROXY_INPLACE(|=)
0087 # undef BOOST_PYTHON_PROXY_INPLACE
0088 
0089 template <class Policies>
0090 inline void proxy<Policies>::del() const
0091 {
0092     Policies::del(m_target, m_key);
0093 }
0094 
0095 }}} // namespace boost::python::api
0096 
0097 #endif // PROXY_DWA2002615_HPP