the game where you go into mines and start crafting! but for consoles (forked directly from smartcmd's github)
at main 77 lines 1.9 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 SCOPE_DWA2002724_HPP 6# define SCOPE_DWA2002724_HPP 7 8# include <boost/python/detail/prefix.hpp> 9# include <boost/python/object.hpp> 10# include <boost/python/refcount.hpp> 11 12namespace boost { namespace python { 13 14namespace detail 15{ 16 // Making this a namespace-scope variable to avoid Cygwin issues. 17 // Use a PyObject* to avoid problems with static destruction after Py_Finalize 18 extern BOOST_PYTHON_DECL PyObject* current_scope; 19} 20 21class scope 22 : public object 23{ 24 public: 25 inline scope(scope const&); 26 inline scope(object const&); 27 inline scope(); 28 inline ~scope(); 29 30 private: // data members 31 PyObject* m_previous_scope; 32 33 private: // unimplemented functions 34 void operator=(scope const&); 35}; 36 37inline scope::scope(object const& new_scope) 38 : object(new_scope) 39 , m_previous_scope(detail::current_scope) 40{ 41 detail::current_scope = python::incref(new_scope.ptr()); 42} 43 44inline scope::scope() 45 : object(detail::borrowed_reference( 46 detail::current_scope ? detail::current_scope : Py_None 47 )) 48 , m_previous_scope(python::xincref(detail::current_scope)) 49{ 50} 51 52inline scope::~scope() 53{ 54 python::xdecref(detail::current_scope); 55 detail::current_scope = m_previous_scope; 56} 57 58namespace converter 59{ 60 template <> 61 struct object_manager_traits<scope> 62 : object_manager_traits<object> 63 { 64 }; 65} 66 67// Placing this after the specialization above suppresses a CWPro8.3 bug 68inline scope::scope(scope const& new_scope) 69 : object(new_scope) 70 , m_previous_scope(detail::current_scope) 71{ 72 detail::current_scope = python::incref(new_scope.ptr()); 73} 74 75}} // namespace boost::python 76 77#endif // SCOPE_DWA2002724_HPP