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