Chris@16
|
1 // Copyright David Abrahams 2002.
|
Chris@16
|
2 // Distributed under the Boost Software License, Version 1.0. (See
|
Chris@16
|
3 // accompanying file LICENSE_1_0.txt or copy at
|
Chris@16
|
4 // http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
5 #ifndef SCOPE_DWA2002724_HPP
|
Chris@16
|
6 # define SCOPE_DWA2002724_HPP
|
Chris@16
|
7
|
Chris@16
|
8 # include <boost/python/detail/prefix.hpp>
|
Chris@16
|
9 # include <boost/python/object.hpp>
|
Chris@16
|
10 # include <boost/python/refcount.hpp>
|
Chris@16
|
11
|
Chris@16
|
12 namespace boost { namespace python {
|
Chris@16
|
13
|
Chris@16
|
14 namespace detail
|
Chris@16
|
15 {
|
Chris@16
|
16 // Making this a namespace-scope variable to avoid Cygwin issues.
|
Chris@16
|
17 // Use a PyObject* to avoid problems with static destruction after Py_Finalize
|
Chris@16
|
18 extern BOOST_PYTHON_DECL PyObject* current_scope;
|
Chris@16
|
19 }
|
Chris@16
|
20
|
Chris@16
|
21 class scope
|
Chris@16
|
22 : public object
|
Chris@16
|
23 {
|
Chris@16
|
24 public:
|
Chris@16
|
25 inline scope(scope const&);
|
Chris@16
|
26 inline scope(object const&);
|
Chris@16
|
27 inline scope();
|
Chris@16
|
28 inline ~scope();
|
Chris@16
|
29
|
Chris@16
|
30 private: // data members
|
Chris@16
|
31 PyObject* m_previous_scope;
|
Chris@16
|
32
|
Chris@16
|
33 private: // unimplemented functions
|
Chris@16
|
34 void operator=(scope const&);
|
Chris@16
|
35 };
|
Chris@16
|
36
|
Chris@16
|
37 inline scope::scope(object const& new_scope)
|
Chris@16
|
38 : object(new_scope)
|
Chris@16
|
39 , m_previous_scope(detail::current_scope)
|
Chris@16
|
40 {
|
Chris@16
|
41 detail::current_scope = python::incref(new_scope.ptr());
|
Chris@16
|
42 }
|
Chris@16
|
43
|
Chris@16
|
44 inline scope::scope()
|
Chris@16
|
45 : object(detail::borrowed_reference(
|
Chris@16
|
46 detail::current_scope ? detail::current_scope : Py_None
|
Chris@16
|
47 ))
|
Chris@16
|
48 , m_previous_scope(python::xincref(detail::current_scope))
|
Chris@16
|
49 {
|
Chris@16
|
50 }
|
Chris@16
|
51
|
Chris@16
|
52 inline scope::~scope()
|
Chris@16
|
53 {
|
Chris@16
|
54 python::xdecref(detail::current_scope);
|
Chris@16
|
55 detail::current_scope = m_previous_scope;
|
Chris@16
|
56 }
|
Chris@16
|
57
|
Chris@16
|
58 namespace converter
|
Chris@16
|
59 {
|
Chris@16
|
60 template <>
|
Chris@16
|
61 struct object_manager_traits<scope>
|
Chris@16
|
62 : object_manager_traits<object>
|
Chris@16
|
63 {
|
Chris@16
|
64 };
|
Chris@16
|
65 }
|
Chris@16
|
66
|
Chris@16
|
67 // Placing this after the specialization above suppresses a CWPro8.3 bug
|
Chris@16
|
68 inline scope::scope(scope const& new_scope)
|
Chris@16
|
69 : object(new_scope)
|
Chris@16
|
70 , m_previous_scope(detail::current_scope)
|
Chris@16
|
71 {
|
Chris@16
|
72 detail::current_scope = python::incref(new_scope.ptr());
|
Chris@16
|
73 }
|
Chris@16
|
74
|
Chris@16
|
75 }} // namespace boost::python
|
Chris@16
|
76
|
Chris@16
|
77 #endif // SCOPE_DWA2002724_HPP
|