File indexing completed on 2025-01-18 09:50:42
0001
0002
0003
0004
0005 #ifndef SCOPE_DWA2002724_HPP
0006 # define SCOPE_DWA2002724_HPP
0007
0008 # include <boost/python/detail/prefix.hpp>
0009 # include <boost/python/object.hpp>
0010 # include <boost/python/refcount.hpp>
0011
0012 namespace boost { namespace python {
0013
0014 namespace detail
0015 {
0016
0017
0018 extern BOOST_PYTHON_DECL PyObject* current_scope;
0019 }
0020
0021 class scope
0022 : public object
0023 {
0024 public:
0025 inline scope(scope const&);
0026 inline scope(object const&);
0027 inline scope();
0028 inline ~scope();
0029
0030 private:
0031 PyObject* m_previous_scope;
0032
0033 private:
0034 void operator=(scope const&);
0035 };
0036
0037 inline scope::scope(object const& new_scope)
0038 : object(new_scope)
0039 , m_previous_scope(detail::current_scope)
0040 {
0041 detail::current_scope = python::incref(new_scope.ptr());
0042 }
0043
0044 inline scope::scope()
0045 : object(detail::borrowed_reference(
0046 detail::current_scope ? detail::current_scope : Py_None
0047 ))
0048 , m_previous_scope(python::xincref(detail::current_scope))
0049 {
0050 }
0051
0052 inline scope::~scope()
0053 {
0054 python::xdecref(detail::current_scope);
0055 detail::current_scope = m_previous_scope;
0056 }
0057
0058 namespace converter
0059 {
0060 template <>
0061 struct object_manager_traits<scope>
0062 : object_manager_traits<object>
0063 {
0064 };
0065 }
0066
0067
0068 inline scope::scope(scope const& new_scope)
0069 : object(new_scope)
0070 , m_previous_scope(detail::current_scope)
0071 {
0072 detail::current_scope = python::incref(new_scope.ptr());
0073 }
0074
0075 }}
0076
0077 #endif