自动注册类厂 代码实现
来源:互联网 发布:烟台淘宝客服招聘 编辑:程序博客网 时间:2024/04/28 17:26
struct CellCreateKey
{
INT64 ddwColFlag;
CellCreateKey(INT64 ddwColFlag)
{
this->ddwColFlag = ddwColFlag;
}
CellCreateKey(const CellCreateKey& oParam)
{
this->ddwColFlag = oParam.ddwColFlag;
}
bool operator<(const CellCreateKey& oParam) const
{
return ddwColFlag < oParam.ddwColFlag;
}
};
class Factory
{
public:
static Factory& Get();
Type* CreateCPD(const CellCreateKey& stParam);
public:
template<class T>
struct Register_Helper
{
Register_Helper(const CellCreateKey& stKey)
{
Factory::Get().s_mapCPD.emplace(stKey, [&]{return T(stKey.ddwColFlag)});
}
Register_Helper(const CellCreateKey& stkey, std::function<Type*()> createFun)
{
Factory::Get().s_mapCPD.emplace(stkey, createFun);
}
};
protected:
Factory(){};
protected:
static map<CellCreateKey, std::function<Type*()>> s_mapCPD;
};
#define Register_CPD(ddwColFlag, CPD) static Factory::Register_Helper<CPD> oRegister_Helper_##ddwColFlag##(CellCreateKey(ddwColFlag))
#define Register_CPD_EX(ddwColFlag, createFunc) static Factory::Register_Helper<int> oRegister_Helper_##ddwColFlag##(CellCreateKey(ddwColFlag), createFunc)
{
INT64 ddwColFlag;
CellCreateKey(INT64 ddwColFlag)
{
this->ddwColFlag = ddwColFlag;
}
CellCreateKey(const CellCreateKey& oParam)
{
this->ddwColFlag = oParam.ddwColFlag;
}
bool operator<(const CellCreateKey& oParam) const
{
return ddwColFlag < oParam.ddwColFlag;
}
};
class Factory
{
public:
static Factory& Get();
Type* CreateCPD(const CellCreateKey& stParam);
public:
template<class T>
struct Register_Helper
{
Register_Helper(const CellCreateKey& stKey)
{
Factory::Get().s_mapCPD.emplace(stKey, [&]{return T(stKey.ddwColFlag)});
}
Register_Helper(const CellCreateKey& stkey, std::function<Type*()> createFun)
{
Factory::Get().s_mapCPD.emplace(stkey, createFun);
}
};
protected:
Factory(){};
protected:
static map<CellCreateKey, std::function<Type*()>> s_mapCPD;
};
#define Register_CPD(ddwColFlag, CPD) static Factory::Register_Helper<CPD> oRegister_Helper_##ddwColFlag##(CellCreateKey(ddwColFlag))
#define Register_CPD_EX(ddwColFlag, createFunc) static Factory::Register_Helper<int> oRegister_Helper_##ddwColFlag##(CellCreateKey(ddwColFlag), createFunc)
阅读全文
0 0
- 自动注册类厂 代码实现
- asp 注册代码实现
- 通过类静态成员变量 可以实现自动注册机制
- android 应用软件注册与自动登录代码
- ThinkPHP注册自动验证及自动完成部分代码参考
- ThinkPHP注册自动验证及自动完成部分代码参考
- C#实现自动注册自定义文件类型介绍
- ruckus 设置OPTION43 实现设备自动注册
- C++中实现自动注册的工厂
- myeclipse到期自动注册类
- 用VC实现自动处理网页,比如自动发帖,注册
- 用代码实现注册Ocx和Dll
- 实现注册页面中的倒计时功能代码
- Java注册邮箱激活验证实现代码
- Java注册邮箱激活验证实现代码
- Java注册邮箱激活验证实现代码
- 登录+注册界面的实现(代码)
- Java 实现会员注册升级 关键代码
- 494. Target Sum
- 六数码 广搜例题 附带一些实用的小用法
- AI域名与建站完全指南
- Logistic Regression 逻辑回归,Tensorflow源码实现
- Java 对象在堆中的内存结构
- 自动注册类厂 代码实现
- vue页面闪烁[解决]
- 论文阅读-《Learning Deep Features for Discriminative Localization》
- c if做判断,控制div动态加载图片按钮
- 教你如何正确的创建Android马甲包
- 深入理解javascript原型和闭包(4)——隐式原型
- C#---保留固定小数点后面位数
- latex生成pdf中文标签乱码&pdf复制乱码
- linux系统(Ubuntu)如何设置双显双触摸