Chris@16
|
1 // Copyright David Abrahams 2004. Distributed under the Boost
|
Chris@16
|
2 // Software License, Version 1.0. (See accompanying
|
Chris@16
|
3 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
|
Chris@16
|
4 #ifndef WRAPPER_BASE_DWA2004722_HPP
|
Chris@16
|
5 # define WRAPPER_BASE_DWA2004722_HPP
|
Chris@16
|
6
|
Chris@16
|
7 # include <boost/python/detail/prefix.hpp>
|
Chris@16
|
8 # include <boost/type_traits/is_polymorphic.hpp>
|
Chris@16
|
9 # include <boost/mpl/bool.hpp>
|
Chris@16
|
10
|
Chris@16
|
11 namespace boost { namespace python {
|
Chris@16
|
12
|
Chris@16
|
13 class override;
|
Chris@16
|
14
|
Chris@16
|
15 namespace detail
|
Chris@16
|
16 {
|
Chris@16
|
17 class BOOST_PYTHON_DECL_FORWARD wrapper_base;
|
Chris@16
|
18
|
Chris@16
|
19 namespace wrapper_base_ // ADL disabler
|
Chris@16
|
20 {
|
Chris@16
|
21 inline PyObject* get_owner(wrapper_base const volatile& w);
|
Chris@16
|
22
|
Chris@16
|
23 inline PyObject*
|
Chris@16
|
24 owner_impl(void const volatile* /*x*/, mpl::false_)
|
Chris@16
|
25 {
|
Chris@16
|
26 return 0;
|
Chris@16
|
27 }
|
Chris@16
|
28
|
Chris@16
|
29 template <class T>
|
Chris@16
|
30 inline PyObject*
|
Chris@16
|
31 owner_impl(T const volatile* x, mpl::true_);
|
Chris@16
|
32
|
Chris@16
|
33 template <class T>
|
Chris@16
|
34 inline PyObject*
|
Chris@16
|
35 owner(T const volatile* x)
|
Chris@16
|
36 {
|
Chris@16
|
37 return wrapper_base_::owner_impl(x,is_polymorphic<T>());
|
Chris@16
|
38 }
|
Chris@16
|
39 }
|
Chris@16
|
40
|
Chris@16
|
41 class BOOST_PYTHON_DECL wrapper_base
|
Chris@16
|
42 {
|
Chris@16
|
43 friend void initialize_wrapper(PyObject* self, wrapper_base* w);
|
Chris@16
|
44 friend PyObject* wrapper_base_::get_owner(wrapper_base const volatile& w);
|
Chris@16
|
45 protected:
|
Chris@16
|
46 wrapper_base() : m_self(0) {}
|
Chris@16
|
47
|
Chris@16
|
48 override get_override(
|
Chris@16
|
49 char const* name, PyTypeObject* class_object) const;
|
Chris@16
|
50
|
Chris@16
|
51 private:
|
Chris@16
|
52 void detach();
|
Chris@16
|
53
|
Chris@16
|
54 private:
|
Chris@16
|
55 PyObject* m_self;
|
Chris@16
|
56 };
|
Chris@16
|
57
|
Chris@16
|
58 namespace wrapper_base_ // ADL disabler
|
Chris@16
|
59 {
|
Chris@16
|
60 template <class T>
|
Chris@16
|
61 inline PyObject*
|
Chris@16
|
62 owner_impl(T const volatile* x, mpl::true_)
|
Chris@16
|
63 {
|
Chris@16
|
64 if (wrapper_base const volatile* w = dynamic_cast<wrapper_base const volatile*>(x))
|
Chris@16
|
65 {
|
Chris@16
|
66 return wrapper_base_::get_owner(*w);
|
Chris@16
|
67 }
|
Chris@16
|
68 return 0;
|
Chris@16
|
69 }
|
Chris@16
|
70
|
Chris@16
|
71 inline PyObject* get_owner(wrapper_base const volatile& w)
|
Chris@16
|
72 {
|
Chris@16
|
73 return w.m_self;
|
Chris@16
|
74 }
|
Chris@16
|
75 }
|
Chris@16
|
76
|
Chris@16
|
77 inline void initialize_wrapper(PyObject* self, wrapper_base* w)
|
Chris@16
|
78 {
|
Chris@16
|
79 w->m_self = self;
|
Chris@16
|
80 }
|
Chris@16
|
81
|
Chris@16
|
82 inline void initialize_wrapper(PyObject* /*self*/, ...) {}
|
Chris@16
|
83
|
Chris@16
|
84
|
Chris@16
|
85
|
Chris@16
|
86 } // namespace detail
|
Chris@16
|
87
|
Chris@16
|
88 }} // namespace boost::python
|
Chris@16
|
89
|
Chris@16
|
90 #endif // WRAPPER_BASE_DWA2004722_HPP
|