Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:50:42

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 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   // Making this a namespace-scope variable to avoid Cygwin issues.
0017   // Use a PyObject* to avoid problems with static destruction after Py_Finalize
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: // data members
0031     PyObject* m_previous_scope;
0032 
0033  private: // unimplemented functions
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 // Placing this after the specialization above suppresses a CWPro8.3 bug
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 }} // namespace boost::python
0076 
0077 #endif // SCOPE_DWA2002724_HPP