📄 callback.h
字号:
{
func = f;
}
}
};
/************************* no arg - no return *******************/
class CBFunctor0:public CBFunctorBase{
public:
CBFunctor0(RHCB_DUMMY_INIT = 0){}
void operator()()const
{
thunk(*this);
}
virtual CBFunctorBase *clone() const // added by MG
{
return new CBFunctor0(*this);
}
protected:
typedef void (*Thunk)(const CBFunctorBase &);
CBFunctor0(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 Callee, class MemFunc>
class CBMemberTranslator0:public CBFunctor0{
public:
CBMemberTranslator0(Callee &c,const MemFunc &m):
CBFunctor0(thunk,&c,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(callee->*memFunc)();
}
};
template <class Func>
class CBFunctionTranslator0:public CBFunctor0{
public:
CBFunctionTranslator0(Func f):CBFunctor0(thunk,0,(PFunc)f,0,0){}
static void thunk(const CBFunctorBase &ftor)
{
(Func(ftor.getFunc()))();
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class Callee,class TRT,class CallType>
inline CBMemberTranslator0<Callee,TRT (CallType::*)()>
makeFunctor(CBFunctor0 *,Callee &c,TRT (CallType::* RHCB_CONST_REF f)())
{
typedef TRT (CallType::*MemFunc)();
return CBMemberTranslator0<Callee,MemFunc>(c,f);
}
#endif
template <class Callee,class TRT,class CallType>
inline CBMemberTranslator0<const Callee,TRT (CallType::*)()const>
makeFunctor(CBFunctor0 *,const Callee &c,
TRT (CallType::* RHCB_CONST_REF f)()const)
{
typedef TRT (CallType::*MemFunc)()const;
return CBMemberTranslator0<const Callee,MemFunc>(c,f);
}
template <class TRT>
inline CBFunctionTranslator0<TRT (*)()>
makeFunctor(CBFunctor0 *,TRT (*f)())
{
return CBFunctionTranslator0<TRT (*)()>(f);
}
/************************* no arg - with return *******************/
template <class RT>
class CBFunctor0wRet:public CBFunctorBase{
public:
CBFunctor0wRet(RHCB_DUMMY_INIT = 0){}
RT operator()()const
{
return RHCB_BC4_RET_BUG(thunk(*this));
}
virtual CBFunctorBase *clone() const // added by MG
{
return new CBFunctor0wRet<RT>(*this);
}
protected:
typedef RT (*Thunk)(const CBFunctorBase &);
CBFunctor0wRet(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 RT,class Callee, class MemFunc>
class CBMemberTranslator0wRet:public CBFunctor0wRet<RT>{
public:
CBMemberTranslator0wRet(Callee &c,const MemFunc &m):
CBFunctor0wRet<RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
static RT thunk(const CBFunctorBase &ftor)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
return RHCB_BC4_RET_BUG((callee->*memFunc)());
}
};
template <class RT,class Func>
class CBFunctionTranslator0wRet:public CBFunctor0wRet<RT>{
public:
CBFunctionTranslator0wRet(Func f):CBFunctor0wRet<RT>(thunk,0,(PFunc)f,0,0){}
static RT thunk(const CBFunctorBase &ftor)
{
return (Func(ftor.getFunc()))();
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class RT,class Callee,class TRT,class CallType>
inline CBMemberTranslator0wRet<RT,Callee,TRT (CallType::*)()>
makeFunctor(CBFunctor0wRet<RT>*,Callee &c,TRT (CallType::* RHCB_CONST_REF f)())
{
typedef TRT (CallType::*MemFunc)();
return CBMemberTranslator0wRet<RT,Callee,MemFunc>(c,f);
}
#endif
template <class RT,class Callee,class TRT,class CallType>
inline CBMemberTranslator0wRet<RT,const Callee,TRT (CallType::*)()const>
makeFunctor(CBFunctor0wRet<RT>*,const Callee &c,
TRT (CallType::* RHCB_CONST_REF f)()const)
{
typedef TRT (CallType::*MemFunc)()const;
return CBMemberTranslator0wRet<RT,const Callee,MemFunc>(c,f);
}
template <class RT,class TRT>
inline CBFunctionTranslator0wRet<RT,TRT (*)()>
makeFunctor(CBFunctor0wRet<RT>*,TRT (*f)())
{
return CBFunctionTranslator0wRet<RT,TRT (*)()>(f);
}
/************************* one arg - no return *******************/
template <class P1>
class CBFunctor1:public CBFunctorBase{
public:
CBFunctor1(RHCB_DUMMY_INIT = 0){}
void operator()(P1 p1)const
{
thunk(*this,p1);
}
virtual CBFunctorBase *clone() const // added by MG
{
return new CBFunctor1<P1>(*this);
}
//for STL
typedef P1 argument_type;
typedef void result_type;
protected:
typedef void (*Thunk)(const CBFunctorBase &,P1);
CBFunctor1(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 Callee, class MemFunc>
class CBMemberTranslator1:public CBFunctor1<P1>{
public:
CBMemberTranslator1(Callee &c,const MemFunc &m):
CBFunctor1<P1>(thunk,&c,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(callee->*memFunc)(p1);
}
};
template <class P1,class Func>
class CBFunctionTranslator1:public CBFunctor1<P1>{
public:
CBFunctionTranslator1(Func f):CBFunctor1<P1>(thunk,0,(PFunc)f,0,0){}
static void thunk(const CBFunctorBase &ftor,P1 p1)
{
(Func(ftor.getFunc()))(p1);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1<P1,Callee,TRT (CallType::*)(TP1)>
makeFunctor(CBFunctor1<P1>*,Callee &c,TRT (CallType::* RHCB_CONST_REF f)(TP1))
{
typedef TRT (CallType::*MemFunc)(TP1);
return CBMemberTranslator1<P1,Callee,MemFunc>(c,f);
}
#endif
template <class P1,class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1<P1,const Callee,TRT (CallType::*)(TP1)const>
makeFunctor(CBFunctor1<P1>*,const Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
{
typedef TRT (CallType::*MemFunc)(TP1)const;
return CBMemberTranslator1<P1,const Callee,MemFunc>(c,f);
}
template <class P1,class TRT,class TP1>
inline CBFunctionTranslator1<P1,TRT (*)(TP1)>
makeFunctor(CBFunctor1<P1>*,TRT (*f)(TP1))
{
return CBFunctionTranslator1<P1,TRT (*)(TP1)>(f);
}
template <class P1,class MemFunc>
class CBMemberOf1stArgTranslator1:public CBFunctor1<P1>{
public:
CBMemberOf1stArgTranslator1(const MemFunc &m):
CBFunctor1<P1>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
static void thunk(const CBFunctorBase &ftor,P1 p1)
{
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
(p1.*memFunc)();
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1<P1,TRT (CallType::*)()>
makeFunctor(CBFunctor1<P1>*,TRT (CallType::* RHCB_CONST_REF f)())
{
typedef TRT (CallType::*MemFunc)();
return CBMemberOf1stArgTranslator1<P1,MemFunc>(f);
}
#endif
template <class P1,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1<P1,TRT (CallType::*)()const>
makeFunctor(CBFunctor1<P1>*,TRT (CallType::* RHCB_CONST_REF f)()const)
{
typedef TRT (CallType::*MemFunc)()const;
return CBMemberOf1stArgTranslator1<P1,MemFunc>(f);
}
/************************* one arg - with return *******************/
template <class P1,class RT>
class CBFunctor1wRet:public CBFunctorBase{
public:
CBFunctor1wRet(RHCB_DUMMY_INIT = 0){}
RT operator()(P1 p1)const
{
return RHCB_BC4_RET_BUG(thunk(*this,p1));
}
virtual CBFunctorBase *clone() const // added by MG
{
return new CBFunctor1wRet<P1, RT>(*this);
}
//for STL
typedef P1 argument_type;
typedef RT result_type;
protected:
typedef RT (*Thunk)(const CBFunctorBase &,P1);
CBFunctor1wRet(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 RT,class Callee, class MemFunc>
class CBMemberTranslator1wRet:public CBFunctor1wRet<P1,RT>{
public:
CBMemberTranslator1wRet(Callee &c,const MemFunc &m):
CBFunctor1wRet<P1,RT>(thunk,&c,0,&m,sizeof(MemFunc)){}
static RT thunk(const CBFunctorBase &ftor,P1 p1)
{
Callee *callee = (Callee *)ftor.getCallee();
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
return RHCB_BC4_RET_BUG((callee->*memFunc)(p1));
}
};
template <class P1,class RT,class Func>
class CBFunctionTranslator1wRet:public CBFunctor1wRet<P1,RT>{
public:
CBFunctionTranslator1wRet(Func f):
CBFunctor1wRet<P1,RT>(thunk,0,(PFunc)f,0,0){}
static RT thunk(const CBFunctorBase &ftor,P1 p1)
{
return (Func(ftor.getFunc()))(p1);
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class RT,
class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1wRet<P1,RT,Callee,TRT (CallType::*)(TP1)>
makeFunctor(CBFunctor1wRet<P1,RT>*,Callee &c,
TRT (CallType::* RHCB_CONST_REF f)(TP1))
{
typedef TRT (CallType::*MemFunc)(TP1);
return CBMemberTranslator1wRet<P1,RT,Callee,MemFunc>(c,f);
}
#endif
template <class P1,class RT,
class Callee,class TRT,class CallType,class TP1>
inline CBMemberTranslator1wRet<P1,RT,
const Callee,TRT (CallType::*)(TP1)const>
makeFunctor(CBFunctor1wRet<P1,RT>*,
const Callee &c,TRT (CallType::* RHCB_CONST_REF f)(TP1)const)
{
typedef TRT (CallType::*MemFunc)(TP1)const;
return CBMemberTranslator1wRet<P1,RT,const Callee,MemFunc>(c,f);
}
template <class P1,class RT,class TRT,class TP1>
inline CBFunctionTranslator1wRet<P1,RT,TRT (*)(TP1)>
makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (*f)(TP1))
{
return CBFunctionTranslator1wRet<P1,RT,TRT (*)(TP1)>(f);
}
template <class P1,class RT,class MemFunc>
class CBMemberOf1stArgTranslator1wRet:public CBFunctor1wRet<P1,RT>{
public:
CBMemberOf1stArgTranslator1wRet(const MemFunc &m):
CBFunctor1wRet<P1,RT>(thunk,(void *)1,0,&m,sizeof(MemFunc)){}
static RT thunk(const CBFunctorBase &ftor,P1 p1)
{
MemFunc &memFunc RHCB_CTOR_STYLE_INIT
(*(MemFunc*)(void *)(ftor.getMemFunc()));
return RHCB_BC4_RET_BUG((p1.*memFunc)());
}
};
#if !defined(RHCB_CANT_OVERLOAD_ON_CONSTNESS)
template <class P1,class RT,class TRT,class CallType>
inline CBMemberOf1stArgTranslator1wRet<P1,RT,TRT (CallType::*)()>
makeFunctor(CBFunctor1wRet<P1,RT>*,TRT (CallType::* RHCB_CONST_REF f)())
{
typedef TRT (CallType::*MemFunc)();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -