当前位置:网站首页>Tar source code analysis 9
Tar source code analysis 9
2022-07-04 06:37:00 【Tao song remains the same】
How to define classes in dynamic runtime , It's also very intuitive :
#include "util/tc_dyn_object.h"
#include <string.h>
namespace tars
{
/**********************************TC_DYN_RuntimeClass Definition ***********************************/
TC_DYN_RuntimeClass* TC_DYN_RuntimeClass::pFirstClass = NULL;
TC_DYN_Object* TC_DYN_RuntimeClass::createObject()
{
if (m_pfnCreateObject == NULL)
{
return NULL;
}
TC_DYN_Object* pObject = (*m_pfnCreateObject)();
{
return pObject;
}
}
TC_DYN_RuntimeClass* TC_DYN_RuntimeClass::load(const char *szClassName)
{
TC_DYN_RuntimeClass* pClass;
for (pClass = pFirstClass; pClass != NULL; pClass = pClass->m_pNextClass)
{
if (strcmp(szClassName, pClass->m_lpszClassName) == 0)
return pClass;
}
return NULL;
}
/**********************************szTC_DYN_Object Definition ***********************************/
TC_DYN_RuntimeClass TC_DYN_Object::classTC_DYN_Object =
{
(char*)"TC_DYN_Object",
sizeof(TC_DYN_Object),
NULL,
NULL,
NULL
};
static TC_DYN_Init _init_TC_DYN_Object(&TC_DYN_Object::classTC_DYN_Object);
TC_DYN_RuntimeClass* TC_DYN_Object::GetRuntimeClass() const
{
return &TC_DYN_Object::classTC_DYN_Object;
}
bool TC_DYN_Object::isKindOf(const TC_DYN_RuntimeClass* pClass) const
{
TC_DYN_RuntimeClass* pClassThis = GetRuntimeClass();
while (pClassThis != NULL)
{
if (pClassThis == pClass)
{
return true;
}
pClassThis = pClassThis->m_pBaseClass;
}
return false;
}
}
边栏推荐
- Practical gadget instructions
- 7. Agency mode
- AWT introduction
- 运算符<< >>傻瓜式测试用例
- 2022 wechat enterprise mailbox login entry introduction, how to open and register enterprise wechat enterprise mailbox?
- P26-P34 third_ template
- tars源码分析之4
- 17-18. Dependency scope and life cycle plug-ins
- 分布式CAP理论
- Average two numbers
猜你喜欢
随机推荐
Mysql 45讲学习笔记(六)全局锁
Appium foundation - appium installation (II)
Realize IIC data / instruction interaction with micro batg135
QT QTableWidget 表格列置顶需求的思路和代码
分布式CAP理论
tars源码分析之5
Native Cloud - SSH articles must be read on Cloud (used for Remote Login to Cloud Server)
ORICO ORICO outdoor power experience, lightweight and portable, the most convenient office charging station
Tsinghua University product: penalty gradient norm improves generalization of deep learning model
Considerations for testing a website
金盾视频播放器拦截的软件关键词和进程信息
4G wireless all network solar hydrological equipment power monitoring system bms110
[number theory] fast power (Euler power)
What is the sheji principle?
《ClickHouse原理解析与应用实践》读书笔记(4)
P26-P34 third_ template
Which water in the environment needs water quality monitoring
Wechat applet scroll view component scrollable view area
tars源码分析之1
24 magicaccessorimpl can access the debugging of all methods