1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65
|
template <typename FT,typename PT0=char,typename PT1=char,typename PT2=char,typename PT3=char,typename PT4=char>
struct binder{
FT f;
PT0 pt0;
PT1 pt1;
PT2 pt2;
PT3 pt3;
PT4 pt4;
int p;
bool free_after_first_use;
typedef void(*Call_1)(PT0);
typedef void(*Call_2)(PT0,PT1);
typedef void(*Call_3)(PT0,PT1,PT2);
typedef void(*Call_4)(PT0,PT1,PT2,PT3);
typedef void(*Call_5)(PT0,PT1,PT2,PT3,PT4);
binder():f(0),p(0),free_after_first_use(1){}
binder(FT f,const PT0 &pt0):f(f),pt0(pt0),p(1),free_after_first_use(1){}
binder(FT f,const PT0 &pt0,const PT1 &pt1):f(f),pt0(pt0),pt1(pt1),p(2),free_after_first_use(1){}
binder(FT f,const PT0 &pt0,const PT1 &pt1,const PT2 &pt2):f(f),pt0(pt0),pt1(pt1),pt2(pt2),p(3),free_after_first_use(1){}
binder(FT f,const PT0 &pt0,const PT1 &pt1,const PT2 &pt2,const PT3 &pt3):f(f),pt0(pt0),pt1(pt1),pt2(pt2),pt3(pt3),p(4),free_after_first_use(1){}
binder(FT f,const PT0 &pt0,const PT1 &pt1,const PT2 &pt2,const PT3 &pt3,const PT4 &pt4):f(f),pt0(pt0),pt1(pt1),pt2(pt2),pt3(pt3),pt4(pt4),p(5),free_after_first_use(1){}
void call(){
if (p<3){
if (p<2){
((Call_1)f)(pt0);
}else{
((Call_2)f)(pt0,pt1);
}
}else if (p>3){
if (p<5){
((Call_4)f)(pt0,pt1,pt2,pt3);
}else{
((Call_5)f)(pt0,pt1,pt2,pt3,pt4);
}
}else{
((Call_3)f)(pt0,pt1,pt2);
}
}
};
template <typename FT,typename PT0>
inline binder<FT,PT0> *bind(FT f,const PT0 &pt0){
return new binder<FT,PT0>(f,pt0);
}
template <typename FT,typename PT0,typename PT1>
inline binder<FT,PT0,PT1> *bind(FT f,const PT0 &pt0,const PT1 &pt1){
return new binder<FT,PT0,PT1>(f,pt0,pt1);
}
template <typename FT,typename PT0,typename PT1,typename PT2>
inline binder<FT,PT0,PT1,PT2> *bind(FT f,const PT0 &pt0,const PT1 &pt1,const PT2 &pt2){
return new binder<FT,PT0,PT1,PT2>(f,pt0,pt1,pt2);
}
template <typename FT,typename PT0,typename PT1,typename PT2,typename PT3>
inline binder<FT,PT0,PT1,PT2,PT3> *bind(FT f,const PT0 &pt0,const PT1 &pt1,const PT2 &pt2,const PT3 &pt3){
return new binder<FT,PT0,PT1,PT2,PT3>(f,pt0,pt1,pt2,pt3);
}
template <typename FT,typename PT0,typename PT1,typename PT2,typename PT3,typename PT4>
inline binder<FT,PT0,PT1,PT2,PT3,PT4> *bind(FT f,const PT0 &pt0,const PT1 &pt1,const PT2 &pt2,const PT3 &pt3,const PT4 &pt4){
return new binder<FT,PT0,PT1,PT2,PT3,PT4>(f,pt0,pt1,pt2,pt3,pt4);
}
#define BINDER_TYPEDEF_1(name,arg1) typedef binder<void(*)(arg1),arg1> name
#define BINDER_TYPEDEF_2(name,arg1,arg2) typedef binder<void(*)(arg1,arg2),arg1,arg2> name
#define BINDER_TYPEDEF_3(name,arg1,arg2,arg3) typedef binder<void(*)(arg1,arg2,arg3),arg1,arg2,arg3> name
#define BINDER_TYPEDEF_4(name,arg1,arg2,arg3,arg4) typedef binder<void(*)(arg1,arg2,arg3,arg4),arg1,arg2,arg3,arg4> name
#define BINDER_TYPEDEF_5(name,arg1,arg2,arg3,arg4,arg5) typedef binder<void(*)(arg1,arg2,arg3,arg4,arg5),arg1,arg2,arg3,arg4,arg5> name
|