source: NonGTP/Boost/boost/python/scope.hpp @ 857

Revision 857, 1.9 KB checked in by igarcia, 18 years ago (diff)
Line 
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# include <boost/utility.hpp>
12
13namespace boost { namespace python {
14
15namespace detail
16{
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;
20}
21
22class scope
23  : public object
24{
25 public:
26    inline scope(scope const&);
27    inline scope(object const&);
28    inline scope();
29    inline ~scope();
30   
31 private: // data members
32    PyObject* m_previous_scope;
33
34 private: // unimplemented functions
35    void operator=(scope const&);
36};
37
38inline scope::scope(object const& new_scope)
39    : object(new_scope)
40    , m_previous_scope(detail::current_scope)
41{
42    detail::current_scope = python::incref(new_scope.ptr());
43}
44
45inline scope::scope()
46    : object(detail::borrowed_reference(
47                 detail::current_scope ? detail::current_scope : Py_None
48                 ))
49    , m_previous_scope(python::xincref(detail::current_scope))
50{
51}
52
53inline scope::~scope()
54{
55    python::xdecref(detail::current_scope);
56    detail::current_scope = m_previous_scope;
57}
58
59namespace converter
60{
61  template <>
62  struct object_manager_traits<scope>
63      : object_manager_traits<object>
64  {
65  };
66}
67
68// Placing this after the specialization above suppresses a CWPro8.3 bug
69inline scope::scope(scope const& new_scope)
70    : object(new_scope)
71    , m_previous_scope(detail::current_scope)
72{
73    detail::current_scope = python::incref(new_scope.ptr());
74}
75
76}} // namespace boost::python
77
78#endif // SCOPE_DWA2002724_HPP
Note: See TracBrowser for help on using the repository browser.