RTTI ---- Imitate from Inside MFC
来源:互联网 发布:软件脱壳后源码 编辑:程序博客网 时间:2024/05/16 19:26
RTTI means Runtime Type Information.
The compiler itself enable this functionality.
Now here just to imitate the mechalism referring to Inside MFC.
1. CRuntimeClass node to construct the link list.
struct CRuntimeClass
{
LPCSTR m_lpszClassName;
int m_nObjectSize;
UINT m_wSchema;
CObject* (PASCAL* m_pfnCreateObject)();
CRuntimeClass* m_pBaseClass;
CRuntimeClass* m_pNextClass;
static CRuntimeClass* pFirstClass;
}
2. DECLARE_DYNAMIC(class_Name) to declare in .h file.
#define DECLARE_DYNAMIC(class_name) /
public: /
static CRuntimeClass class##class_name; /
virtual CRuntimeClass* GetRuntimeClass() const;
3. Implement macro in .cpp file
#define IMPLEMENT_DYNAMIC(class_name, base_class_name) /
_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, NULL)
#define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) /
static char _lpsz##class_name[] = #class_name;
CRuntimeClass class_name::class##class_name = { /
_lpsz##class_name, sizeof(class_name), wShema,pfnNew, /
RuntimeClass(base_class_name),NULL }; /
static AFX_CLASSINIT _init_##class_name(&class_name::class##class_name); /
CRuntimeClass* class_name::GetRuntimeClass() const /
{return &clas_name::class##class_name; }
#define RUNTIME_CLASS(class_name) /
(&class_name::class##class_name)
struct AFX_CLASSINIT
{AFX_CLASSINIT(CRuntimeClass* pNewClass); };
3. The root class CObject has the specific definition as its m_pBaseClass = NULL.
4. Initialize the static variable.
CRuntimeClass* CRuntimeClass::pFirstClass = NULL;
5. Initial Class to link all the nodes.
AFX_CLASSINIT::AFX_CLASSINIT(CRuntimeClass* pNewClass)
{
pNewClass->m_pNextClass = CRuntimeClass::pFirstClass;
CRuntimeClass::pFirstClass = pNewClass;
}
6. Define the judge function in CObject IsKindof()
BOOL CObject:: IsKindOf(const CRuntimeClass* pClass) const
{
CRuntimeClass* pClassThis = GetRuntimeClass();
while (pClassThis != null)
{
if (pClassThis == pClass)
return True;
pClassThis = pClassThis->m_pBaseClass;
}
return FALSE;
}
The compiler itself enable this functionality.
Now here just to imitate the mechalism referring to Inside MFC.
1. CRuntimeClass node to construct the link list.
struct CRuntimeClass
{
LPCSTR m_lpszClassName;
int m_nObjectSize;
UINT m_wSchema;
CObject* (PASCAL* m_pfnCreateObject)();
CRuntimeClass* m_pBaseClass;
CRuntimeClass* m_pNextClass;
static CRuntimeClass* pFirstClass;
}
2. DECLARE_DYNAMIC(class_Name) to declare in .h file.
#define DECLARE_DYNAMIC(class_name) /
public: /
static CRuntimeClass class##class_name; /
virtual CRuntimeClass* GetRuntimeClass() const;
3. Implement macro in .cpp file
#define IMPLEMENT_DYNAMIC(class_name, base_class_name) /
_IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, 0xFFFF, NULL)
#define _IMPLEMENT_RUNTIMECLASS(class_name, base_class_name, wSchema, pfnNew) /
static char _lpsz##class_name[] = #class_name;
CRuntimeClass class_name::class##class_name = { /
_lpsz##class_name, sizeof(class_name), wShema,pfnNew, /
RuntimeClass(base_class_name),NULL }; /
static AFX_CLASSINIT _init_##class_name(&class_name::class##class_name); /
CRuntimeClass* class_name::GetRuntimeClass() const /
{return &clas_name::class##class_name; }
#define RUNTIME_CLASS(class_name) /
(&class_name::class##class_name)
struct AFX_CLASSINIT
{AFX_CLASSINIT(CRuntimeClass* pNewClass); };
3. The root class CObject has the specific definition as its m_pBaseClass = NULL.
4. Initialize the static variable.
CRuntimeClass* CRuntimeClass::pFirstClass = NULL;
5. Initial Class to link all the nodes.
AFX_CLASSINIT::AFX_CLASSINIT(CRuntimeClass* pNewClass)
{
pNewClass->m_pNextClass = CRuntimeClass::pFirstClass;
CRuntimeClass::pFirstClass = pNewClass;
}
6. Define the judge function in CObject IsKindof()
BOOL CObject:: IsKindOf(const CRuntimeClass* pClass) const
{
CRuntimeClass* pClassThis = GetRuntimeClass();
while (pClassThis != null)
{
if (pClassThis == pClass)
return True;
pClassThis = pClassThis->m_pBaseClass;
}
return FALSE;
}
- RTTI ---- Imitate from Inside MFC
- Dynamic Creation ----------- Imitate from Inside MFC
- Message Mapping ---- Imitate from Inside MFC
- MFC rtti 学习笔记
- 关于MFC中的RTTI
- MFC深入浅出之RTTI
- MFC-RTTI
- MFC RTTI 实现
- MFC RTTI 宏
- MFC RTTI 仿真
- MFC仿真之RTTI
- MFC RTTI实现原理
- MFC的RTTI
- MFC的RTTI实现
- MFC的RTTI
- MFC的RTTI实现
- MFC的RTTI实现
- MFC的RTTI实现机制!
- Java6 WebServices (二)客户端
- IBM WebSphere 开发者技术期刊: 将 Spring 和 Hibernate 与 WebSphere Application Server 一起使用
- 数据库备份与还原处理
- 使用业务驱动的开发为卫生保健组织开发 SOA 解决方案
- 《解剖PetShop》系列之一
- RTTI ---- Imitate from Inside MFC
- Ajax 和 REST,第 2 部分
- 关于 Apache Geronimo PetStore 演示的分析
- 于 Power 体系结构的汇编语言,第 2 部分: PowerPC 上加载和存储的艺术
- 跨越边界: 延迟绑定
- 千万不要死于无知——平衡饮食
- 在 Ubuntu 6.10 上安装并使用 Lotus Notes 7
- ToString 格式化数值
- 在 WebSphere Federation Server V9.1 中使用联邦过程