callback.h
来自「The goal of this library is to make ODBC」· C头文件 代码 · 共 1,435 行 · 第 1/4 页
H
1,435 行
return CBMemberOf1stArgTranslator1wRet<P1,RT,MemFunc>(f);
}
#endif
template <class P1,class RT,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1wRet<P1,RT,TRT (CallType::*)()const>
makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (CallType::* RHCB_CONST_REF f)()const)
{
typedef TRT (CallType::*MemFunc)()const;
return CBMemberOf1stArgTranslator1wRet<P1,RT,MemFunc>(f);
}
/************************* two args - no return *******************/
template <class P1,class P2>
class CBFunctor2:public CBFunctorBase{
public:
CBFunctor2(RHCB_DUMMY_INIT = 0){}
void operator()(P1 p1,P2 p2)const
{
thunk(*this,p1,p2);
}
virtual CBFunctorBase *clone() const // added by MG
{
return new CBFunctor2<P1, P2>(*this);
}
//for STL
typedef P1 first_argument_type;
typedef P2 second_argument_type;
typedef void result_type;
protected:
typedef void (*Thunk)(const CBFunctorBase &,P1,P2);
CBFunctor2(Thunk t,const void *c,PFunc f,const void *mf,size_t sz):
CBFunctorBase(c,f,mf,sz),thunk(t){}
private:
Thunk thunk;
};
template <class P1,class P2,class Callee, class MemFunc>
class CBMemberTranslator2:public CBFunctor2<P1,P2>{
public:
CBMemberTranslator2(Callee &c,const MemFunc &m):
CBFunctor2<P1,P2>(thunk,&c,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(callee->*memFunc)(p1,p2);
}
};
template <class P1,class P2,class Func>
class CBFunctionTranslator2:public CBFunctor2<P1,P2>{
public:
CBFunctionTranslator2(Func f):CBFunctor2<P1,P2>(thunk,0,(PFunc)f,0,0){}
static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
{
(Func(ftor.getFunc()))(p1,p2);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class P2,class Callee,
class TRT,class CallType,class TP1,class TP2>
inline CBMemberTranslator2<P1,P2,Callee,TRT (CallType::*)(TP1,TP2)>
makeFunctor(CBFunctor2<P1,P2>*,Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2))
{
typedef TRT (CallType::*MemFunc)(TP1,TP2);
return CBMemberTranslator2<P1,P2,Callee,MemFunc>(c,f);
}
#endif
template <class P1,class P2,class Callee,
class TRT,class CallType,class TP1,class TP2>
inline CBMemberTranslator2<P1,P2,const Callee,
TRT (CallType::*)(TP1,TP2)const>
makeFunctor(CBFunctor2<P1,P2>*,const Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2)const)
{
typedef TRT (CallType::*MemFunc)(TP1,TP2)const;
return CBMemberTranslator2<P1,P2,const Callee,MemFunc>(c,f);
}
template <class P1,class P2,class TRT,class TP1,class TP2>
inline CBFunctionTranslator2<P1,P2,TRT (*)(TP1,TP2)>
makeFunctor(CBFunctor2<P1,P2>*,TRT (*f)(TP1,TP2))
{
return CBFunctionTranslator2<P1,P2,TRT (*)(TP1,TP2)>(f);
}
template <class P1,class P2,class MemFunc>
class CBMemberOf1stArgTranslator2:public CBFunctor2<P1,P2>{
public:
CBMemberOf1stArgTranslator2(const MemFunc &m):
CBFunctor2<P1,P2>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
{
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(p1.*memFunc)(p2);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class P2,class TRT,class CallType,class TP1>
inline CBMemberOf1stArgTranslator2<P1,P2,TRT (CallType::*)(TP1)>
makeFunctor(CBFunctor2<P1,P2>*,TRT (CallType::* RHCB_CONST_REF f)(TP1))
{
typedef TRT (CallType::*MemFunc)(TP1);
return CBMemberOf1stArgTranslator2<P1,P2,MemFunc>(f);
}
#endif
template <class P1,class P2,class TRT,class CallType,class TP1>
inline CBMemberOf1stArgTranslator2<P1,P2,TRT (CallType::*)(TP1)const>
makeFunctor(CBFunctor2<P1,P2>*,TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
{
typedef TRT (CallType::*MemFunc)(TP1)const;
return CBMemberOf1stArgTranslator2<P1,P2,MemFunc>(f);
}
/************************* two args - with return *******************/
template <class P1,class P2,class RT>
class CBFunctor2wRet:public CBFunctorBase{
public:
CBFunctor2wRet(RHCB_DUMMY_INIT = 0){}
RT operator()(P1 p1,P2 p2)const
{
return RHCB_BC4_RET_BUG(thunk(*this,p1,p2));
}
virtual CBFunctorBase *clone() const // added by MG
{
return new CBFunctor2wRet<P1, P2, RT>(*this);
}
//for STL
typedef P1 first_argument_type;
typedef P2 second_argument_type;
typedef RT result_type;
protected:
typedef RT (*Thunk)(const CBFunctorBase &,P1,P2);
CBFunctor2wRet(Thunk t,const void *c,PFunc f,const void *mf,size_t sz):
CBFunctorBase(c,f,mf,sz),thunk(t){}
private:
Thunk thunk;
};
template <class P1,class P2,class RT,class Callee, class MemFunc>
class CBMemberTranslator2wRet:public CBFunctor2wRet<P1,P2,RT>{
public:
CBMemberTranslator2wRet(Callee &c,const MemFunc &m):
CBFunctor2wRet<P1,P2,RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
return RHCB_BC4_RET_BUG((callee->*memFunc)(p1,p2));
}
};
template <class P1,class P2,class RT,class Func>
class CBFunctionTranslator2wRet:public CBFunctor2wRet<P1,P2,RT>{
public:
CBFunctionTranslator2wRet(Func f):
CBFunctor2wRet<P1,P2,RT>(thunk,0,(PFunc)f,0,0){}
static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
{
return (Func(ftor.getFunc()))(p1,p2);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class P2,class RT,class Callee,
class TRT,class CallType,class TP1,class TP2>
inline CBMemberTranslator2wRet<P1,P2,RT,Callee,
TRT (CallType::*)(TP1,TP2)>
makeFunctor(CBFunctor2wRet<P1,P2,RT>*,Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2))
{
typedef TRT (CallType::*MemFunc)(TP1,TP2);
return CBMemberTranslator2wRet<P1,P2,RT,Callee,MemFunc>(c,f);
}
#endif
template <class P1,class P2,class RT,class Callee,
class TRT,class CallType,class TP1,class TP2>
inline CBMemberTranslator2wRet<P1,P2,RT,const Callee,
TRT (CallType::*)(TP1,TP2)const>
makeFunctor(CBFunctor2wRet<P1,P2,RT>*,const Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2)const)
{
typedef TRT (CallType::*MemFunc)(TP1,TP2)const;
return CBMemberTranslator2wRet<P1,P2,RT,const Callee,MemFunc>(c,f);
}
template <class P1,class P2,class RT,class TRT,class TP1,class TP2>
inline CBFunctionTranslator2wRet<P1,P2,RT,TRT (*)(TP1,TP2)>
makeFunctor(CBFunctor2wRet<P1,P2,RT>*,TRT (*f)(TP1,TP2))
{
return CBFunctionTranslator2wRet<P1,P2,RT,TRT (*)(TP1,TP2)>(f);
}
template <class P1,class P2,class RT,class MemFunc>
class CBMemberOf1stArgTranslator2wRet:public CBFunctor2wRet<P1,P2,RT>{
public:
CBMemberOf1stArgTranslator2wRet(const MemFunc &m):
CBFunctor2wRet<P1,P2,RT>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
static RT thunk(const CBFunctorBase &ftor,P1 p1,P2 p2)
{
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
return RHCB_BC4_RET_BUG((p1.*memFunc)(p2));
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class P2,class RT,class TRT,class CallType,class TP1>
inline CBMemberOf1stArgTranslator2wRet<P1,P2,RT,TRT (CallType::*)(TP1)>
makeFunctor(CBFunctor2wRet<P1,P2,RT>*,TRT (CallType::* RHCB_CONST_REF f)(TP1))
{
typedef TRT (CallType::*MemFunc)(TP1);
return CBMemberOf1stArgTranslator2wRet<P1,P2,RT,MemFunc>(f);
}
#endif
template <class P1,class P2,class RT,class TRT,class CallType,class TP1>
inline CBMemberOf1stArgTranslator2wRet<P1,P2,RT,TRT (CallType::*)(TP1)const>
makeFunctor(CBFunctor2wRet<P1,P2,RT>*,
TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
{
typedef TRT (CallType::*MemFunc)(TP1)const;
return CBMemberOf1stArgTranslator2wRet<P1,P2,RT,MemFunc>(f);
}
/************************* three args - no return *******************/
template <class P1,class P2,class P3>
class CBFunctor3:public CBFunctorBase{
public:
CBFunctor3(RHCB_DUMMY_INIT = 0){}
void operator()(P1 p1,P2 p2,P3 p3)const
{
thunk(*this,p1,p2,p3);
}
virtual CBFunctorBase *clone() const // added by MG
{
return new CBFunctor3<P1, P2, P3>(*this);
}
protected:
typedef void (*Thunk)(const CBFunctorBase &,P1,P2,P3);
CBFunctor3(Thunk t,const void *c,PFunc f,const void *mf,size_t sz):
CBFunctorBase(c,f,mf,sz),thunk(t){}
private:
Thunk thunk;
};
template <class P1,class P2,class P3,class Callee, class MemFunc>
class CBMemberTranslator3:public CBFunctor3<P1,P2,P3>{
public:
CBMemberTranslator3(Callee &c,const MemFunc &m):
CBFunctor3<P1,P2,P3>(thunk,&c,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(callee->*memFunc)(p1,p2,p3);
}
};
template <class P1,class P2,class P3,class Func>
class CBFunctionTranslator3:public CBFunctor3<P1,P2,P3>{
public:
CBFunctionTranslator3(Func f):CBFunctor3<P1,P2,P3>(thunk,0,(PFunc)f,0,0){}
static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
{
(Func(ftor.getFunc()))(p1,p2,p3);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class P2,class P3,class Callee,
class TRT,class CallType,class TP1,class TP2,class TP3>
inline CBMemberTranslator3<P1,P2,P3,Callee,
TRT (CallType::*)(TP1,TP2,TP3)>
makeFunctor(CBFunctor3<P1,P2,P3>*,Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3))
{
typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3);
return CBMemberTranslator3<P1,P2,P3,Callee,MemFunc>(c,f);
}
#endif
template <class P1,class P2,class P3,class Callee,
class TRT,class CallType,class TP1,class TP2,class TP3>
inline CBMemberTranslator3<P1,P2,P3,const Callee,
TRT (CallType::*)(TP1,TP2,TP3)const>
makeFunctor(CBFunctor3<P1,P2,P3>*,const Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2,TP3)const)
{
typedef TRT (CallType::*MemFunc)(TP1,TP2,TP3)const;
return CBMemberTranslator3<P1,P2,P3,const Callee,MemFunc>(c,f);
}
template <class P1,class P2,class P3,
class TRT,class TP1,class TP2,class TP3>
inline CBFunctionTranslator3<P1,P2,P3,TRT (*)(TP1,TP2,TP3)>
makeFunctor(CBFunctor3<P1,P2,P3>*,TRT (*f)(TP1,TP2,TP3))
{
return CBFunctionTranslator3<P1,P2,P3,TRT (*)(TP1,TP2,TP3)>(f);
}
template <class P1,class P2,class P3,class MemFunc>
class CBMemberOf1stArgTranslator3:public CBFunctor3<P1,P2,P3>{
public:
CBMemberOf1stArgTranslator3(const MemFunc &m):
CBFunctor3<P1,P2,P3>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1,P2 p2,P3 p3)
{
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(p1.*memFunc)(p2,p3);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class P2,class P3,class TRT,class CallType,
class TP1,class TP2>
inline CBMemberOf1stArgTranslator3<P1,P2,P3,TRT (CallType::*)(TP1,TP2)>
makeFunctor(CBFunctor3<P1,P2,P3>*,TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2))
{
typedef TRT (CallType::*MemFunc)(TP1,TP2);
return CBMemberOf1stArgTranslator3<P1,P2,P3,MemFunc>(f);
}
#endif
template <class P1,class P2,class P3,class TRT,class CallType,
class TP1,class TP2>
inline CBMemberOf1stArgTranslator3<P1,P2,P3,TRT (CallType::*)(TP1,TP2)const>
makeFunctor(CBFunctor3<P1,P2,P3>*,
TRT (CallType::* RHCB_CONST_REF f)(TP1,TP2)const)
{
typedef TRT (CallType::*MemFunc)(TP1,TP2)const;
return CBMemberOf1stArgTranslator3<P1,P2,P3,MemFunc>(f);
}
/************************* three args - with return *******************/
template <class P1,class P2,class P3,class RT>
class CBFunctor3wRet:public CBFunctorBase{
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?