📄 ixmlparser.c
字号:
#include "iXmlParser.h"
#include "AEEStdLib.h"
/*----------------------------------------------------------------
函数
------------------------------------------------------------------*/
//以下两个用于环境调用
int IXmlParser_New(int16 nSize, IShell *pIShell, IModule* pIModule,IModule ** ppMod);
//以下具体实现
static uint32 IXmlParser_AddRef(IXmlParser* pMe);
static uint32 IXmlParser_Release(IXmlParser* pMe);
static boolean IXmlParser_ParseXml(IXmlParser * pMe, const char * xml);
static McbXMLElement* IXmlParser_GetRootElement(IXmlParser * pMe);
static McbXMLResults IXmlParser_GetResults(IXmlParser * pMe);
static void IXmlParser_Reset(IXmlParser * pMe);
/*-----------------------------------------------------------------------------------------
实现
------------------------------------------------------------------------------------------*/
int IXmlParser_New(int16 nSize, IShell *pIShell, IModule* pIModule,IModule ** ppMod)
{
//声明扩展类的结构和虚表
IXmlParser* pMe = NULL;
VTBL(IXmlParser) * modFuncs;
//要求传入Mod/Shell
if( !ppMod || !pIShell || !pIModule )
return EFAILED;
*ppMod = NULL;
// 分配扩展类的内存
if( nSize < sizeof(IXmlParser) )
nSize += sizeof(IXmlParser);
if( (pMe = (IXmlParser*)MALLOC(nSize +sizeof(VTBL(IXmlParser)))) == NULL )
return ENOMEMORY;
modFuncs = (VTBL(IXmlParser)*)((byte *)pMe + nSize);
//初始化虚表
modFuncs->AddRef = IXmlParser_AddRef;
modFuncs->Release = IXmlParser_Release;
modFuncs->ParseXml = IXmlParser_ParseXml;
modFuncs->GetRootElement = IXmlParser_GetRootElement;
modFuncs->GetResults = IXmlParser_GetResults;
modFuncs->Reset = IXmlParser_Reset;
INIT_VTBL(pMe, IModule, *modFuncs);
//初始基本数据
pMe->m_nRefs = 1;
pMe->m_pIShell = pIShell;
pMe->m_pIModule = pIModule;
pMe->m_pRoot = NULL;
ZEROAT(&pMe->m_Results);
//获取系统控件
ISHELL_AddRef(pIShell);
IMODULE_AddRef(pIModule);
//当前模块
*ppMod = (IModule*)pMe;
return AEE_SUCCESS;
}
/*-------------------------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------------------------*/
static uint32 IXmlParser_AddRef(IXmlParser* pMe)
{
return ++(pMe->m_nRefs);
}
static uint32 IXmlParser_Release(IXmlParser* pMe)
{
if( --pMe->m_nRefs != 0 )
return pMe->m_nRefs;
//如果已经没有引用了
ISHELL_Release(pMe->m_pIShell);
IMODULE_Release(pMe->m_pIModule);
//释放资源
IXmlParser_Reset(pMe);
//释放自己
FREE_VTBL(pMe, IModule);
FREE( pMe );
return 0;
}
/*-----------------------------------------------------------------------------------------------------------
------------------------------------------------------------------------------------------------------------*/
static boolean IXmlParser_ParseXml(IXmlParser * pMe, const char * xml)
{
pMe->m_pRoot = McbParseXML(xml,&pMe->m_Results);
//debug
{
char * str;
McbAddAttribute(pMe->m_pRoot->pEntries[0].node.pElement,"with","sharetop",0);
str = McbCreateXMLString(pMe->m_pRoot,0,0);
DBGPRINTF("--%s",str);
FREEIF(str);
}
if( pMe->m_Results.error==eXMLErrorNone && pMe->m_pRoot && pMe->m_pRoot->nSize>0)
return TRUE;
else
return FALSE;
}
static McbXMLElement* IXmlParser_GetRootElement(IXmlParser * pMe)
{
return pMe->m_pRoot;
}
static McbXMLResults IXmlParser_GetResults(IXmlParser * pMe)
{
return pMe->m_Results;
}
static void IXmlParser_Reset(IXmlParser * pMe)
{
if(pMe->m_pRoot)
{
McbDeleteRoot(pMe->m_pRoot);
pMe->m_pRoot=NULL;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -