📄 parser.cpp
字号:
if (cmdID || NotZeroArrayLenght(1, items) || (cred)) {
ret = new Exec(cmdID, noResp, cred, items);
}
deleteCmdID(&cmdID);
deleteCred(&cred);
deleteArrayList(&items);
return ret;
}
Get* Parser::getGet(const char*xml) {
Get* ret = NULL;
ArrayList* items = NULL;
unsigned int pos = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
CmdID* cmdID = getCmdID (t);
if(t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, CRED , NULL);
Cred* cred = getCred (t);
if(t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
BOOL noResp = getNoResp (t);
if(t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContentLevel (xml, META , NULL);
Meta* meta = getMeta (t);
if(t) {delete [] t; t = NULL;}
char* lang = XMLProcessor::copyElementContent (xml, LANG, NULL);
items = getItems(xml);
if (NotNullCheck(1, lang) || (cred)
|| (cmdID)
|| (meta)
|| NotZeroArrayLenght(1, items)) {
ret = new Get(cmdID, noResp, lang, cred, meta, items); //Item[]
}
deleteCmdID(&cmdID);
deleteCred(&cred);
deleteMeta(&meta);
safeDel(&lang);
deleteArrayList(&items);
return ret;
}
Put* Parser::getPut(const char*xml) {
Put* ret = NULL;
ArrayList* items = NULL;
unsigned int pos = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
CmdID* cmdID = getCmdID (t);
if(t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, CRED , NULL);
Cred* cred = getCred (t);
if(t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
BOOL noResp = getNoResp (t);
if(t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContentLevel (xml, META , NULL);
Meta* meta = getMeta (t);
if(t) {delete [] t; t = NULL;}
char* lang = XMLProcessor::copyElementContent (xml, LANG, NULL);
items = getItems(xml);
if (NotNullCheck(1, lang) || (cred)
|| (cmdID)
|| (meta)
|| NotZeroArrayLenght(1, items)) {
ret = new Put(cmdID, noResp, lang, cred, meta, items); //Item[]
}
deleteCmdID(&cmdID);
deleteCred(&cred);
deleteMeta(&meta);
safeDel(&lang);
deleteArrayList(&items);
return ret;
}
Search* Parser::getSearch(const char*xml) {
Search* ret = NULL;
CmdID* cmdID = NULL;
BOOL noResp = NULL;
BOOL noResults= NULL;
Cred* cred = NULL;
Target* target = NULL;
ArrayList* sources = new ArrayList(); // an Array of SourceArray object
char* lang = NULL;
Meta* meta = NULL;
Data* data = NULL;
unsigned int pos = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
cmdID = getCmdID (t);
if (t) { delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, CRED , NULL);
cred = getCred (t);
if (t) { delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
noResp = getNoResp (t);
if (t) { delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(xml, NO_RESULTS, NULL);
noResults = getNoResults(t);
if (t) { delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, TARGET,NULL);
target = getTarget (t);
if (t) { delete [] t; t = NULL;}
lang = XMLProcessor::copyElementContent (xml, LANG, NULL);
t = XMLProcessor::copyElementContentLevel (xml, META , NULL);
meta = getMeta (t);
if (t) { delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, DATA , NULL);
data = getData (t);
if (t) { delete [] t; t = NULL;}
sources = getSources (xml);
if (NotNullCheck(1, lang) || (cmdID) || (cred)
|| (meta) || (target)
|| (data) || NotZeroArrayLenght(1, sources)) {
ret = new Search(cmdID, noResp, noResults, cred, target, sources, lang, meta, data);
}
deleteCmdID(&cmdID);
deleteCred(&cred);
deleteTarget(&target);
safeDel(&lang);
deleteData(&data);
deleteMeta(&meta);
deleteArrayList(&sources);
return ret;
}
Results* Parser::getResult(const char*xml) {
if (!xml)
return NULL;
Results* ret = NULL;
CmdID* cmdID = NULL;
char* msgRef = NULL;
char* cmdRef = NULL;
Meta* meta = NULL;
ArrayList* targetRefs = new ArrayList(); // it could be an array with only a value
ArrayList* sourceRefs = new ArrayList();
ArrayList* items = new ArrayList();
unsigned int pos = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent (xml, CMD_ID , NULL);
cmdID = getCmdID (t);
if (t) {delete [] t; t = NULL;}
msgRef = XMLProcessor::copyElementContent (xml, MSG_REF, NULL);
cmdRef = XMLProcessor::copyElementContent (xml, CMD_REF, NULL);
t = XMLProcessor::copyElementContentLevel(xml, META, NULL);
meta = getMeta (t);
if (t) {delete [] t; t = NULL;}
targetRefs = getTargetRefs(xml);
sourceRefs = getSourceRefs(xml);
items = getItems (xml);
if (NotNullCheck(2, msgRef, cmdRef) || (cmdID) || (meta)
|| NotZeroArrayLenght(3, items, targetRefs, sourceRefs)
) {
ret = new Results(cmdID, msgRef, cmdRef, meta, targetRefs, sourceRefs, items);
}
deleteArrayList(&sourceRefs);
deleteArrayList(&targetRefs);
deleteArrayList(&items);
deleteAll(2, &msgRef, &cmdRef);
deleteCmdID(&cmdID);
deleteMeta(&meta);
return ret;
}
//
// return and array list of items
//
ArrayList* Parser::getItems(const char*xml, const char* command) {
Item* item = NULL;
ArrayList* items = NULL;
unsigned int pos = 0, previous = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent(&xml[pos], ITEM, &pos);
while ((item = getItem(t, command)) != NULL) {
if (item) {
if (!items)
items = new ArrayList();
items->add(*item); // in the ArrayList NULL element cannot be inserted
deleteItem(&item);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContent(&xml[pos], ITEM, &pos);
}
if (t) { delete [] t; t = NULL; }
return items;
}
Item* Parser::getItem(const char*xml, const char* command) {
Item* ret = NULL;
Target* target = NULL;
Source* source = NULL;
Meta* meta = NULL;
ComplexData* data = NULL;
BOOL moreData = FALSE;
char* targetParent = NULL;
char* sourceParent = NULL;
char* t = NULL;
unsigned int pos = 0;
t = XMLProcessor::copyElementContent(xml, TARGET,NULL);
target = getTarget (t);
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(xml, SOURCE,NULL);
source = getSource (t);
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContentLevel(xml, META,NULL);
meta = getMeta (t);
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(xml, COMPLEX_DATA,NULL);
data = getComplexData(t,command);
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContent(xml, MORE_DATA,NULL);
moreData = getMoreData (t);
if (t) {delete [] t; t = NULL;}
targetParent = XMLProcessor::copyElementContent(xml, TARGET_PARENT, NULL);
sourceParent = XMLProcessor::copyElementContent(xml, SOURCE_PARENT, NULL);
if ((target) ||
(source) ||
(meta) ||
(data)) {
// ret = new Item(target, source, meta, data, moreData);
ret = new Item(target, source, targetParent, sourceParent, meta, data, moreData);
}
deleteTarget (&target);
deleteSource (&source);
deleteMeta (&meta);
deleteComplexData(&data);
deleteAll(2, &targetParent, &sourceParent);
return ret;
}
int Parser::getDataCode(const char*content) {
int ret = 0;
if (content) {
ret = strtol(content, NULL, 10);
}
return ret;
}
Data* Parser::getData(const char*content) {
Data* ret = 0;
if (content) {
ret = new Data(content);
}
return ret;
}
BOOL Parser::getFinalMsg(const char*content) {
BOOL ret = FALSE;
if (content) {
ret = TRUE;
}
return ret;
}
CmdID* Parser::getCmdID(const char*content) {
CmdID* ret = NULL;
if (content) {
ret = new CmdID(content);
}
return ret;
}
ComplexData* Parser::getComplexData(const char*xml, const char* command) {
ComplexData* ret = NULL;
Anchor* anchor = NULL;
DevInf* devInf = NULL;
if (command &&
(strcmp(command, ADD) == 0 ||
strcmp(command, REPLACE) == 0 ||
strcmp(command, DEL) == 0 ||
strcmp(command, COPY) == 0 ) ) {
if (xml) {
ret = new ComplexData(xml);
}
}
else {
anchor = getAnchor(xml);
devInf = getDevInf(xml);
if (anchor || devInf) {
ret = new ComplexData(NULL);
if (anchor)
ret->setAnchor(anchor);
if (devInf)
ret->setDevInf(devInf);
}
else if (xml) {
ret = new ComplexData(xml);
}
}
return ret;
}
DevInf* Parser::getDevInf(const char*xml) {
DevInf* ret = NULL;
DataStore* dataStore = NULL;
CTCap* ctCap = NULL;
Ext* ext = NULL;
VerDTD* verDTD = NULL;
char* man = NULL;
char* mod = NULL;
char* oem = NULL;
char* fwV = NULL;
char* swV = NULL;
char* hwV = NULL;
char* devId = NULL;
char* devTyp = NULL;
ArrayList* dataStores = NULL; // DataStore[]
ArrayList* ctCaps = NULL; // CTCap[]
ArrayList* exts = NULL; // Ext[]
BOOL utc = NULL; // if present they Support UTC
BOOL supportLargeObjs = NULL; // if present they Support largeObject
BOOL supportNumberOfChanges = NULL; // if present they Support NumberOfChanges
SyncCap* syncCap = NULL;
char* value = NULL;
unsigned int pos = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent(xml, VER_DTD,NULL);
verDTD = getVerDTD(t);
if (t) {delete [] t; t = NULL;}
man = XMLProcessor::copyElementContent(xml, MAN, NULL);
mod = XMLProcessor::copyElementContent(xml, MOD, NULL);
oem = XMLProcessor::copyElementContent(xml, OEM, NULL);
fwV = XMLProcessor::copyElementContent(xml, FWV, NULL);
swV = XMLProcessor::copyElementContent(xml, SWV, NULL);
hwV = XMLProcessor::copyElementContent(xml, HWV, NULL);
devId = XMLProcessor::copyElementContent(xml, DEV_ID, NULL);
devTyp = XMLProcessor::copyElementContent(xml, DEV_TYP, NULL);
t = XMLProcessor::copyElementContent(xml, SYNC_CAP,NULL);
syncCap = getSyncCap(t);
if (t) {delete [] t; t = NULL;}
unsigned int previous = 0;
pos = 0;
// DataStore
t = XMLProcessor::copyElementContent(&xml[pos], DATA_STORE, &pos);
while ((dataStore = getDataStore(t)) != NULL) {
if (dataStore) {
if (!dataStores) {
dataStores = new ArrayList();
}
dataStores->add(*dataStore); // in the ArrayList NULL element cannot be inserted
deleteDataStore(&dataStore);
}
pos += previous;
previous = pos;
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(&xml[pos], DATA_STORE, &pos);
}
if (t) {delete [] t; t = NULL;}
// ctCap
pos = 0; previous = 0;
t = XMLProcessor::copyElementContent(&xml[pos], CT_CAP, &pos);
while ((ctCap = getCTCap(t)) != NULL) {
if (ctCap) {
if (!ctCaps) {
ctCaps = new ArrayList();
}
ctCaps->add(*ctCap); // in the ArrayList NULL element cannot be inserted
deleteCTCap(&ctCap);
}
pos += previous;
previous = pos;
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(&xml[pos], CT_CAP, &pos);
}
if (t) {delete [] t; t = NULL;}
// ext
pos = 0; previous = 0;
t = XMLProcessor::copyElementContent(&xml[pos], EXT, &pos);
while ((ext = getExt(t)) != NULL) {
if (ext) {
if (!exts) {
exts = new ArrayList();
}
exts->add(*ext); // in the ArrayList NULL element cannot be inserted
deleteExt(&ext);
}
pos += previous;
previous = pos;
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(&xml[pos], EXT, &pos);
}
if (t) {delete [] t; t = NULL;}
//
// The large object value depends on SUPPORT_LARGE_OBJECT tag.
//
if ((value = XMLProcessor::copyEl
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -