fix doc example typo
[boost.git] / boost / python / scope.hpp
blobae9a40a3833eb32a6dcaa8ee0b923cd574b1aff8
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
8 # include <boost/python/detail/prefix.hpp>
9 # include <boost/python/object.hpp>
10 # include <boost/python/refcount.hpp>
11 # include <boost/utility.hpp>
13 namespace boost { namespace python {
15 namespace detail
17 // Making this a namespace-scope variable to avoid Cygwin issues.
18 // Use a PyObject* to avoid problems with static destruction after Py_Finalize
19 extern BOOST_PYTHON_DECL PyObject* current_scope;
22 class scope
23 : public object
25 public:
26 inline scope(scope const&);
27 inline scope(object const&);
28 inline scope();
29 inline ~scope();
31 private: // data members
32 PyObject* m_previous_scope;
34 private: // unimplemented functions
35 void operator=(scope const&);
38 inline scope::scope(object const& new_scope)
39 : object(new_scope)
40 , m_previous_scope(detail::current_scope)
42 detail::current_scope = python::incref(new_scope.ptr());
45 inline scope::scope()
46 : object(detail::borrowed_reference(
47 detail::current_scope ? detail::current_scope : Py_None
49 , m_previous_scope(python::xincref(detail::current_scope))
53 inline scope::~scope()
55 python::xdecref(detail::current_scope);
56 detail::current_scope = m_previous_scope;
59 namespace converter
61 template <>
62 struct object_manager_traits<scope>
63 : object_manager_traits<object>
68 // Placing this after the specialization above suppresses a CWPro8.3 bug
69 inline scope::scope(scope const& new_scope)
70 : object(new_scope)
71 , m_previous_scope(detail::current_scope)
73 detail::current_scope = python::incref(new_scope.ptr());
76 }} // namespace boost::python
78 #endif // SCOPE_DWA2002724_HPP