1 | // ============================================================== // |
---|
2 | // // |
---|
3 | // File : cbtypes.h // |
---|
4 | // Purpose : generic cb types // |
---|
5 | // // |
---|
6 | // Coded by Ralf Westram (coder@reallysoft.de) in August 2011 // |
---|
7 | // Institute of Microbiology (Technical University Munich) // |
---|
8 | // http://www.arb-home.de/ // |
---|
9 | // // |
---|
10 | // ============================================================== // |
---|
11 | |
---|
12 | #ifndef CBTYPES_H |
---|
13 | #define CBTYPES_H |
---|
14 | |
---|
15 | #ifndef CB_BASE_H |
---|
16 | #include "cb_base.h" |
---|
17 | #endif |
---|
18 | #ifndef TTYPES_H |
---|
19 | #include <ttypes.h> |
---|
20 | #endif |
---|
21 | #ifndef STATIC_ASSERT_H |
---|
22 | #include <static_assert.h> |
---|
23 | #endif |
---|
24 | #ifndef SMARTPTR_H |
---|
25 | #include <smartptr.h> |
---|
26 | #endif |
---|
27 | |
---|
28 | |
---|
29 | // --------------------------------- |
---|
30 | // function type inspection |
---|
31 | |
---|
32 | template<typename RT, typename P1, typename P2, typename P3> |
---|
33 | struct Function { |
---|
34 | enum { NumParams = 3 }; |
---|
35 | typedef RT (*Type)(P1,P2,P3); |
---|
36 | typedef RT ResultType; |
---|
37 | }; |
---|
38 | template<typename RT, typename P1, typename P2> |
---|
39 | struct Function<RT, P1, P2, void> { |
---|
40 | enum { NumParams = 2 }; |
---|
41 | typedef RT (*Type)(P1,P2); |
---|
42 | }; |
---|
43 | template<typename RT, typename P1> |
---|
44 | struct Function<RT, P1, void, void> { |
---|
45 | enum { NumParams = 1 }; |
---|
46 | typedef RT (*Type)(P1); |
---|
47 | }; |
---|
48 | template<typename RT> |
---|
49 | struct Function<RT, void, void, void> { |
---|
50 | enum { NumParams = 0 }; |
---|
51 | typedef RT (*Type)(); |
---|
52 | }; |
---|
53 | |
---|
54 | // --------------------------- |
---|
55 | // forward parameters |
---|
56 | |
---|
57 | template<typename T> |
---|
58 | struct ForwardParamT { |
---|
59 | typedef typename IfThenElseType< TypeT<T>::IsClassT, |
---|
60 | typename TypeOp<T>::RefConstT, |
---|
61 | typename TypeOp<T>::ArgT >::ResultType Type; |
---|
62 | }; |
---|
63 | |
---|
64 | template<typename T> |
---|
65 | struct ForwardParamT<T*> { |
---|
66 | typedef typename TypeOp<T>::ArgT *Type; |
---|
67 | }; |
---|
68 | template<> class ForwardParamT<void> { class Unused {}; public: typedef Unused Type; }; |
---|
69 | |
---|
70 | // ------------------------------ |
---|
71 | // const parameter types |
---|
72 | |
---|
73 | template<typename T> |
---|
74 | struct ConstParamT { |
---|
75 | typedef typename IfThenElseType< TypeT<T>::IsClassT, |
---|
76 | typename TypeOp<T>::RefConstT, |
---|
77 | typename TypeOp<T>::ConstT >::ResultType Type; |
---|
78 | }; |
---|
79 | template<typename T> |
---|
80 | struct ConstParamT<T*> { |
---|
81 | typedef typename TypeOp<T>::ConstT *Type; |
---|
82 | }; |
---|
83 | template<> class ConstParamT<void> { class Unused {}; public: typedef Unused Type; }; |
---|
84 | |
---|
85 | // ------------------------------------ |
---|
86 | // forbid some parameter types |
---|
87 | |
---|
88 | template<typename T> class AW_CL_castableType { public: static AW_CL cast_to_AW_CL(const T& t) { return (AW_CL)t; } }; |
---|
89 | |
---|
90 | #define INVALID_CB_PARAM_TYPE(TYPE) template<> class AW_CL_castableType<TYPE> { } |
---|
91 | |
---|
92 | INVALID_CB_PARAM_TYPE(void); |
---|
93 | INVALID_CB_PARAM_TYPE(double); |
---|
94 | INVALID_CB_PARAM_TYPE(float); |
---|
95 | |
---|
96 | #undef INVALID_CB_PARAM_TYPE |
---|
97 | |
---|
98 | // ----------------------- |
---|
99 | // typed callback |
---|
100 | |
---|
101 | template<typename RT, typename P1 = void, typename P2 = void, typename P3 = void> |
---|
102 | struct StrictlyTypedCallback { |
---|
103 | typedef typename Function<RT,P1,P2,P3>::Type FuncType; |
---|
104 | |
---|
105 | private: |
---|
106 | typedef typename ForwardParamT<P1>::Type FP1; |
---|
107 | typedef typename ForwardParamT<P2>::Type FP2; |
---|
108 | typedef typename ForwardParamT<P3>::Type FP3; |
---|
109 | |
---|
110 | FuncType cb; |
---|
111 | |
---|
112 | public: |
---|
113 | enum { NumParams = Function<RT,P1,P2,P3>::NumParams }; |
---|
114 | |
---|
115 | StrictlyTypedCallback(FuncType CB) : cb(CB) {} |
---|
116 | |
---|
117 | RT operator()(FP1 p1, FP2 p2, FP3 p3) const { return cb(p1, p2, p3); } |
---|
118 | RT operator()(FP1 p1, FP2 p2) const { return cb(p1, p2); } |
---|
119 | RT operator()(FP1 p1) const { return cb(p1); } |
---|
120 | RT operator()() const { return cb(); } |
---|
121 | |
---|
122 | bool equals(const StrictlyTypedCallback& other) const { return cb == other.cb; } |
---|
123 | |
---|
124 | AW_CL get_cb() const { return (AW_CL)cb; } |
---|
125 | static StrictlyTypedCallback make_cb(AW_CL cb_) { return StrictlyTypedCallback((FuncType)cb_); } |
---|
126 | |
---|
127 | bool is_set() const { return cb != 0; } |
---|
128 | |
---|
129 | bool operator < (const StrictlyTypedCallback& other) const { return cb < other.cb; } |
---|
130 | bool operator == (const StrictlyTypedCallback& other) const { return cb == other.cb; } |
---|
131 | }; |
---|
132 | |
---|
133 | // --------------------- |
---|
134 | // CallbackData |
---|
135 | |
---|
136 | template<typename P1, typename P2> |
---|
137 | struct CallbackData { |
---|
138 | P1 p1; |
---|
139 | P2 p2; |
---|
140 | |
---|
141 | typedef void (*CallbackDataDeallocator)(P1 p1, P2 p2); |
---|
142 | CallbackDataDeallocator dealloc; |
---|
143 | |
---|
144 | CallbackData(P1 p1_, P2 p2_) : p1(p1_), p2(p2_), dealloc(NULp) {} |
---|
145 | CallbackData(P1 p1_, P2 p2_, CallbackDataDeallocator dealloc_) : p1(p1_), p2(p2_), dealloc(dealloc_) {} |
---|
146 | ~CallbackData() { if (dealloc) dealloc(p1, p2); } |
---|
147 | bool operator < (const CallbackData& other) const { |
---|
148 | return p1<other.p1 || (p1 == other.p1 && (p2< other.p2 || (p2 == other.p2 && dealloc<other.dealloc))); |
---|
149 | } |
---|
150 | bool operator == (const CallbackData& other) const { |
---|
151 | return p1 == other.p1 && p2 == other.p2 && dealloc == other.dealloc; |
---|
152 | } |
---|
153 | }; |
---|
154 | |
---|
155 | typedef CallbackData<AW_CL,AW_CL> UntypedCallbackData; |
---|
156 | |
---|
157 | // ------------------------------ |
---|
158 | // casted callback types |
---|
159 | |
---|
160 | template<typename RT> |
---|
161 | struct Callback_VV { // VV stands for arguments (VARIABLE, VARIABLE) |
---|
162 | typedef StrictlyTypedCallback<RT,AW_CL,AW_CL,AW_CL> Signature; |
---|
163 | |
---|
164 | private: |
---|
165 | Signature cb; |
---|
166 | SmartPtr<UntypedCallbackData> cd; |
---|
167 | |
---|
168 | public: |
---|
169 | Callback_VV(Signature CB, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2)) {} |
---|
170 | Callback_VV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2, dealloc)) {} |
---|
171 | |
---|
172 | RT operator()() const { return cb(cd->p1, cd->p2, 0); } |
---|
173 | |
---|
174 | bool operator < (const Callback_VV& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); } |
---|
175 | bool operator == (const Callback_VV& other) const { return cb == other.cb && *cd == *other.cd; } |
---|
176 | |
---|
177 | bool same_function_as(const Callback_VV& other) const { return cb == other.cb; } |
---|
178 | |
---|
179 | AW_CL callee() const { return cb.get_cb(); } // @@@ only intermediate - remove later |
---|
180 | AW_CL inspect_CD1() const { return cd->p1; } // @@@ only intermediate - remove later |
---|
181 | AW_CL inspect_CD2() const { return cd->p2; } // @@@ only intermediate - remove later |
---|
182 | }; |
---|
183 | |
---|
184 | template<typename RT, typename FIXED> |
---|
185 | struct Callback_FVV { // FVV stands for arguments (FIXED, VARIABLE, VARIABLE) |
---|
186 | typedef StrictlyTypedCallback<RT,FIXED,AW_CL,AW_CL> Signature; |
---|
187 | |
---|
188 | private: |
---|
189 | Signature cb; |
---|
190 | SmartPtr<UntypedCallbackData> cd; |
---|
191 | |
---|
192 | public: |
---|
193 | Callback_FVV(Signature CB, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2)) {} |
---|
194 | Callback_FVV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2, dealloc)) {} |
---|
195 | |
---|
196 | RT operator()(FIXED fixed) const { return cb(fixed, cd->p1, cd->p2); } |
---|
197 | |
---|
198 | bool operator < (const Callback_FVV& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); } |
---|
199 | bool operator == (const Callback_FVV& other) const { return cb == other.cb && *cd == *other.cd; } |
---|
200 | |
---|
201 | bool same_function_as(const Callback_FVV& other) const { return cb == other.cb; } |
---|
202 | |
---|
203 | AW_CL callee() const { return cb.get_cb(); } // @@@ only intermediate - remove later |
---|
204 | AW_CL inspect_CD1() const { return cd->p1; } // @@@ only intermediate - remove later |
---|
205 | AW_CL inspect_CD2() const { return cd->p2; } // @@@ only intermediate - remove later |
---|
206 | }; |
---|
207 | |
---|
208 | template<typename RT, typename F1, typename F2> |
---|
209 | struct Callback_FFV { // FFV stands for arguments (FIXED, FIXED, VARIABLE) |
---|
210 | typedef StrictlyTypedCallback<RT,F1,F2,AW_CL> Signature; |
---|
211 | |
---|
212 | private: |
---|
213 | typedef CallbackData<AW_CL, AW_CL> FFV_CallbackData; // 2nd AW_CL is unused |
---|
214 | |
---|
215 | Signature cb; |
---|
216 | SmartPtr<FFV_CallbackData> cd; |
---|
217 | |
---|
218 | public: |
---|
219 | Callback_FFV(Signature CB, AW_CL P) |
---|
220 | : cb(CB), |
---|
221 | cd(new FFV_CallbackData(P, 0)) |
---|
222 | {} |
---|
223 | |
---|
224 | RT operator()(F1 f1, F2 f2) const { return cb(f1, f2, cd->p1); } |
---|
225 | |
---|
226 | bool operator < (const Callback_FFV& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); } |
---|
227 | bool operator == (const Callback_FFV& other) const { return cb == other.cb && *cd == *other.cd; } |
---|
228 | |
---|
229 | bool same_function_as(const Callback_FFV& other) const { return cb == other.cb; } |
---|
230 | }; |
---|
231 | |
---|
232 | template<typename RT, typename F1, typename F2> |
---|
233 | struct Callback_FVF { // FVF stands for arguments (FIXED, VARIABLE, FIXED) |
---|
234 | typedef StrictlyTypedCallback<RT,F1,AW_CL,F2> SigP1; |
---|
235 | typedef StrictlyTypedCallback<RT,F1,F2,void> SigP0F12; |
---|
236 | typedef StrictlyTypedCallback<RT,F2,void,void> SigP0F2; |
---|
237 | |
---|
238 | private: |
---|
239 | enum funtype { ST_P0F12, ST_P0F2, ST_P1 }; // Signature type |
---|
240 | typedef CallbackData<AW_CL,funtype> FVF_CallbackData; |
---|
241 | |
---|
242 | AW_CL cb; // has one of the above Signatures |
---|
243 | SmartPtr<FVF_CallbackData> cd; // cd->p2 cannot be used by clients and is used to select Signature of 'cb' |
---|
244 | |
---|
245 | funtype get_funtype() const { return cd->p2; } |
---|
246 | |
---|
247 | public: |
---|
248 | Callback_FVF(SigP0F12 CB) : cb(CB.get_cb()), cd(new FVF_CallbackData(0, ST_P0F12)) {} |
---|
249 | Callback_FVF(SigP0F2 CB) : cb(CB.get_cb()), cd(new FVF_CallbackData(0, ST_P0F2)) {} |
---|
250 | Callback_FVF(SigP1 CB, AW_CL P1) : cb(CB.get_cb()), cd(new FVF_CallbackData(P1, ST_P1)) {} |
---|
251 | Callback_FVF(SigP1 CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1) : |
---|
252 | cb(CB.get_cb()), |
---|
253 | cd(new FVF_CallbackData(P1, ST_P1, CASTSIG(typename FVF_CallbackData::CallbackDataDeallocator, dealloc))) |
---|
254 | {} |
---|
255 | |
---|
256 | RT operator()(F1 f1, F2 f2) const { |
---|
257 | funtype ft = get_funtype(); |
---|
258 | if (ft == ST_P0F12) return SigP0F12::make_cb(cb)(f1, f2); |
---|
259 | if (ft == ST_P0F2) return SigP0F2::make_cb(cb)(f2); |
---|
260 | arb_assert(ft == ST_P1); |
---|
261 | return SigP1::make_cb(cb)(f1, cd->p1, f2); |
---|
262 | } |
---|
263 | |
---|
264 | bool operator < (const Callback_FVF& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); } |
---|
265 | bool operator == (const Callback_FVF& other) const { return cb == other.cb && *cd == *other.cd; } |
---|
266 | |
---|
267 | bool same_function_as(const Callback_FVF& other) const { return cb == other.cb; } |
---|
268 | |
---|
269 | AW_CL callee() const { return cb; } // @@@ only intermediate - remove later |
---|
270 | AW_CL inspect_CD1() const { return cd->p1; } // @@@ only intermediate - remove later |
---|
271 | AW_CL inspect_CD2() const { return cd->p2; } // @@@ only intermediate - remove later |
---|
272 | }; |
---|
273 | |
---|
274 | |
---|
275 | // --------------------------- |
---|
276 | // convenience macros |
---|
277 | |
---|
278 | #define CASTABLE_TO_AW_CL(TYPE) (sizeof(TYPE) <= sizeof(AW_CL)) |
---|
279 | #define CAST_TO_AW_CL(TYPE,PARAM) AW_CL_castableType<TYPE>::cast_to_AW_CL(PARAM) |
---|
280 | |
---|
281 | #define CONST_PARAM_T(T) typename ConstParamT<T>::Type |
---|
282 | |
---|
283 | #define CAST_DEALLOCATOR(dealloc) CASTSIG(UntypedCallbackData::CallbackDataDeallocator,dealloc) |
---|
284 | |
---|
285 | // ------------ |
---|
286 | // VV |
---|
287 | |
---|
288 | #define CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,P1fun) \ |
---|
289 | template<typename P1> \ |
---|
290 | inline CB BUILDER(RESULT (*cb)(P1fun), P1 p1) { \ |
---|
291 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
292 | return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), 0); \ |
---|
293 | } \ |
---|
294 | template<typename P1> \ |
---|
295 | inline CB BUILDER(RESULT (*cb)(P1fun), \ |
---|
296 | void (*dealloc)(P1), P1 p1) { \ |
---|
297 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
298 | return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), 0); \ |
---|
299 | } |
---|
300 | |
---|
301 | #define CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1fun,P2fun) \ |
---|
302 | template<typename P1, typename P2> \ |
---|
303 | inline CB BUILDER(RESULT (*cb)(P1fun, P2fun), \ |
---|
304 | P1 p1, P2 p2) { \ |
---|
305 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \ |
---|
306 | return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \ |
---|
307 | } \ |
---|
308 | template<typename P1, typename P2> \ |
---|
309 | inline CB BUILDER(RESULT (*cb)(P1fun, P2fun), \ |
---|
310 | void (*dealloc)(P1,P2), P1 p1, P2 p2) { \ |
---|
311 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \ |
---|
312 | return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \ |
---|
313 | } |
---|
314 | |
---|
315 | #define CBTYPE_VV_BUILDER_NP12(BUILDER,CB,RESULT,SIG,P1,P2) \ |
---|
316 | CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,P1); \ |
---|
317 | CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,CONST_PARAM_T(P1)); \ |
---|
318 | CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1,P2); \ |
---|
319 | CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1,CONST_PARAM_T(P2)); \ |
---|
320 | CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,CONST_PARAM_T(P1),P2); \ |
---|
321 | CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,CONST_PARAM_T(P1),CONST_PARAM_T(P2)) |
---|
322 | |
---|
323 | #define CBTYPE_VV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,SIG) \ |
---|
324 | inline CB BUILDER(RESULT (*cb)()) { \ |
---|
325 | return CB(CASTSIG(SIG,cb), 0, 0); \ |
---|
326 | } \ |
---|
327 | CBTYPE_VV_BUILDER_NP12(BUILDER,CB,RESULT,SIG,P1,P2) |
---|
328 | |
---|
329 | // ------------- |
---|
330 | // FVV |
---|
331 | |
---|
332 | #define CBTYPE_FVV_BUILDER_NP(BUILDER,CB,RESULT,FIXED,SIG) \ |
---|
333 | inline CB BUILDER(RESULT (*cb)(FIXED)) { \ |
---|
334 | return CB((SIG)(void*)cb, 0, 0); \ |
---|
335 | } |
---|
336 | |
---|
337 | |
---|
338 | #define CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,P1fun) \ |
---|
339 | template<typename P1> \ |
---|
340 | inline CB BUILDER(RESULT (*cb)(FIXED, P1fun), P1 p1) { \ |
---|
341 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
342 | return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), 0); \ |
---|
343 | } \ |
---|
344 | template<typename P1> \ |
---|
345 | inline CB BUILDER(RESULT (*cb)(FIXED, P1fun), \ |
---|
346 | void (*dealloc)(P1), P1 p1) { \ |
---|
347 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
348 | return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), 0); \ |
---|
349 | } |
---|
350 | |
---|
351 | #define CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1fun,P2fun) \ |
---|
352 | template<typename P1, typename P2> \ |
---|
353 | inline CB BUILDER(RESULT (*cb)(FIXED, P1fun, P2fun), \ |
---|
354 | P1 p1, P2 p2) { \ |
---|
355 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \ |
---|
356 | return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \ |
---|
357 | } \ |
---|
358 | template<typename P1, typename P2> \ |
---|
359 | inline CB BUILDER(RESULT (*cb)(FIXED, P1fun, P2fun), \ |
---|
360 | void (*dealloc)(P1,P2), P1 p1, P2 p2) { \ |
---|
361 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \ |
---|
362 | return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \ |
---|
363 | } |
---|
364 | |
---|
365 | #define CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,FIXED,SIG,P1,P2) \ |
---|
366 | CBTYPE_FVV_BUILDER_NP(BUILDER,CB,RESULT,FIXED,SIG); \ |
---|
367 | CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,P1); \ |
---|
368 | CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,CONST_PARAM_T(P1)); \ |
---|
369 | CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1,P2); \ |
---|
370 | CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1,CONST_PARAM_T(P2)); \ |
---|
371 | CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,CONST_PARAM_T(P1),P2); \ |
---|
372 | CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,CONST_PARAM_T(P1),CONST_PARAM_T(P2)) |
---|
373 | |
---|
374 | #define CBTYPE_FVV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,FIXED,SIG) \ |
---|
375 | inline CB BUILDER(RESULT (*cb)()) { \ |
---|
376 | return CB(CASTSIG(SIG,cb), 0, 0); \ |
---|
377 | } \ |
---|
378 | CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,FIXED,SIG,P1,P2); \ |
---|
379 | CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,UNFIXED,SIG,P1,P2) |
---|
380 | |
---|
381 | #define CBTYPE_FVV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,Pfun) \ |
---|
382 | template<typename P> \ |
---|
383 | inline CB BUILDER(RESULT (*cb)(F1,F2,Pfun), P p) { \ |
---|
384 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P)); \ |
---|
385 | return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P,p)); \ |
---|
386 | } \ |
---|
387 | template<typename P> \ |
---|
388 | inline CB BUILDER(RESULT (*cb)(F1,F2,Pfun), void (*dealloc)(P), P p) { \ |
---|
389 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P)); \ |
---|
390 | return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P,p)); \ |
---|
391 | } |
---|
392 | |
---|
393 | // ------------- |
---|
394 | // FFV |
---|
395 | |
---|
396 | #define CBTYPE_FFV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,F1,F2,SIG) \ |
---|
397 | inline CB BUILDER(RESULT (*cb)()) { return CB(CASTSIG(SIG,cb), 0); } \ |
---|
398 | inline CB BUILDER(RESULT (*cb)(F1)) { return CB(CASTSIG(SIG,cb), 0); } \ |
---|
399 | inline CB BUILDER(RESULT (*cb)(F1,F2)) { return CB(CASTSIG(SIG,cb), 0); } \ |
---|
400 | CBTYPE_FVV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,P); \ |
---|
401 | CBTYPE_FVV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,CONST_PARAM_T(P)) |
---|
402 | |
---|
403 | // ------------- |
---|
404 | // FVF |
---|
405 | |
---|
406 | #define CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,P1fun) \ |
---|
407 | template<typename P1> \ |
---|
408 | inline CB BUILDER(RESULT (*cb)(F1, P1fun, F2), P1 p1) { \ |
---|
409 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
410 | return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1)); \ |
---|
411 | } \ |
---|
412 | template<typename P1> \ |
---|
413 | inline CB BUILDER(RESULT (*cb)(F1, P1fun, F2), \ |
---|
414 | void (*dealloc)(P1), P1 p1) { \ |
---|
415 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
416 | return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1)); \ |
---|
417 | } |
---|
418 | |
---|
419 | #define CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,P1fun) \ |
---|
420 | template<typename P1> \ |
---|
421 | inline CB BUILDER(RESULT (*cb)(F1, P1fun), P1 p1) { \ |
---|
422 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
423 | return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1)); \ |
---|
424 | } \ |
---|
425 | template<typename P1> \ |
---|
426 | inline CB BUILDER(RESULT (*cb)(F1, P1fun), \ |
---|
427 | void (*dealloc)(P1), P1 p1) { \ |
---|
428 | STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \ |
---|
429 | return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1)); \ |
---|
430 | } |
---|
431 | |
---|
432 | #define CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,P1) \ |
---|
433 | inline CB BUILDER(RESULT (*cb)(F1)) { return CB(CASTSIG(SIG01,cb)); } \ |
---|
434 | inline CB BUILDER(RESULT (*cb)(F1,F2)) { return CB(CASTSIG(SIG01,cb)); } \ |
---|
435 | CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,P1); \ |
---|
436 | CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,CONST_PARAM_T(P1)); \ |
---|
437 | CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,P1); \ |
---|
438 | CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,CONST_PARAM_T(P1)) |
---|
439 | |
---|
440 | #define CBTYPE_FVF_BUILDER_TEMPLATES(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,SIG02) \ |
---|
441 | inline CB BUILDER(RESULT (*cb)()) { return CB((SIG01)cb); } \ |
---|
442 | inline CB BUILDER(RESULT (*cb)(F2)) { return CB((SIG02)cb); } \ |
---|
443 | CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,P1); \ |
---|
444 | CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,UNFIXED,F2,SIG,SIG01,P1) |
---|
445 | |
---|
446 | // declares the callback type (CBTYPE) and the makeCBTYPE() templates needed to ensure |
---|
447 | // typecheck between callback-signature and bound parameters |
---|
448 | |
---|
449 | #define DECLARE_CBTYPE_VV_AND_BUILDERS(CBTYPE,RESULT) \ |
---|
450 | typedef Callback_VV<RESULT> CBTYPE; \ |
---|
451 | CBTYPE_VV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT, \ |
---|
452 | CBTYPE::Signature::FuncType) |
---|
453 | |
---|
454 | #define DECLARE_CBTYPE_FVV_AND_BUILDERS(CBTYPE,RESULT,FIXED) \ |
---|
455 | typedef Callback_FVV<RESULT, FIXED> CBTYPE; \ |
---|
456 | CBTYPE_FVV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,FIXED, \ |
---|
457 | CBTYPE::Signature::FuncType) |
---|
458 | |
---|
459 | #define DECLARE_CBTYPE_FFV_AND_BUILDERS(CBTYPE,RESULT,F1,F2) \ |
---|
460 | typedef Callback_FFV<RESULT,F1,F2> CBTYPE; \ |
---|
461 | CBTYPE_FFV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,F1,F2, \ |
---|
462 | CBTYPE::Signature::FuncType) |
---|
463 | |
---|
464 | #define DECLARE_CBTYPE_FVF_AND_BUILDERS(CBTYPE,RESULT,F1,F2) \ |
---|
465 | typedef Callback_FVF<RESULT,F1,F2> CBTYPE; \ |
---|
466 | CBTYPE_FVF_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,F1,F2, \ |
---|
467 | CBTYPE::SigP1::FuncType, \ |
---|
468 | CBTYPE::SigP0F12::FuncType, \ |
---|
469 | CBTYPE::SigP0F2::FuncType) |
---|
470 | |
---|
471 | #else |
---|
472 | #error cbtypes.h included twice |
---|
473 | #endif // CBTYPES_H |
---|