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)