source: tags/ms_r16q3/SL/CB/cbtypes.h

Last change on this file was 14479, checked in by westram, 8 years ago
  • add new typed callback style w/o fixed argument
    • add unit tests for callback style
File size: 24.0 KB
Line 
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
32template<typename RT, typename P1, typename P2, typename P3>
33struct Function {
34    enum { NumParams = 3 };
35    typedef RT (*Type)(P1,P2,P3);
36    typedef RT ResultType;
37};
38template<typename RT, typename P1, typename P2>
39struct Function<RT, P1, P2, void> {
40    enum { NumParams = 2 };
41    typedef RT (*Type)(P1,P2);
42};
43template<typename RT, typename P1>
44struct Function<RT, P1, void, void> {
45    enum { NumParams = 1 };
46    typedef RT (*Type)(P1);
47};
48template<typename RT>
49struct Function<RT, void, void, void> {
50    enum { NumParams = 0 };
51    typedef RT (*Type)();
52};
53
54// ---------------------------
55//      forward parameters
56
57template<typename T>
58struct ForwardParamT {
59    typedef typename IfThenElseType< TypeT<T>::IsClassT,
60                                     typename TypeOp<T>::RefConstT,
61                                     typename TypeOp<T>::ArgT >::ResultType Type;
62};
63
64template<typename T>
65struct ForwardParamT<T*> {
66    typedef typename TypeOp<T>::ArgT *Type;
67};
68template<> class ForwardParamT<void> { class Unused {}; public: typedef Unused Type; };
69
70// ------------------------------
71//      const parameter types
72
73template<typename T>
74struct ConstParamT {
75    typedef typename IfThenElseType< TypeT<T>::IsClassT,
76                                     typename TypeOp<T>::RefConstT,
77                                     typename TypeOp<T>::ConstT >::ResultType Type;
78};
79template<typename T>
80struct ConstParamT<T*> {
81    typedef typename TypeOp<T>::ConstT *Type;
82};
83template<> class ConstParamT<void> { class Unused {}; public: typedef Unused Type; };
84
85// ------------------------------------
86//      forbid some parameter types
87
88template<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
92INVALID_CB_PARAM_TYPE(void);
93INVALID_CB_PARAM_TYPE(double);
94INVALID_CB_PARAM_TYPE(float);
95
96#undef INVALID_CB_PARAM_TYPE
97
98// -----------------------
99//      typed callback
100
101template<typename RT, typename P1 = void, typename P2 = void, typename P3 = void>
102struct StrictlyTypedCallback {
103    typedef typename Function<RT,P1,P2,P3>::Type FuncType;
104
105private:
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
112public:
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
136template<typename P1, typename P2>
137struct 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(NULL) {}
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
155typedef CallbackData<AW_CL,AW_CL> UntypedCallbackData;
156
157// ------------------------------
158//      casted callback types
159
160template<typename RT>
161struct Callback_VV { // VV stands for arguments (VARIABLE, VARIABLE)
162    typedef StrictlyTypedCallback<RT,AW_CL,AW_CL,AW_CL> Signature;
163
164private:
165    Signature                     cb;
166    SmartPtr<UntypedCallbackData> cd;
167
168public:
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
184template<typename RT, typename FIXED>
185struct Callback_FVV { // FVV stands for arguments (FIXED, VARIABLE, VARIABLE)
186    typedef StrictlyTypedCallback<RT,FIXED,AW_CL,AW_CL> Signature;
187
188private:
189    Signature                     cb;
190    SmartPtr<UntypedCallbackData> cd;
191
192public:
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
208template<typename RT, typename F1, typename F2>
209struct Callback_FFV { // FFV stands for arguments (FIXED, FIXED, VARIABLE)
210    typedef StrictlyTypedCallback<RT,F1,F2,AW_CL> Signature;
211
212private:
213    typedef CallbackData<AW_CL, AW_CL> FFV_CallbackData; // 2nd AW_CL is unused
214
215    Signature                  cb;
216    SmartPtr<FFV_CallbackData> cd;
217
218public:
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
227template<typename RT, typename F1, typename F2>
228struct Callback_FVF { // FVF stands for arguments (FIXED, VARIABLE, FIXED)
229    typedef StrictlyTypedCallback<RT,F1,AW_CL,F2>  SigP1;
230    typedef StrictlyTypedCallback<RT,F1,F2,void>   SigP0F12;
231    typedef StrictlyTypedCallback<RT,F2,void,void> SigP0F2;
232
233private:
234    enum funtype { ST_P0F12, ST_P0F2, ST_P1 }; // Signature type
235    typedef CallbackData<AW_CL,funtype> FVF_CallbackData;
236
237    AW_CL                      cb;  // has one of the above Signatures
238    SmartPtr<FVF_CallbackData> cd;  // cd->p2 cannot be used by clients and is used to select Signature of 'cb'
239
240    funtype get_funtype() const { return cd->p2; }
241
242public:
243    Callback_FVF(SigP0F12 CB) : cb(CB.get_cb()), cd(new FVF_CallbackData(0, ST_P0F12)) {}
244    Callback_FVF(SigP0F2 CB) : cb(CB.get_cb()), cd(new FVF_CallbackData(0, ST_P0F2)) {}
245    Callback_FVF(SigP1 CB, AW_CL P1) : cb(CB.get_cb()), cd(new FVF_CallbackData(P1, ST_P1)) {}
246    Callback_FVF(SigP1 CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1)
247        : cb(CB.get_cb()), cd(new FVF_CallbackData(P1, ST_P1, (typename FVF_CallbackData::CallbackDataDeallocator)dealloc)) {}
248
249    RT operator()(F1 f1, F2 f2) const {
250        funtype ft = get_funtype();
251        if (ft == ST_P0F12) return SigP0F12::make_cb(cb)(f1, f2);
252        if (ft == ST_P0F2) return SigP0F2::make_cb(cb)(f2);
253        arb_assert(ft == ST_P1);
254        return SigP1::make_cb(cb)(f1, cd->p1, f2);
255    }
256
257    bool operator <  (const Callback_FVF& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); }
258    bool operator == (const Callback_FVF& other) const { return cb == other.cb && *cd == *other.cd; }
259
260    bool same_function_as(const Callback_FVF& other) const { return cb == other.cb; }
261
262    AW_CL callee() const { return cb; }          // @@@ only intermediate - remove later
263    AW_CL inspect_CD1() const { return cd->p1; } // @@@ only intermediate - remove later
264    AW_CL inspect_CD2() const { return cd->p2; } // @@@ only intermediate - remove later
265};
266
267
268// ---------------------------
269//      convenience macros
270
271#define CASTABLE_TO_AW_CL(TYPE)   (sizeof(TYPE) <= sizeof(AW_CL))
272#define CAST_TO_AW_CL(TYPE,PARAM) AW_CL_castableType<TYPE>::cast_to_AW_CL(PARAM)
273
274#define CONST_PARAM_T(T) typename ConstParamT<T>::Type
275
276// ------------
277//      VV
278
279#define CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,P1fun)                                                    \
280    template<typename P1>                                                                                       \
281    inline CB BUILDER(RESULT (*cb)(P1fun), P1 p1) {                                                             \
282        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
283        return CB((SIG)cb, CAST_TO_AW_CL(P1,p1), 0);                                                            \
284    }                                                                                                           \
285    template<typename P1>                                                                                       \
286    inline CB BUILDER(RESULT (*cb)(P1fun),                                                                      \
287                      void (*dealloc)(P1), P1 p1) {                                                             \
288        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
289        return CB((SIG)cb, (UntypedCallbackData::CallbackDataDeallocator)dealloc, CAST_TO_AW_CL(P1,p1), 0);     \
290    }
291
292#define CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1fun,P2fun)                                                 \
293    template<typename P1, typename P2>                                                                                  \
294    inline CB BUILDER(RESULT (*cb)(P1fun, P2fun),                                                                       \
295                      P1 p1, P2 p2) {                                                                                   \
296        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2));                                                  \
297        return CB((SIG)cb, CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2));                                                 \
298    }                                                                                                                   \
299    template<typename P1, typename P2>                                                                                  \
300    inline CB BUILDER(RESULT (*cb)(P1fun, P2fun),                                                                       \
301                      void (*dealloc)(P1,P2), P1 p1, P2 p2) {                                                           \
302        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2));                                                  \
303        return CB((SIG)cb, (UntypedCallbackData::CallbackDataDeallocator)dealloc, CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \
304    }
305
306#define CBTYPE_VV_BUILDER_NP12(BUILDER,CB,RESULT,SIG,P1,P2)                                     \
307    CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,P1);                                          \
308    CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,CONST_PARAM_T(P1));                           \
309    CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1,P2);                                  \
310    CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1,CONST_PARAM_T(P2));                   \
311    CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,CONST_PARAM_T(P1),P2);                   \
312    CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,CONST_PARAM_T(P1),CONST_PARAM_T(P2))
313
314#define CBTYPE_VV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,SIG)      \
315    inline CB BUILDER(RESULT (*cb)()) {                         \
316        return CB((SIG)cb, 0, 0);                               \
317    }                                                           \
318    CBTYPE_VV_BUILDER_NP12(BUILDER,CB,RESULT,SIG,P1,P2)
319
320// -------------
321//      FVV
322
323#define CBTYPE_FVV_BUILDER_NP(BUILDER,CB,RESULT,FIXED,SIG)      \
324    inline CB BUILDER(RESULT (*cb)(FIXED)) {                    \
325        return CB((SIG)cb, 0, 0);                               \
326    }
327
328
329#define CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,P1fun)                                             \
330    template<typename P1>                                                                                       \
331    inline CB BUILDER(RESULT (*cb)(FIXED, P1fun), P1 p1) {                                                      \
332        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
333        return CB((SIG)cb, CAST_TO_AW_CL(P1,p1), 0);                                                            \
334    }                                                                                                           \
335    template<typename P1>                                                                                       \
336    inline CB BUILDER(RESULT (*cb)(FIXED, P1fun),                                                               \
337                      void (*dealloc)(P1), P1 p1) {                                                             \
338        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
339        return CB((SIG)cb, (UntypedCallbackData::CallbackDataDeallocator)dealloc, CAST_TO_AW_CL(P1,p1), 0);     \
340    }
341
342#define CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1fun,P2fun) \
343    template<typename P1, typename P2>                                  \
344    inline CB BUILDER(RESULT (*cb)(FIXED, P1fun, P2fun),                \
345                      P1 p1, P2 p2) {                                   \
346        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2));  \
347        return CB((SIG)cb, CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \
348    }                                                                   \
349    template<typename P1, typename P2>                                  \
350    inline CB BUILDER(RESULT (*cb)(FIXED, P1fun, P2fun),                \
351                      void (*dealloc)(P1,P2), P1 p1, P2 p2) {           \
352        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2));  \
353        return CB((SIG)cb, (UntypedCallbackData::CallbackDataDeallocator)dealloc, CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \
354    }
355
356#define CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,FIXED,SIG,P1,P2)                                      \
357    CBTYPE_FVV_BUILDER_NP(BUILDER,CB,RESULT,FIXED,SIG);                                                 \
358    CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,P1);                                           \
359    CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,CONST_PARAM_T(P1));                            \
360    CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1,P2);                                   \
361    CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1,CONST_PARAM_T(P2));                    \
362    CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,CONST_PARAM_T(P1),P2);                    \
363    CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,CONST_PARAM_T(P1),CONST_PARAM_T(P2))
364
365#define CBTYPE_FVV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,FIXED,SIG)                                       \
366    inline CB BUILDER(RESULT (*cb)()) {                                                                 \
367        return CB((SIG)cb, 0, 0);                                                                       \
368    }                                                                                                   \
369    CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,FIXED,SIG,P1,P2);                                         \
370    CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,UNFIXED,SIG,P1,P2)
371
372#define CBTYPE_FVV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,Pfun)                                        \
373    template<typename P>                                                                                \
374    inline CB BUILDER(RESULT (*cb)(F1,F2,Pfun), P p) {                                                  \
375        STATIC_ASSERT(CASTABLE_TO_AW_CL(P));                                                            \
376        return CB((SIG)cb, CAST_TO_AW_CL(P,p));                                                         \
377    }                                                                                                   \
378    template<typename P>                                                                                \
379    inline CB BUILDER(RESULT (*cb)(F1,F2,Pfun), void (*dealloc)(P), P p) {                              \
380        STATIC_ASSERT(CASTABLE_TO_AW_CL(P));                                                            \
381        return CB((SIG)cb, (UntypedCallbackData::CallbackDataDeallocator)dealloc, CAST_TO_AW_CL(P,p));  \
382    }
383
384// -------------
385//      FFV
386
387#define CBTYPE_FFV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,F1,F2,SIG)          \
388    inline CB BUILDER(RESULT (*cb)()) { return CB((SIG)cb, 0); }           \
389    inline CB BUILDER(RESULT (*cb)(F1)) { return CB((SIG)cb, 0); }         \
390    inline CB BUILDER(RESULT (*cb)(F1,F2)) { return CB((SIG)cb, 0); }      \
391    CBTYPE_FVV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,P);                 \
392    CBTYPE_FVV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,CONST_PARAM_T(P))
393
394// -------------
395//      FVF
396
397#define CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,P1fun)                                        \
398    template<typename P1>                                                                                       \
399    inline CB BUILDER(RESULT (*cb)(F1, P1fun, F2), P1 p1) {                                                     \
400        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
401        return CB((SIG)cb, CAST_TO_AW_CL(P1,p1));                                                               \
402    }                                                                                                           \
403    template<typename P1>                                                                                       \
404    inline CB BUILDER(RESULT (*cb)(F1, P1fun, F2),                                                              \
405                      void (*dealloc)(P1), P1 p1) {                                                             \
406        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
407        return CB((SIG)cb, (UntypedCallbackData::CallbackDataDeallocator)dealloc, CAST_TO_AW_CL(P1,p1));        \
408    }
409
410#define CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,P1fun)                                             \
411    template<typename P1>                                                                                       \
412    inline CB BUILDER(RESULT (*cb)(F1, P1fun), P1 p1) {                                                         \
413        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
414        return CB((SIG)cb, CAST_TO_AW_CL(P1,p1));                                                               \
415    }                                                                                                           \
416    template<typename P1>                                                                                       \
417    inline CB BUILDER(RESULT (*cb)(F1, P1fun),                                                                  \
418                      void (*dealloc)(P1), P1 p1) {                                                             \
419        STATIC_ASSERT(CASTABLE_TO_AW_CL(P1));                                                                   \
420        return CB((SIG)cb, (UntypedCallbackData::CallbackDataDeallocator)dealloc, CAST_TO_AW_CL(P1,p1));        \
421    }
422
423#define CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,P1)                    \
424    inline CB BUILDER(RESULT (*cb)(F1)) { return CB((SIG01)cb); }                       \
425    inline CB BUILDER(RESULT (*cb)(F1,F2)) { return CB((SIG01)cb); }                    \
426    CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,P1);                      \
427    CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,CONST_PARAM_T(P1));       \
428    CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,P1);                           \
429    CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,CONST_PARAM_T(P1))
430
431#define CBTYPE_FVF_BUILDER_TEMPLATES(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,SIG02)           \
432    inline CB BUILDER(RESULT (*cb)()) { return CB((SIG01)cb); }                         \
433    inline CB BUILDER(RESULT (*cb)(F2)) { return CB((SIG02)cb); }                       \
434    CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,P1);                       \
435    CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,UNFIXED,F2,SIG,SIG01,P1)
436
437// declares the callback type (CBTYPE) and the makeCBTYPE() templates needed to ensure
438// typecheck between callback-signature and bound parameters
439
440#define DECLARE_CBTYPE_VV_AND_BUILDERS(CBTYPE,RESULT)           \
441    typedef Callback_VV<RESULT> CBTYPE;                         \
442    CBTYPE_VV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,     \
443                                CBTYPE::Signature::FuncType)
444
445#define DECLARE_CBTYPE_FVV_AND_BUILDERS(CBTYPE,RESULT,FIXED)            \
446    typedef Callback_FVV<RESULT, FIXED> CBTYPE;                         \
447    CBTYPE_FVV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,FIXED,      \
448                                 CBTYPE::Signature::FuncType)
449
450#define DECLARE_CBTYPE_FFV_AND_BUILDERS(CBTYPE,RESULT,F1,F2)            \
451    typedef Callback_FFV<RESULT,F1,F2> CBTYPE;                          \
452    CBTYPE_FFV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,F1,F2,      \
453                                 CBTYPE::Signature::FuncType)
454
455#define DECLARE_CBTYPE_FVF_AND_BUILDERS(CBTYPE,RESULT,F1,F2)            \
456    typedef Callback_FVF<RESULT,F1,F2> CBTYPE;                          \
457    CBTYPE_FVF_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,F1,F2,      \
458                                 CBTYPE::SigP1::FuncType,               \
459                                 CBTYPE::SigP0F12::FuncType,            \
460                                 CBTYPE::SigP0F2::FuncType)
461
462#else
463#error cbtypes.h included twice
464#endif // CBTYPES_H
Note: See TracBrowser for help on using the repository browser.