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 // if you really need to provide a double, use e.g. 'const double*' and make sure pointed-to instance persists.
98 
99 #undef INVALID_CB_PARAM_TYPE
100 
101 // -----------------------
102 // typed callback
103 
104 template<typename RT, typename P1 = void, typename P2 = void, typename P3 = void>
107 
108 private:
109  typedef typename ForwardParamT<P1>::Type FP1;
110  typedef typename ForwardParamT<P2>::Type FP2;
111  typedef typename ForwardParamT<P3>::Type FP3;
112 
113  FuncType cb;
114 
115 public:
117 
118  StrictlyTypedCallback(FuncType CB) : cb(CB) {}
119 
120  RT operator()(FP1 p1, FP2 p2, FP3 p3) const { return cb(p1, p2, p3); }
121  RT operator()(FP1 p1, FP2 p2) const { return cb(p1, p2); }
122  RT operator()(FP1 p1) const { return cb(p1); }
123  RT operator()() const { return cb(); }
124 
125  bool equals(const StrictlyTypedCallback& other) const { return cb == other.cb; }
126 
127  AW_CL get_cb() const { return (AW_CL)cb; }
128  static StrictlyTypedCallback make_cb(AW_CL cb_) { return StrictlyTypedCallback((FuncType)cb_); }
129 
130  bool is_set() const { return cb != 0; }
131 
132  bool operator < (const StrictlyTypedCallback& other) const { return cb < other.cb; }
133  bool operator == (const StrictlyTypedCallback& other) const { return cb == other.cb; }
134 };
135 
136 // ---------------------
137 // CallbackData
138 
139 template<typename P1, typename P2>
140 struct CallbackData {
141  P1 p1;
142  P2 p2;
143 
144  typedef void (*CallbackDataDeallocator)(P1 p1, P2 p2);
146 
147  CallbackData(P1 p1_, P2 p2_) : p1(p1_), p2(p2_), dealloc(NULp) {}
148  CallbackData(P1 p1_, P2 p2_, CallbackDataDeallocator dealloc_) : p1(p1_), p2(p2_), dealloc(dealloc_) {}
149  ~CallbackData() { if (dealloc) dealloc(p1, p2); }
150  bool operator < (const CallbackData& other) const {
151  return p1<other.p1 || (p1 == other.p1 && (p2< other.p2 || (p2 == other.p2 && dealloc<other.dealloc)));
152  }
153  bool operator == (const CallbackData& other) const {
154  return p1 == other.p1 && p2 == other.p2 && dealloc == other.dealloc;
155  }
156 };
157 
159 
160 // ------------------------------
161 // casted callback types
162 
163 template<typename RT>
164 struct Callback_VV { // VV stands for arguments (VARIABLE, VARIABLE)
166 
167 private:
168  Signature cb;
170 
171 public:
172  Callback_VV(Signature CB, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2)) {}
173  Callback_VV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2, dealloc)) {}
174 
175  RT operator()() const { return cb(cd->p1, cd->p2, 0); }
176 
177  bool operator < (const Callback_VV& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); }
178  bool operator == (const Callback_VV& other) const { return cb == other.cb && *cd == *other.cd; }
179 
180  bool same_function_as(const Callback_VV& other) const { return cb == other.cb; }
181 
182  AW_CL callee() const { return cb.get_cb(); } // @@@ only intermediate - remove later
183  AW_CL inspect_CD1() const { return cd->p1; } // @@@ only intermediate - remove later
184  AW_CL inspect_CD2() const { return cd->p2; } // @@@ only intermediate - remove later
185 };
186 
187 template<typename RT, typename FIXED>
188 struct Callback_FVV { // FVV stands for arguments (FIXED, VARIABLE, VARIABLE)
190 
191 private:
192  Signature cb;
194 
195 public:
196  Callback_FVV(Signature CB, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2)) {}
197  Callback_FVV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2) : cb(CB), cd(new UntypedCallbackData(P1, P2, dealloc)) {}
198 
199  RT operator()(FIXED fixed) const { return cb(fixed, cd->p1, cd->p2); }
200 
201  bool operator < (const Callback_FVV& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); }
202  bool operator == (const Callback_FVV& other) const { return cb == other.cb && *cd == *other.cd; }
203 
204  bool same_function_as(const Callback_FVV& other) const { return cb == other.cb; }
205 
206  AW_CL callee() const { return cb.get_cb(); } // @@@ only intermediate - remove later
207  AW_CL inspect_CD1() const { return cd->p1; } // @@@ only intermediate - remove later
208  AW_CL inspect_CD2() const { return cd->p2; } // @@@ only intermediate - remove later
209 };
210 
211 template<typename RT, typename F1, typename F2>
212 struct Callback_FFV { // FFV stands for arguments (FIXED, FIXED, VARIABLE)
214 
215 private:
216  typedef CallbackData<AW_CL, AW_CL> FFV_CallbackData; // 2nd AW_CL is unused
217 
218  Signature cb;
220 
221 public:
222  Callback_FFV(Signature CB, AW_CL P)
223  : cb(CB),
224  cd(new FFV_CallbackData(P, 0))
225  {}
226 
227  RT operator()(F1 f1, F2 f2) const { return cb(f1, f2, cd->p1); }
228 
229  bool operator < (const Callback_FFV& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); }
230  bool operator == (const Callback_FFV& other) const { return cb == other.cb && *cd == *other.cd; }
231 
232  bool same_function_as(const Callback_FFV& other) const { return cb == other.cb; }
233 };
234 
235 template<typename RT, typename F1, typename F2>
236 struct Callback_FVF { // FVF stands for arguments (FIXED, VARIABLE, FIXED)
240 
241 private:
242  enum funtype { ST_P0F12, ST_P0F2, ST_P1 }; // Signature type
243  typedef CallbackData<AW_CL,funtype> FVF_CallbackData;
244 
245  AW_CL cb; // has one of the above Signatures
246  SmartPtr<FVF_CallbackData> cd; // cd->p2 cannot be used by clients and is used to select Signature of 'cb'
247 
248  funtype get_funtype() const { return cd->p2; }
249 
250 public:
251  Callback_FVF(SigP0F12 CB) : cb(CB.get_cb()), cd(new FVF_CallbackData(0, ST_P0F12)) {}
252  Callback_FVF(SigP0F2 CB) : cb(CB.get_cb()), cd(new FVF_CallbackData(0, ST_P0F2)) {}
253  Callback_FVF(SigP1 CB, AW_CL P1) : cb(CB.get_cb()), cd(new FVF_CallbackData(P1, ST_P1)) {}
255  cb(CB.get_cb()),
256  cd(new FVF_CallbackData(P1, ST_P1, CASTSIG(typename FVF_CallbackData::CallbackDataDeallocator, dealloc)))
257  {}
258 
259  RT operator()(F1 f1, F2 f2) const {
260  funtype ft = get_funtype();
261  if (ft == ST_P0F12) return SigP0F12::make_cb(cb)(f1, f2);
262  if (ft == ST_P0F2) return SigP0F2::make_cb(cb)(f2);
263  arb_assert(ft == ST_P1);
264  return SigP1::make_cb(cb)(f1, cd->p1, f2);
265  }
266 
267  bool operator < (const Callback_FVF& other) const { return cb<other.cb || (cb == other.cb && *cd<*other.cd); }
268  bool operator == (const Callback_FVF& other) const { return cb == other.cb && *cd == *other.cd; }
269 
270  bool same_function_as(const Callback_FVF& other) const { return cb == other.cb; }
271 
272  AW_CL callee() const { return cb; } // @@@ only intermediate - remove later
273  AW_CL inspect_CD1() const { return cd->p1; } // @@@ only intermediate - remove later
274  AW_CL inspect_CD2() const { return cd->p2; } // @@@ only intermediate - remove later
275 };
276 
277 
278 // ---------------------------
279 // convenience macros
280 
281 #define CASTABLE_TO_AW_CL(TYPE) (sizeof(TYPE) <= sizeof(AW_CL))
282 #define CAST_TO_AW_CL(TYPE,PARAM) AW_CL_castableType<TYPE>::cast_to_AW_CL(PARAM)
283 
284 #define CONST_PARAM_T(T) typename ConstParamT<T>::Type
285 
286 #define CAST_DEALLOCATOR(dealloc) CASTSIG(UntypedCallbackData::CallbackDataDeallocator,dealloc)
287 
288 // If a parameter is mutable (in the sense that the callee may modify the callers data),
289 // a matching callback shall be allowed to accept that parameter const-qualified,
290 // i.e. we need an additional builder accepting such a callback.
291 template<typename P> struct ParamIsMutable { static constexpr bool value = false; }; // default case: everything is considered immutable (by-value, const&, const*, etc.)
292 template<typename P> struct ParamIsMutable<P&> { static constexpr bool value = !std::is_const<P>::value; }; // plain lvalue references to NON-const are MUTABLE
293 template<typename P> struct ParamIsMutable<P*> { static constexpr bool value = !std::is_const<P>::value; }; // pointers to NON-const are MUTABLE
294 template<typename P> struct ParamIsMutable<P* const> { static constexpr bool value = !std::is_const<P>::value; }; // handle const-qualified pointer variables (e.g., int* const)
295 template<typename ReturnType, typename... Args> struct ParamIsMutable<ReturnType(*)(Args...)> { static constexpr bool value = false; }; // functions pointers are never MUTABLE
296 
297 #define CONST_VARIANT_REQUIRED(T) ParamIsMutable<T>::value
298 #define CONST_VARIANTS_REQUIRED(T1,T2) (CONST_VARIANT_REQUIRED(T1) && CONST_VARIANT_REQUIRED(T2))
299 
300 // defines a return type (e.g. for builder templates), while allowing to completely disable the template (when COND is false):
301 #define RETURN_TYPE_IF(COND,CB) typename std::enable_if<COND,CB>::type
302 
303 // ----------------------------------------------------
304 // builder-macro parameter naming conventions
305 //
306 // parameter explanation example
307 // --------- ----------- -------
308 // BUILDER builder name makeCreateWindowCallback
309 // CB callback type; result of BUILDER CreateWindowCallback
310 // RESULT result type of CB AW_window*
311 // FIXED fixed parameter (for FVV) AW_root*
312 // F# fixed parameters (for FFV and FVF)
313 // SIG internal AW_CL Signature CreateWindowCallback::Signature::FuncType (see Callback_FVV)
314 // P# first or second custom CB parameter int, char*, const double*
315 // P#fun same base type as P#, may add constness int, const char*, const double*
316 // MAYBE_CB enable_if-guarded callback type (CB)
317 
318 // ------------
319 // VV
320 
321 #define CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,P1fun,MAYBE_CB) \
322  template<typename P1> \
323  inline MAYBE_CB \
324  BUILDER(RESULT (*cb)(P1fun), P1 p1) { \
325  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
326  return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), 0); \
327  } \
328  template<typename P1> \
329  inline MAYBE_CB \
330  BUILDER(RESULT (*cb)(P1fun), void (*dealloc)(P1), P1 p1) { \
331  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
332  return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), 0); \
333  }
334 
335 #define CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1fun,P2fun,MAYBE_CB) \
336  template<typename P1, typename P2> \
337  inline MAYBE_CB \
338  BUILDER(RESULT (*cb)(P1fun, P2fun), P1 p1, P2 p2) { \
339  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \
340  return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \
341  } \
342  template<typename P1, typename P2> \
343  inline MAYBE_CB \
344  BUILDER(RESULT (*cb)(P1fun, P2fun), void (*dealloc)(P1,P2), P1 p1, P2 p2) { \
345  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \
346  return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \
347  }
348 
349 #define CBTYPE_VV_BUILDER_NP12(BUILDER,CB,RESULT,SIG,P1,P2) \
350  CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,P1,RETURN_TYPE_IF(true,CB)); \
351  CBTYPE_VV_BUILDER_P1(BUILDER,CB,RESULT,SIG,P1,CONST_PARAM_T(P1),RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P1),CB)); \
352  CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1,P2,RETURN_TYPE_IF(true,CB)); \
353  CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1,CONST_PARAM_T(P2),RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P2),CB)); \
354  CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,CONST_PARAM_T(P1),P2,RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P1),CB)); \
355  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))
356 
357 #define CBTYPE_VV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,SIG) \
358  inline CB BUILDER(RESULT (*cb)()) { \
359  return CB(CASTSIG(SIG,cb), 0, 0); \
360  } \
361  CBTYPE_VV_BUILDER_NP12(BUILDER,CB,RESULT,SIG,P1,P2)
362 
363 // -------------
364 // FVV
365 
366 #define CBTYPE_FVV_BUILDER_NP(BUILDER,CB,RESULT,FIXED,SIG) \
367  inline CB BUILDER(RESULT (*cb)(FIXED)) { \
368  return CB((SIG)(void*)cb, 0, 0); \
369  }
370 
371 
372 #define CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,P1fun,MAYBE_CB) \
373  template<typename P1> \
374  inline MAYBE_CB \
375  BUILDER(RESULT (*cb)(FIXED, P1fun), P1 p1) { \
376  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
377  return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), 0); \
378  } \
379  template<typename P1> \
380  inline MAYBE_CB \
381  BUILDER(RESULT (*cb)(FIXED, P1fun), void (*dealloc)(P1), P1 p1) { \
382  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
383  return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), 0); \
384  }
385 
386 #define CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1fun,P2fun,MAYBE_CB) \
387  template<typename P1, typename P2> \
388  inline MAYBE_CB \
389  BUILDER(RESULT (*cb)(FIXED, P1fun, P2fun), P1 p1, P2 p2) { \
390  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \
391  return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \
392  } \
393  template<typename P1, typename P2> \
394  inline MAYBE_CB \
395  BUILDER(RESULT (*cb)(FIXED, P1fun, P2fun), void (*dealloc)(P1,P2), P1 p1, P2 p2) { \
396  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1) && CASTABLE_TO_AW_CL(P2)); \
397  return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1), CAST_TO_AW_CL(P2,p2)); \
398  }
399 
400 #define CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,FIXED,SIG,P1,P2) \
401  CBTYPE_FVV_BUILDER_NP(BUILDER,CB,RESULT,FIXED,SIG); \
402  CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,P1,RETURN_TYPE_IF(true,CB)); \
403  CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,CONST_PARAM_T(P1),RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P1),CB)); \
404  CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1,P2,RETURN_TYPE_IF(true,CB)); \
405  CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1,CONST_PARAM_T(P2),RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P2),CB)); \
406  CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,CONST_PARAM_T(P1),P2,RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P1),CB)); \
407  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))
408 
409 #define CBTYPE_FVV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,FIXED,SIG) \
410  inline CB BUILDER(RESULT (*cb)()) { \
411  return CB(CASTSIG(SIG,cb), 0, 0); \
412  } \
413  CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,FIXED,SIG,P1,P2); \
414  CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,UNFIXED,SIG,P1,P2)
415 
416 // -------------
417 // FFV
418 
419 #define CBTYPE_FFV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,Pfun,MAYBE_CB) \
420  template<typename P> \
421  inline MAYBE_CB \
422  BUILDER(RESULT (*cb)(F1,F2,Pfun), P p) { \
423  STATIC_ASSERT(CASTABLE_TO_AW_CL(P)); \
424  return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P,p)); \
425  } \
426  template<typename P> \
427  inline MAYBE_CB \
428  BUILDER(RESULT (*cb)(F1,F2,Pfun), void (*dealloc)(P), P p) { \
429  STATIC_ASSERT(CASTABLE_TO_AW_CL(P)); \
430  return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P,p)); \
431  }
432 
433 #define CBTYPE_FFV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,F1,F2,SIG) \
434  inline CB BUILDER(RESULT (*cb)()) { return CB(CASTSIG(SIG,cb), 0); } \
435  inline CB BUILDER(RESULT (*cb)(F1)) { return CB(CASTSIG(SIG,cb), 0); } \
436  inline CB BUILDER(RESULT (*cb)(F1,F2)) { return CB(CASTSIG(SIG,cb), 0); } \
437  CBTYPE_FFV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,P,RETURN_TYPE_IF(true,CB)); \
438  CBTYPE_FFV_BUILDER_P(BUILDER,CB,RESULT,F1,F2,SIG,P,CONST_PARAM_T(P),RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P),CB))
439 
440 // -------------
441 // FVF
442 
443 #define CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,P1fun,MAYBE_CB) \
444  template<typename P1> \
445  inline MAYBE_CB \
446  BUILDER(RESULT (*cb)(F1, P1fun, F2), P1 p1) { \
447  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
448  return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1)); \
449  } \
450  template<typename P1> \
451  inline MAYBE_CB \
452  BUILDER(RESULT (*cb)(F1, P1fun, F2), void (*dealloc)(P1), P1 p1) { \
453  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
454  return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1)); \
455  }
456 
457 #define CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,P1fun,MAYBE_CB) \
458  template<typename P1> \
459  inline MAYBE_CB \
460  BUILDER(RESULT (*cb)(F1, P1fun), P1 p1) { \
461  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
462  return CB(CASTSIG(SIG,cb), CAST_TO_AW_CL(P1,p1)); \
463  } \
464  template<typename P1> \
465  inline MAYBE_CB \
466  BUILDER(RESULT (*cb)(F1, P1fun), void (*dealloc)(P1), P1 p1) { \
467  STATIC_ASSERT(CASTABLE_TO_AW_CL(P1)); \
468  return CB(CASTSIG(SIG,cb), CAST_DEALLOCATOR(dealloc), CAST_TO_AW_CL(P1,p1)); \
469  }
470 
471 #define CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,P1) \
472  inline CB BUILDER(RESULT (*cb)(F1)) { return CB(CASTSIG(SIG01,cb)); } \
473  inline CB BUILDER(RESULT (*cb)(F1,F2)) { return CB(CASTSIG(SIG01,cb)); } \
474  CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,P1,RETURN_TYPE_IF(true,CB)); \
475  CBTYPE_FVF_BUILDER_P1_F1F2(BUILDER,CB,RESULT,F1,F2,SIG,P1,CONST_PARAM_T(P1),RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P1),CB)); \
476  CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,P1,RETURN_TYPE_IF(true,CB)); \
477  CBTYPE_FVF_BUILDER_P1_F1(BUILDER,CB,RESULT,F1,SIG,P1,CONST_PARAM_T(P1),RETURN_TYPE_IF(CONST_VARIANT_REQUIRED(P1),CB))
478 
479 #define CBTYPE_FVF_BUILDER_TEMPLATES(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,SIG02) \
480  inline CB BUILDER(RESULT (*cb)()) { return CB((SIG01)cb); } \
481  inline CB BUILDER(RESULT (*cb)(F2)) { return CB((SIG02)cb); } \
482  CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,F1,F2,SIG,SIG01,P1); \
483  CBTYPE_FVF_BUILDER_NP1(BUILDER,CB,RESULT,UNFIXED,F2,SIG,SIG01,P1)
484 
485 // declares the callback type (CBTYPE) and the makeCBTYPE() templates needed to ensure
486 // typecheck between callback-signature and bound parameters
487 
488 #define DECLARE_CBTYPE_VV_AND_BUILDERS(CBTYPE,RESULT) \
489  typedef Callback_VV<RESULT> CBTYPE; \
490  CBTYPE_VV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT, \
491  CBTYPE::Signature::FuncType)
492 
493 #define DECLARE_CBTYPE_FVV_AND_BUILDERS(CBTYPE,RESULT,FIXED) \
494  typedef Callback_FVV<RESULT, FIXED> CBTYPE; \
495  CBTYPE_FVV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,FIXED, \
496  CBTYPE::Signature::FuncType)
497 
498 #define DECLARE_CBTYPE_FFV_AND_BUILDERS(CBTYPE,RESULT,F1,F2) \
499  typedef Callback_FFV<RESULT,F1,F2> CBTYPE; \
500  CBTYPE_FFV_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,F1,F2, \
501  CBTYPE::Signature::FuncType)
502 
503 #define DECLARE_CBTYPE_FVF_AND_BUILDERS(CBTYPE,RESULT,F1,F2) \
504  typedef Callback_FVF<RESULT,F1,F2> CBTYPE; \
505  CBTYPE_FVF_BUILDER_TEMPLATES(make##CBTYPE,CBTYPE,RESULT,F1,F2, \
506  CBTYPE::SigP1::FuncType, \
507  CBTYPE::SigP0F12::FuncType, \
508  CBTYPE::SigP0F2::FuncType)
509 
510 #else
511 #error cbtypes.h included twice
512 #endif // CBTYPES_H
#define arb_assert(cond)
Definition: arb_assert.h:245
AW_CL callee() const
Definition: cbtypes.h:182
bool operator==(const Callback_FVV &other) const
Definition: cbtypes.h:202
bool operator<(const Callback_FFV &other) const
Definition: cbtypes.h:229
StrictlyTypedCallback< RT, FIXED, AW_CL, AW_CL > Signature
Definition: cbtypes.h:189
RT operator()(FIXED fixed) const
Definition: cbtypes.h:199
RT operator()(FP1 p1, FP2 p2, FP3 p3) const
Definition: cbtypes.h:120
static constexpr bool value
Definition: cbtypes.h:291
Callback_FVF(SigP0F12 CB)
Definition: cbtypes.h:251
RT operator()(F1 f1, F2 f2) const
Definition: cbtypes.h:259
StrictlyTypedCallback(FuncType CB)
Definition: cbtypes.h:118
RT ResultType
Definition: cbtypes.h:38
T const ConstT
Definition: ttypes.h:220
StrictlyTypedCallback< RT, F1, F2, AW_CL > Signature
Definition: cbtypes.h:213
CallbackDataDeallocator dealloc
Definition: cbtypes.h:145
T const & RefConstT
Definition: ttypes.h:223
Callback_FVF(SigP1 CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1)
Definition: cbtypes.h:254
AW_CL inspect_CD1() const
Definition: cbtypes.h:183
StrictlyTypedCallback< RT, F2, void, void > SigP0F2
Definition: cbtypes.h:239
bool operator<(const Callback_FVV &other) const
Definition: cbtypes.h:201
#define CASTSIG(sig, cb)
Definition: arbtools.h:123
bool operator<(const Callback_FVF &other) const
Definition: cbtypes.h:267
AW_CL inspect_CD1() const
Definition: cbtypes.h:207
bool same_function_as(const Callback_FVF &other) const
Definition: cbtypes.h:270
CallbackData(P1 p1_, P2 p2_)
Definition: cbtypes.h:147
StrictlyTypedCallback< RT, AW_CL, AW_CL, AW_CL > Signature
Definition: cbtypes.h:165
Callback_FVV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2)
Definition: cbtypes.h:197
AW_CL inspect_CD2() const
Definition: cbtypes.h:274
StrictlyTypedCallback< RT, F1, AW_CL, F2 > SigP1
Definition: cbtypes.h:237
bool operator<(const StrictlyTypedCallback &other) const
Definition: cbtypes.h:132
AW_CL callee() const
Definition: cbtypes.h:206
RT operator()(F1 f1, F2 f2) const
Definition: cbtypes.h:227
T ArgT
Definition: ttypes.h:218
Function< RT, P1, P2, P3 >::Type FuncType
Definition: cbtypes.h:106
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:121
CallbackData(P1 p1_, P2 p2_, CallbackDataDeallocator dealloc_)
Definition: cbtypes.h:148
bool operator==(const Callback_FFV &other) const
Definition: cbtypes.h:230
bool operator<(const CallbackData &other) const
Definition: cbtypes.h:150
bool same_function_as(const Callback_FVV &other) const
Definition: cbtypes.h:204
RT operator()(FP1 p1) const
Definition: cbtypes.h:122
#define INVALID_CB_PARAM_TYPE(TYPE)
Definition: cbtypes.h:92
CallbackData< AW_CL, AW_CL > UntypedCallbackData
Definition: cbtypes.h:158
bool operator==(const Callback_VV &other) const
Definition: cbtypes.h:178
bool operator<(const Callback_VV &other) const
Definition: cbtypes.h:177
AW_CL callee() const
Definition: cbtypes.h:272
bool equals(const StrictlyTypedCallback &other) const
Definition: cbtypes.h:125
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:144
bool operator==(const Callback_FVF &other) const
Definition: cbtypes.h:268
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:180
StrictlyTypedCallback< RT, F1, F2, void > SigP0F12
Definition: cbtypes.h:238
long AW_CL
Definition: cb.h:21
Callback_FVF(SigP1 CB, AW_CL P1)
Definition: cbtypes.h:253
Callback_FVV(Signature CB, AW_CL P1, AW_CL P2)
Definition: cbtypes.h:196
AW_CL get_cb() const
Definition: cbtypes.h:127
Callback_VV(Signature CB, AW_CL P1, AW_CL P2)
Definition: cbtypes.h:172
bool same_function_as(const Callback_FFV &other) const
Definition: cbtypes.h:232
Callback_VV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2)
Definition: cbtypes.h:173
#define NULp
Definition: cxxforward.h:116
AW_CL inspect_CD1() const
Definition: cbtypes.h:273
RT operator()() const
Definition: cbtypes.h:123
Callback_FFV(Signature CB, AW_CL P)
Definition: cbtypes.h:222
Definition: trnsprob.h:20
AW_CL inspect_CD2() const
Definition: cbtypes.h:184
static StrictlyTypedCallback make_cb(AW_CL cb_)
Definition: cbtypes.h:128
TypeOp< T >::ConstT * Type
Definition: cbtypes.h:83
bool operator==(const StrictlyTypedCallback &other) const
Definition: cbtypes.h:133
~CallbackData()
Definition: cbtypes.h:149
AW_CL inspect_CD2() const
Definition: cbtypes.h:208
bool operator==(const CallbackData &other) const
Definition: cbtypes.h:153
static Params P
Definition: arb_probe.cxx:81
Callback_FVF(SigP0F2 CB)
Definition: cbtypes.h:252
RT operator()() const
Definition: cbtypes.h:175
bool is_set() const
Definition: cbtypes.h:130