]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/python/include/boost/python/object/pointer_holder.hpp
bump version to 12.2.2-pve1
[ceph.git] / ceph / src / boost / libs / python / include / boost / python / object / pointer_holder.hpp
1 #if !defined(BOOST_PP_IS_ITERATING)
2
3 // Copyright David Abrahams 2001.
4 // Distributed under the Boost Software License, Version 1.0. (See
5 // accompanying file LICENSE_1_0.txt or copy at
6 // http://www.boost.org/LICENSE_1_0.txt)
7
8 # ifndef POINTER_HOLDER_DWA20011215_HPP
9 # define POINTER_HOLDER_DWA20011215_HPP
10
11 # include <boost/get_pointer.hpp>
12 # include <boost/type.hpp>
13
14 # include <boost/python/instance_holder.hpp>
15 # include <boost/python/object/inheritance_query.hpp>
16 # include <boost/python/object/forward.hpp>
17
18 # include <boost/python/pointee.hpp>
19 # include <boost/python/type_id.hpp>
20
21 # include <boost/python/detail/wrapper_base.hpp>
22 # include <boost/python/detail/force_instantiate.hpp>
23 # include <boost/python/detail/preprocessor.hpp>
24
25
26 # include <boost/mpl/if.hpp>
27 # include <boost/mpl/apply.hpp>
28
29 # include <boost/preprocessor/comma_if.hpp>
30 # include <boost/preprocessor/iterate.hpp>
31 # include <boost/preprocessor/repeat.hpp>
32 # include <boost/preprocessor/debug/line.hpp>
33 # include <boost/preprocessor/enum_params.hpp>
34 # include <boost/preprocessor/repetition/enum_binary_params.hpp>
35
36 # include <boost/detail/workaround.hpp>
37
38 # include <boost/type_traits/remove_const.hpp>
39
40 namespace boost { namespace python {
41
42 template <class T> class wrapper;
43
44 }}
45
46
47 namespace boost { namespace python { namespace objects {
48
49 #define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) objects::do_unforward(a##n,0)
50
51 template <class Pointer, class Value>
52 struct pointer_holder : instance_holder
53 {
54 typedef Value value_type;
55
56 pointer_holder(Pointer);
57
58 // Forward construction to the held object
59
60 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 1))
61 # include BOOST_PP_ITERATE()
62
63 private: // types
64
65 private: // required holder implementation
66 void* holds(type_info, bool null_ptr_only);
67
68 template <class T>
69 inline void* holds_wrapped(type_info dst_t, wrapper<T>*,T* p)
70 {
71 return python::type_id<T>() == dst_t ? p : 0;
72 }
73
74 inline void* holds_wrapped(type_info, ...)
75 {
76 return 0;
77 }
78
79 private: // data members
80 Pointer m_p;
81 };
82
83 template <class Pointer, class Value>
84 struct pointer_holder_back_reference : instance_holder
85 {
86 private:
87 typedef typename python::pointee<Pointer>::type held_type;
88 public:
89 typedef Value value_type;
90
91 // Not sure about this one -- can it work? The source object
92 // undoubtedly does not carry the correct back reference pointer.
93 pointer_holder_back_reference(Pointer);
94
95 // Forward construction to the held object
96 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/pointer_holder.hpp>, 2))
97 # include BOOST_PP_ITERATE()
98
99 private: // required holder implementation
100 void* holds(type_info, bool null_ptr_only);
101
102 private: // data members
103 Pointer m_p;
104 };
105
106 # undef BOOST_PYTHON_UNFORWARD_LOCAL
107
108 template <class Pointer, class Value>
109 inline pointer_holder<Pointer,Value>::pointer_holder(Pointer p)
110 #if __cplusplus < 201103L
111 : m_p(p)
112 #else
113 : m_p(std::move(p))
114 #endif
115 {
116 }
117
118 template <class Pointer, class Value>
119 inline pointer_holder_back_reference<Pointer,Value>::pointer_holder_back_reference(Pointer p)
120 #if __cplusplus < 201103L
121 : m_p(p)
122 #else
123 : m_p(std::move(p))
124 #endif
125 {
126 }
127
128 template <class Pointer, class Value>
129 void* pointer_holder<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
130 {
131 typedef typename boost::remove_const< Value >::type non_const_value;
132
133 if (dst_t == python::type_id<Pointer>()
134 && !(null_ptr_only && get_pointer(this->m_p))
135 )
136 return &this->m_p;
137
138 Value* p0
139 # if BOOST_WORKAROUND(__SUNPRO_CC, BOOST_TESTED_AT(0x590))
140 = static_cast<Value*>( get_pointer(this->m_p) )
141 # else
142 = get_pointer(this->m_p)
143 # endif
144 ;
145 non_const_value* p = const_cast<non_const_value*>( p0 );
146
147 if (p == 0)
148 return 0;
149
150 if (void* wrapped = holds_wrapped(dst_t, p, p))
151 return wrapped;
152
153 type_info src_t = python::type_id<non_const_value>();
154 return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
155 }
156
157 template <class Pointer, class Value>
158 void* pointer_holder_back_reference<Pointer, Value>::holds(type_info dst_t, bool null_ptr_only)
159 {
160 if (dst_t == python::type_id<Pointer>()
161 && !(null_ptr_only && get_pointer(this->m_p))
162 )
163 return &this->m_p;
164
165 if (!get_pointer(this->m_p))
166 return 0;
167
168 Value* p = get_pointer(m_p);
169
170 if (dst_t == python::type_id<held_type>())
171 return p;
172
173 type_info src_t = python::type_id<Value>();
174 return src_t == dst_t ? p : find_dynamic_type(p, src_t, dst_t);
175 }
176
177 }}} // namespace boost::python::objects
178
179 # endif // POINTER_HOLDER_DWA20011215_HPP
180
181 /* --------------- pointer_holder --------------- */
182 // For gcc 4.4 compatability, we must include the
183 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
184 #else // BOOST_PP_IS_ITERATING
185 #if BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
186 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
187 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
188 # line BOOST_PP_LINE(__LINE__, pointer_holder.hpp)
189 # endif
190
191 # define N BOOST_PP_ITERATION()
192
193 # if (N != 0)
194 template< BOOST_PP_ENUM_PARAMS_Z(1, N, class A) >
195 # endif
196 pointer_holder(PyObject* self BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
197 : m_p(new Value(
198 BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
199 ))
200 {
201 python::detail::initialize_wrapper(self, get_pointer(this->m_p));
202 }
203
204 # undef N
205
206 /* --------------- pointer_holder_back_reference --------------- */
207 #elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
208 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
209 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
210 # line BOOST_PP_LINE(__LINE__, pointer_holder.hpp(pointer_holder_back_reference))
211 # endif
212
213 # define N BOOST_PP_ITERATION()
214
215 # if (N != 0)
216 template < BOOST_PP_ENUM_PARAMS_Z(1, N, class A) >
217 # endif
218 pointer_holder_back_reference(
219 PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
220 : m_p(new held_type(
221 p BOOST_PP_COMMA_IF(N) BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
222 ))
223 {}
224
225 # undef N
226
227 #endif // BOOST_PP_ITERATION_DEPTH()
228 #endif