the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at master 101 lines 2.8 kB view raw
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> 10 11namespace boost { namespace python { namespace api { 12 13template <class Policies> 14class proxy : public object_operators<proxy<Policies> > 15{ 16 typedef typename Policies::key_type key_type; 17 18# if !defined(BOOST_MSVC) || BOOST_MSVC >= 1300 19 typedef proxy const& assignment_self; 20# else 21 typedef proxy assignment_self; 22# endif 23 public: 24 proxy(object const& target, key_type const& key); 25 operator object() const; 26 27 // to support a[b] = c[d] 28 proxy const& operator=(assignment_self) const; 29 30 template <class T> 31 inline proxy const& operator=(T const& rhs) const 32 { 33 Policies::set(m_target, m_key, object(rhs)); 34 return *this; 35 } 36 37 public: // implementation detail 38 void del() const; 39 40 private: 41 object m_target; 42 key_type m_key; 43}; 44 45 46template <class T> 47inline void del(proxy<T> const& x) 48{ 49 x.del(); 50} 51 52// 53// implementation 54// 55 56template <class Policies> 57inline proxy<Policies>::proxy(object const& target, key_type const& key) 58 : m_target(target), m_key(key) 59{} 60 61template <class Policies> 62inline proxy<Policies>::operator object() const 63{ 64 return Policies::get(m_target, m_key); 65} 66 67// to support a[b] = c[d] 68template <class Policies> 69inline proxy<Policies> const& proxy<Policies>::operator=(typename proxy::assignment_self rhs) const 70{ 71 return *this = python::object(rhs); 72} 73 74# define BOOST_PYTHON_PROXY_INPLACE(op) \ 75template <class Policies, class R> \ 76proxy<Policies> const& operator op(proxy<Policies> const& lhs, R const& rhs) \ 77{ \ 78 object old(lhs); \ 79 return lhs = (old op rhs); \ 80} 81BOOST_PYTHON_PROXY_INPLACE(+=) 82BOOST_PYTHON_PROXY_INPLACE(-=) 83BOOST_PYTHON_PROXY_INPLACE(*=) 84BOOST_PYTHON_PROXY_INPLACE(/=) 85BOOST_PYTHON_PROXY_INPLACE(%=) 86BOOST_PYTHON_PROXY_INPLACE(<<=) 87BOOST_PYTHON_PROXY_INPLACE(>>=) 88BOOST_PYTHON_PROXY_INPLACE(&=) 89BOOST_PYTHON_PROXY_INPLACE(^=) 90BOOST_PYTHON_PROXY_INPLACE(|=) 91# undef BOOST_PYTHON_PROXY_INPLACE 92 93template <class Policies> 94inline void proxy<Policies>::del() const 95{ 96 Policies::del(m_target, m_key); 97} 98 99}}} // namespace boost::python::api 100 101#endif // PROXY_DWA2002615_HPP