1,定义函数指针
typedef void (CAppProtocol::*PParse)(const tagClientInfo &clientinfo);
typedef void (CAppProtocol::*PResult)(int result, std::vector<tagProperty> TaskProperty);
2,定义map变量
std::map<CString, PParse> _mapParseProtocol;
std::map<int, PResult> _mapTaskResult;
3,添加具体处理函数
void CAppProtocol::CR_PhoneLogin(int result, std::vector<tagProperty> TaskProperty)
{
......
}
void CAppProtocol::CR_PhoneLogout(int result, std::vector<tagProperty> TaskProperty)
{
........
}
4,为map变量赋值
_mapParseProtocol.insert(std::pair<CString,PParse>(Pr_PhoneLogin, &CAppProtocol::CC_PhoneLogin));
_mapParseProtocol.insert(std::pair<CString,PParse>(Pr_PhoneLogout, &CAppProtocol::CC_PhoneLogout));
5,定义解析函数,只需要传递命令名称和函数参数
void CAppProtocol::ExeParse(CString command, const tagClientInfo &clientinfo)
{
if (_mapParseProtocol.find(command) != _mapParseProtocol.end())
{
PParse pFunc = _mapParseProtocol[command];
return (this->*pFunc)(nodeContent, clientinfo);
}
}
void CAppProtocol::TaskResult(int taskName, int result, std::vector<tagProperty> TaskProperty)
{
if (_mapTaskResult.find(taskName) != _mapTaskResult.end())
{
PResult pFunc = _mapTaskResult[taskName];
return (this->*pFunc)(result, TaskProperty);
}
}