Mercurial > hg > vamp-build-and-test
comparison DEPENDENCIES/generic/include/boost/python/object/value_holder.hpp @ 16:2665513ce2d3
Add boost headers
author | Chris Cannam |
---|---|
date | Tue, 05 Aug 2014 11:11:38 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
15:663ca0da4350 | 16:2665513ce2d3 |
---|---|
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 # if BOOST_WORKAROUND(__GNUC__, == 2) | |
37 # define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) (typename unforward<A##n>::type)objects::do_unforward(a##n,0) | |
38 # else | |
39 # define BOOST_PYTHON_UNFORWARD_LOCAL(z, n, _) BOOST_PP_COMMA_IF(n) objects::do_unforward(a##n,0) | |
40 # endif | |
41 | |
42 template <class Value> | |
43 struct value_holder : instance_holder | |
44 { | |
45 typedef Value held_type; | |
46 typedef Value value_type; | |
47 | |
48 // Forward construction to the held object | |
49 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 1)) | |
50 # include BOOST_PP_ITERATE() | |
51 | |
52 private: // required holder implementation | |
53 void* holds(type_info, bool null_ptr_only); | |
54 | |
55 template <class T> | |
56 inline void* holds_wrapped(type_info dst_t, wrapper<T>*,T* p) | |
57 { | |
58 return python::type_id<T>() == dst_t ? p : 0; | |
59 } | |
60 | |
61 inline void* holds_wrapped(type_info, ...) | |
62 { | |
63 return 0; | |
64 } | |
65 private: // data members | |
66 Value m_held; | |
67 }; | |
68 | |
69 template <class Value, class Held> | |
70 struct value_holder_back_reference : instance_holder | |
71 { | |
72 typedef Held held_type; | |
73 typedef Value value_type; | |
74 | |
75 // Forward construction to the held object | |
76 # define BOOST_PP_ITERATION_PARAMS_1 (4, (0, BOOST_PYTHON_MAX_ARITY, <boost/python/object/value_holder.hpp>, 2)) | |
77 # include BOOST_PP_ITERATE() | |
78 | |
79 private: // required holder implementation | |
80 void* holds(type_info, bool null_ptr_only); | |
81 | |
82 private: // data members | |
83 Held m_held; | |
84 }; | |
85 | |
86 # undef BOOST_PYTHON_UNFORWARD_LOCAL | |
87 | |
88 template <class Value> | |
89 void* value_holder<Value>::holds(type_info dst_t, bool /*null_ptr_only*/) | |
90 { | |
91 if (void* wrapped = holds_wrapped(dst_t, boost::addressof(m_held), boost::addressof(m_held))) | |
92 return wrapped; | |
93 | |
94 type_info src_t = python::type_id<Value>(); | |
95 return src_t == dst_t ? boost::addressof(m_held) | |
96 : find_static_type(boost::addressof(m_held), src_t, dst_t); | |
97 } | |
98 | |
99 template <class Value, class Held> | |
100 void* value_holder_back_reference<Value,Held>::holds( | |
101 type_info dst_t, bool /*null_ptr_only*/) | |
102 { | |
103 type_info src_t = python::type_id<Value>(); | |
104 Value* x = &m_held; | |
105 | |
106 if (dst_t == src_t) | |
107 return x; | |
108 else if (dst_t == python::type_id<Held>()) | |
109 return &m_held; | |
110 else | |
111 return find_static_type(x, src_t, dst_t); | |
112 } | |
113 | |
114 }}} // namespace boost::python::objects | |
115 | |
116 # endif // VALUE_HOLDER_DWA20011215_HPP | |
117 | |
118 // --------------- value_holder --------------- | |
119 | |
120 // For gcc 4.4 compatability, we must include the | |
121 // BOOST_PP_ITERATION_DEPTH test inside an #else clause. | |
122 #else // BOOST_PP_IS_ITERATING | |
123 #if BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 1 | |
124 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \ | |
125 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201))) | |
126 # line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder)) | |
127 # endif | |
128 | |
129 # define N BOOST_PP_ITERATION() | |
130 | |
131 # if (N != 0) | |
132 template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)> | |
133 # endif | |
134 value_holder( | |
135 PyObject* self BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a)) | |
136 : m_held( | |
137 BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) | |
138 ) | |
139 { | |
140 python::detail::initialize_wrapper(self, boost::addressof(this->m_held)); | |
141 } | |
142 | |
143 # undef N | |
144 | |
145 // --------------- value_holder_back_reference --------------- | |
146 | |
147 #elif BOOST_PP_ITERATION_DEPTH() == 1 && BOOST_PP_ITERATION_FLAGS() == 2 | |
148 # if !(BOOST_WORKAROUND(__MWERKS__, > 0x3100) \ | |
149 && BOOST_WORKAROUND(__MWERKS__, BOOST_TESTED_AT(0x3201))) | |
150 # line BOOST_PP_LINE(__LINE__, value_holder.hpp(value_holder_back_reference)) | |
151 # endif | |
152 | |
153 # define N BOOST_PP_ITERATION() | |
154 | |
155 # if (N != 0) | |
156 template <BOOST_PP_ENUM_PARAMS_Z(1, N, class A)> | |
157 # endif | |
158 value_holder_back_reference( | |
159 PyObject* p BOOST_PP_COMMA_IF(N) BOOST_PP_ENUM_BINARY_PARAMS_Z(1, N, A, a)) | |
160 : m_held( | |
161 p BOOST_PP_COMMA_IF(N) | |
162 BOOST_PP_REPEAT_1ST(N, BOOST_PYTHON_UNFORWARD_LOCAL, nil) | |
163 ) | |
164 { | |
165 } | |
166 | |
167 # undef N | |
168 | |
169 #endif // BOOST_PP_ITERATION_DEPTH() | |
170 #endif |