1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/ossrv/ossrv_pub/boost_apis/boost/python/scope.hpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,78 @@
1.4 +// Copyright David Abrahams 2002.
1.5 +// Distributed under the Boost Software License, Version 1.0. (See
1.6 +// accompanying file LICENSE_1_0.txt or copy at
1.7 +// http://www.boost.org/LICENSE_1_0.txt)
1.8 +#ifndef SCOPE_DWA2002724_HPP
1.9 +# define SCOPE_DWA2002724_HPP
1.10 +
1.11 +# include <boost/python/detail/prefix.hpp>
1.12 +# include <boost/python/object.hpp>
1.13 +# include <boost/python/refcount.hpp>
1.14 +# include <boost/utility.hpp>
1.15 +
1.16 +namespace boost { namespace python {
1.17 +
1.18 +namespace detail
1.19 +{
1.20 + // Making this a namespace-scope variable to avoid Cygwin issues.
1.21 + // Use a PyObject* to avoid problems with static destruction after Py_Finalize
1.22 + extern BOOST_PYTHON_DECL PyObject* current_scope;
1.23 +}
1.24 +
1.25 +class scope
1.26 + : public object
1.27 +{
1.28 + public:
1.29 + inline scope(scope const&);
1.30 + inline scope(object const&);
1.31 + inline scope();
1.32 + inline ~scope();
1.33 +
1.34 + private: // data members
1.35 + PyObject* m_previous_scope;
1.36 +
1.37 + private: // unimplemented functions
1.38 + void operator=(scope const&);
1.39 +};
1.40 +
1.41 +inline scope::scope(object const& new_scope)
1.42 + : object(new_scope)
1.43 + , m_previous_scope(detail::current_scope)
1.44 +{
1.45 + detail::current_scope = python::incref(new_scope.ptr());
1.46 +}
1.47 +
1.48 +inline scope::scope()
1.49 + : object(detail::borrowed_reference(
1.50 + detail::current_scope ? detail::current_scope : Py_None
1.51 + ))
1.52 + , m_previous_scope(python::xincref(detail::current_scope))
1.53 +{
1.54 +}
1.55 +
1.56 +inline scope::~scope()
1.57 +{
1.58 + python::xdecref(detail::current_scope);
1.59 + detail::current_scope = m_previous_scope;
1.60 +}
1.61 +
1.62 +namespace converter
1.63 +{
1.64 + template <>
1.65 + struct object_manager_traits<scope>
1.66 + : object_manager_traits<object>
1.67 + {
1.68 + };
1.69 +}
1.70 +
1.71 +// Placing this after the specialization above suppresses a CWPro8.3 bug
1.72 +inline scope::scope(scope const& new_scope)
1.73 + : object(new_scope)
1.74 + , m_previous_scope(detail::current_scope)
1.75 +{
1.76 + detail::current_scope = python::incref(new_scope.ptr());
1.77 +}
1.78 +
1.79 +}} // namespace boost::python
1.80 +
1.81 +#endif // SCOPE_DWA2002724_HPP