typedef TRet (TObj::*PMethod)(PARAMS);
C_METHOD_DELEGATE(TObj* pObj, PMethod pMethod) {
m_pObj = pObj;
m_pMethod = pMethod;
}
virtual TRet Invoke(PARAMS) { return (m_pObj-›*m_pMethod)(ARGS); }
virtual bool Compare(I_DELEGATE‹TRet TEMPLATE_ARGS›* pDelegate) {
C_METHOD_DELEGATE‹TObj, TRet TEMPLATE_ARGS›* pMethodDel = dynamic_cast‹C_METHOD_DELEGATE‹TObj, TRet TEMPLATE_ARGS›*›(pDelegate);
if (pMethodDel == NULL || pMethodDel-›m_pObj != m_pObj || pMethodDel-›m_pMethod != m_pMethod) { return false; }
return true;
}
private:
TObj *m_pObj;
PMethod m_pMethod;
};
template‹class TRet TEMPLATE_PARAMS›
I_DELEGATE‹TRet TEMPLATE_ARGS›* NewDelegate(TRet (*pFunc)(PARAMS)) {
return new C_STATIC_DELEGATE‹TRet TEMPLATE_ARGS›(pFunc);
}
template ‹class TObj, class TRet TEMPLATE_PARAMS›
I_DELEGATE‹TRet TEMPLATE_ARGS›* NewDelegate(TObj* pObj, TRet (TObj::*pMethod)(PARAMS)) {
return new C_METHOD_DELEGATE‹TObj, TRet TEMPLATE_ARGS› (pObj, pMethod);
}
template‹class TRet TEMPLATE_PARAMS›
class C_DELEGATE {
public:
typedef I_DELEGATE‹TRet TEMPLATE_ARGS› IDelegate;
typedef std::list‹IDelegate*› DelegateList;
C_DELEGATE(IDelegate* pDelegate = NULL) { Add(pDelegate); }
~C_DELEGATE() { RemoveAll(); }