实现类头文件
#pragma once
#include <unordered_map>
class DataTranslate;
typedef void(DataTranslate::*DataDealFunc)(DataInteractionBase*)
#ifndef RegisterFunc
#define RegisterFunc(_key, _func_ptr) \
if(!RegisterInputDataFunc(_key,(DataDealFunc) _func_ptr)) \
{\
std::cout<<"DataManager.h 77 - RegisterFunc-" << _key << "-注册失败" << std::endl; \
return false; \
}
#endif
class DataTranslate
{
public:
DataTranslate();
`DataTranslate();
protected:
virtual bool RegisterFunc() = 0;
bool RegisterFunc(std::string _key, DataDealFunc _func);
private:
std::unorderd_map<std::string, DataDealFunc> data_deal_func_map_;
};
实现类源文件:
#inlcude "data_manager.h"
DataTranslate::DataTranslate(){}
DataTranslate::`DataTranslate(){}
bool DataTranslate::RegisterInputDataFunc(std::string _key, DataDealFunc _func)
{
auto iter = data_deal_func_map_.find(_key);
if(iter!=data_deal_func_map_.end())
return false;
data_deal_func_map_[key] = _func;
return true;
}
使用类头文件:
#include "data_manager.h"
class KKK:
public DataTranslate
{
public:
KKK();
`KKK();
protected:
virtual bool RegisterFunc() override;
private:
bool ppp();
使用类源文件:
#include "kkk.h"
KKK::KKK()
{
RegisterFunc();
}
KKK::`KKK(){}
bool KKK::RegisterFunc()
{
RegisterFunc(key,&KKK::ppp);
return true;
}
bool KKK::PPP()
{
return true;
}
|