]> git.proxmox.com Git - ceph.git/blob - ceph/src/boost/boost/python/object/value_holder.hpp
update sources to v12.2.3
[ceph.git] / ceph / src / boost / boost / python / object / value_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 VALUE_HOLDER_DWA20011215_HPP
9 # define VALUE_HOLDER_DWA20011215_HPP
10
11 # include <boost/python/object/value_holder_fwd.hpp>
12
13 # include <boost/python/instance_holder.hpp>
14 # include <boost/python/type_id.hpp>
15 # include <boost/python/wrapper.hpp>
16
17 # include <boost/python/object/inheritance_query.hpp>
18 # include <boost/python/object/forward.hpp>
19
20 # include <boost/python/detail/force_instantiate.hpp>
21 # include <boost/python/detail/preprocessor.hpp>
22
23 # include <boost/preprocessor/comma_if.hpp>
24 # include <boost/preprocessor/enum_params.hpp>
25 # include <boost/preprocessor/iterate.hpp>
26 # include <boost/preprocessor/repeat.hpp>
27 # include <boost/preprocessor/debug/line.hpp>
28
29 # include <boost/preprocessor/repetition/enum_params.hpp>
30 # include <boost/preprocessor/repetition/enum_binary_params.hpp>
31
32 # include <boost/utility/addressof.hpp>
33
34 namespace boost { namespace python { namespace objects {
35
36 #define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) objects::do_unforward(a##n,0)
37
38 template <class Value>
39 struct value_holder : instance_holder
40 {
41 typedef Value held_type;
42 typedef Value value_type;
43
44 // Forward construction to the held object
45 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 1))
46 # include BOOST_PP_ITERATE()
47
48 private: // required holder implementation
49 void* holds(type_info, bool null_ptr_only);
50
51 template <class T>
52 inline void* holds_wrapped(type_info dst_t, wrapper<T>*,T* p)
53 {
54 return python::type_id<T>() == dst_t ? p : 0;
55 }
56
57 inline void* holds_wrapped(type_info, ...)
58 {
59 return 0;
60 }
61 private: // data members
62 Value m_held;
63 };
64
65 template <class Value, class Held>
66 struct value_holder_back_reference : instance_holder
67 {
68 typedef Held held_type;
69 typedef Value value_type;
70
71 // Forward construction to the held object
72 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 2))
73 # include BOOST_PP_ITERATE()
74
75 private: // required holder implementation
76 void* holds(type_info, bool null_ptr_only);
77
78 private: // data members
79 Held m_held;
80 };
81
82 # undef BOOST_PYTHON_UNFORWARD_LOCAL
83
84 template <class Value>
85 void* value_holder<Value>::holds(type_info dst_t, bool /*null_ptr_only*/)
86 {
87 if (void* wrapped = holds_wrapped(dst_t, boost::addressof(m_held), boost::addressof(m_held)))
88 return wrapped;
89
90 type_info src_t = python::type_id<Value>();
91 return src_t == dst_t ? boost::addressof(m_held)
92 : find_static_type(boost::addressof(m_held), src_t, dst_t);
93 }
94
95 template <class Value, class Held>
96 void* value_holder_back_reference<Value,Held>::holds(
97 type_info dst_t, bool /*null_ptr_only*/)
98 {
99 type_info src_t = python::type_id<Value>();
100 Value* x = &m_held;
101
102 if (dst_t == src_t)
103 return x;
104 else if (dst_t == python::type_id<Held>())
105 return &m_held;
106 else
107 return find_static_type(x, src_t, dst_t);
108 }
109
110 }}} // namespace boost::python::objects
111
112 # endif // VALUE_HOLDER_DWA20011215_HPP
113
114 // --------------- value_holder ---------------
115
116 // For gcc 4.4 compatability, we must include the
117 // BOOST_PP_ITERATION_DEPTH test inside an #else clause.
118 #else // BOOST_PP_IS_ITERATING
119 #if BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1
120 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
121 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
122 # line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder))
123 # endif
124
125 # define N BOOST_PP_ITERATION()
126
127 # if (N != 0)
128 template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
129 # endif
130 value_holder(
131 PyObject* self BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
132 : m_held(
133 BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
134 )
135 {
136 python::detail::initialize_wrapper(self, boost::addressof(this->m_held));
137 }
138
139 # undef N
140
141 // --------------- value_holder_back_reference ---------------
142
143 #elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2
144 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \
145 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201)))
146 # line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference))
147 # endif
148
149 # define N BOOST_PP_ITERATION()
150
151 # if (N != 0)
152 template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)>
153 # endif
154 value_holder_back_reference(
155 PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a))
156 : m_held(
157 p BOOST_PP_COMMA_IF(N)
158 BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil)
159 )
160 {
161 }
162
163 # undef N
164
165 #endif // BOOST_PP_ITERATION_DEPTH()
166 #endif