wahyu-GTA-Online-OUTDATED-B.../subVersion/CallbackProxy.h
gabrielkheisa 8e431a3e95 upload
2020-11-06 18:55:46 +07:00

38 lines
873 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#ifndef __CALLBACK_PROXY_H__
#define __CALLBACK_PROXY_H__
//Tobject:调用对象的类型Tparam回调函数参数的类型
template<typename Tobject, typename Tparam>
class CallbackProxy
{
typedef void (Tobject::* CbFun)(Tparam*);
public:
void Set(Tobject* pInstance, CbFun pFun);
bool Exec(Tparam* pParam);
private:
CbFun pCbFun; //回调函数指针
Tobject* m_pInstance; //调用对象
};
//设置调用对象及其回调函数
template<typename Tobject, typename Tparam>
void CallbackProxy<Tobject, Tparam>::Set(Tobject* pInstance, CbFun pFun)
{
m_pInstance = pInstance;
pCbFun = pFun;
};
//调用回调函数
template<typename Tobject, typename Tparam>
bool CallbackProxy<Tobject, Tparam>::Exec(Tparam* pParam)
{
(m_pInstance->*pCbFun)(pParam);
return true;
}
extern std::map<int, CallbackProxy<hack, float>*>* g_pCBMap;
#endif