21 #ifndef STATIC_ASSERT_H
28 #include <type_traits>
34 template<
typename RT,
typename P1,
typename P2,
typename P3>
37 typedef RT (*
Type)(P1,P2,P3);
40 template<
typename RT,
typename P1,
typename P2>
45 template<
typename RT,
typename P1>
85 template<>
class ConstParamT<void> {
class Unused {};
public:
typedef Unused
Type; };
92 #define INVALID_CB_PARAM_TYPE(TYPE) template<> class AW_CL_castableType<TYPE> { }
98 #undef INVALID_CB_PARAM_TYPE
103 template<
typename RT,
typename P1 =
void,
typename P2 =
void,
typename P3 =
void>
119 RT
operator()(FP1 p1, FP2 p2, FP3 p3)
const {
return cb(p1, p2, p3); }
138 template<
typename P1,
typename P2>
150 return p1<other.
p1 || (p1 == other.
p1 && (p2< other.
p2 || (p2 == other.
p2 && dealloc<other.
dealloc)));
153 return p1 == other.
p1 && p2 == other.
p2 && dealloc == other.
dealloc;
162 template<
typename RT>
186 template<
typename RT,
typename FIXED>
210 template<
typename RT,
typename F1,
typename F2>
223 cd(new FFV_CallbackData(P, 0))
234 template<
typename RT,
typename F1,
typename F2>
241 enum funtype { ST_P0F12, ST_P0F2, ST_P1 };
247 funtype get_funtype()
const {
return cd->
p2; }
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)) {}
255 cd(new FVF_CallbackData(P1, ST_P1,
CASTSIG(typename FVF_CallbackData::CallbackDataDeallocator, dealloc)))
259 funtype ft = get_funtype();
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)
283 #define CONST_PARAM_T(T) typename ConstParamT<T>::Type
285 #define CAST_DEALLOCATOR(dealloc) CASTSIG(UntypedCallbackData::CallbackDataDeallocator,dealloc)
291 typename std::remove_cv<typename ConstParamT<P>::Type>
::type
295 #define CONST_VARIANT_REQUIRED(T) RequiresConstVariant<T>::value
296 #define CONST_VARIANTS_REQUIRED(T1,T2) (CONST_VARIANT_REQUIRED(T1) && CONST_VARIANT_REQUIRED(T2))
305 #define RETURN_TYPE_IF(COND,CB) typename std::enable_if<COND,CB>::type
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); \
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); \
323 #define CBTYPE_VV_BUILDER_P1P2(BUILDER,CB,RESULT,SIG,P1,P2,P1fun,P2fun,MAYBE_CB) \
324 template<typename P1, typename P2> \
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)); \
330 template<typename P1, typename P2> \
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)); \
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));
345 #define CBTYPE_VV_BUILDER_TEMPLATES(BUILDER,CB,RESULT,SIG) \
346 inline CB BUILDER(RESULT (*cb)()) { \
347 return CB(CASTSIG(SIG,cb), 0, 0); \
349 CBTYPE_VV_BUILDER_NP12(BUILDER,CB,RESULT,SIG,P1,P2)
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); \
360 #define CBTYPE_FVV_BUILDER_P1(BUILDER,CB,RESULT,FIXED,SIG,P1,P1fun,MAYBE_CB) \
361 template<typename P1> \
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); \
367 template<typename P1> \
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); \
374 #define CBTYPE_FVV_BUILDER_P1P2(BUILDER,CB,RESULT,FIXED,SIG,P1,P2,P1fun,P2fun,MAYBE_CB) \
375 template<typename P1, typename P2> \
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)); \
381 template<typename P1, typename P2> \
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)); \
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))
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); \
401 CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,FIXED,SIG,P1,P2); \
402 CBTYPE_FVV_BUILDER_NP12(BUILDER,CB,RESULT,UNFIXED,SIG,P1,P2)
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)); \
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)); \
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))
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)); \
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)); \
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)); \
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)); \
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))
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)
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)
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)
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)
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)
495 #error cbtypes.h included twice
bool operator==(const Callback_FVV &other) const
bool operator<(const Callback_FFV &other) const
StrictlyTypedCallback< RT, FIXED, AW_CL, AW_CL > Signature
RT operator()(FIXED fixed) const
RT operator()(FP1 p1, FP2 p2, FP3 p3) const
Callback_FVF(SigP0F12 CB)
RT operator()(F1 f1, F2 f2) const
StrictlyTypedCallback(FuncType CB)
StrictlyTypedCallback< RT, F1, F2, AW_CL > Signature
CallbackDataDeallocator dealloc
Callback_FVF(SigP1 CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1)
AW_CL inspect_CD1() const
StrictlyTypedCallback< RT, F2, void, void > SigP0F2
bool operator<(const Callback_FVV &other) const
bool operator<(const Callback_FVF &other) const
AW_CL inspect_CD1() const
bool same_function_as(const Callback_FVF &other) const
CallbackData(P1 p1_, P2 p2_)
StrictlyTypedCallback< RT, AW_CL, AW_CL, AW_CL > Signature
Callback_FVV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2)
AW_CL inspect_CD2() const
StrictlyTypedCallback< RT, F1, AW_CL, F2 > SigP1
bool operator<(const StrictlyTypedCallback &other) const
RT operator()(F1 f1, F2 f2) const
Function< RT, P1, P2, P3 >::Type FuncType
static AW_CL cast_to_AW_CL(const T &t)
RT operator()(FP1 p1, FP2 p2) const
CallbackData(P1 p1_, P2 p2_, CallbackDataDeallocator dealloc_)
bool operator==(const Callback_FFV &other) const
bool operator<(const CallbackData &other) const
bool same_function_as(const Callback_FVV &other) const
RT operator()(FP1 p1) const
#define INVALID_CB_PARAM_TYPE(TYPE)
CallbackData< AW_CL, AW_CL > UntypedCallbackData
bool operator==(const Callback_VV &other) const
bool operator<(const Callback_VV &other) const
bool equals(const StrictlyTypedCallback &other) const
IfThenElseType< TypeT< T >::IsClassT, typename TypeOp< T >::RefConstT, typename TypeOp< T >::ConstT >::ResultType Type
void(* CallbackDataDeallocator)(P1 p1, P2 p2)
bool operator==(const Callback_FVF &other) const
IfThenElseType< TypeT< T >::IsClassT, typename TypeOp< T >::RefConstT, typename TypeOp< T >::ArgT >::ResultType Type
bool same_function_as(const Callback_VV &other) const
StrictlyTypedCallback< RT, F1, F2, void > SigP0F12
Callback_FVF(SigP1 CB, AW_CL P1)
Callback_FVV(Signature CB, AW_CL P1, AW_CL P2)
Callback_VV(Signature CB, AW_CL P1, AW_CL P2)
bool same_function_as(const Callback_FFV &other) const
Callback_VV(Signature CB, UntypedCallbackData::CallbackDataDeallocator dealloc, AW_CL P1, AW_CL P2)
AW_CL inspect_CD1() const
Callback_FFV(Signature CB, AW_CL P)
AW_CL inspect_CD2() const
static StrictlyTypedCallback make_cb(AW_CL cb_)
TypeOp< T >::ConstT * Type
bool operator==(const StrictlyTypedCallback &other) const
AW_CL inspect_CD2() const
bool operator==(const CallbackData &other) const