C++工厂模式
C++ 的工厂模式
#define STACK_POS_TOP (0x0001)
#define STACK_POS_INSIDE (0x0002)
#define BEGIN_CELL_REGISTER \
public: \
virtual CCell* GetCell(ulong ulCellID) \
{ \
switch(ulCellID) \
{
#define CELL_REGISTER(_CellID_, _CellClass_) \
case (_CellID_): \
{ \
CCell* pCell = new _CellClass_(); \
if(pCell) \
{ \
pCell->SetCellID(ulCellID); \
} \
return pCell; \
}
#define END_CELL_REGISTER \
default: \
break; \
} \
return NULL; \
} \
virtual UI_RESULT DeleteCell(CCell* pCell) \
{ \
delete pCell; \
return UI_SUCCESS; \
}
//工厂模式类
BEGIN_CELL_REGISTER
CELL_REGISTER(CELLID_BOOT, CCell_Boot)
END_CELL_REGISTER