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