📄 parser.cpp
字号:
}
}
deleteArrayList(&list);
// Alert: use the copyElementContentLevel because Alert could be also in Atomic and Sequence commands
pos = 0, previous = 0;
t = XMLProcessor::copyElementContentLevel(&xml[pos], ALERT, &pos);
while ((alert = getAlert(t)) != NULL) {
if (alert) {
if (!list)
list = new ArrayList();
list->add(*alert); // in the ArrayList NULL element cannot be inserted
deleteAlert(&alert);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContentLevel(&xml[pos], ALERT, &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// Map: use the copyElementContentLevel because Map could be also in Atomic and Sequence commands
pos = 0, previous = 0;
t = XMLProcessor::copyElementContentLevel(&xml[pos], MAP, &pos);
while ((map = getMap(t)) != NULL) {
if (map) {
if (!list)
list = new ArrayList();
list->add(*map); // in the ArrayList NULL element cannot be inserted
deleteMap(&map);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContentLevel(&xml[pos], MAP, &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// Get: use the copyElementContentLevel because Get could be also in Atomic and Sequence commands
pos = 0, previous = 0;
t = XMLProcessor::copyElementContent(&xml[pos], GET, &pos);
while ((get = getGet(t)) != NULL) {
if (get) {
if (!list)
list = new ArrayList();
list->add(*get); // in the ArrayList NULL element cannot be inserted
deleteGet(&get);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContent(&xml[pos], GET, &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// Put
pos = 0, previous = 0;
t = XMLProcessor::copyElementContent(&xml[pos], PUT, &pos);
while ((put = getPut(t)) != NULL) {
if (put) {
if (!list)
list = new ArrayList();
list->add(*put); // in the ArrayList NULL element cannot be inserted
deletePut(&put);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContent(&xml[pos], PUT, &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// Results
pos = 0, previous = 0;
t = XMLProcessor::copyElementContent(&xml[pos], RESULTS, &pos);
while ((result = getResult(t)) != NULL) {
if (result) {
if (!list)
list = new ArrayList();
list->add(*result); // in the ArrayList NULL element cannot be inserted
deleteResults(&result);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContent(&xml[pos], RESULTS, &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// Exec: use the copyElementContentLevel because Exec could be also in Atomic and Sequence commands
pos = 0, previous = 0;
t = XMLProcessor::copyElementContentLevel(&xml[pos], EXEC, &pos);
while ((exec = getExec(t)) != NULL) {
if (exec) {
if (!list)
list = new ArrayList();
list->add(*exec); // in the ArrayList NULL element cannot be inserted
deleteExec(&exec);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContentLevel(&xml[pos], EXEC, &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// Search
pos = 0, previous = 0;
t = XMLProcessor::copyElementContent(&xml[pos], SEARCH, &pos);
while ((search = getSearch(t)) != NULL) {
if (search) {
if (!list)
list = new ArrayList();
list->add(*search); // in the ArrayList NULL element cannot be inserted
deleteSearch(&search);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContent(&xml[pos], SEARCH, &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// get the Sync commands. not belonging to Atomic and Sequence
//sync = getSync(XMLProcessor::copyElementContentExcept (xml, SYNC, "Atomic&Sequence", NULL));
//if (sync) {
// ret->add(*sync);
// deleteSync(&sync);
//}
// Sync
pos = 0, previous = 0;
t = XMLProcessor::copyElementContentExcept(&xml[pos], SYNC, "Atomic&Sequence", &pos);
while ((sync = getSync(t)) != NULL) {
if (sync) {
if (!list)
list = new ArrayList();
list->add(*sync); // in the ArrayList NULL element cannot be inserted
deleteSync(&sync);
}
pos += previous;
previous = pos;
if (t) { delete [] t; t = NULL; }
t = XMLProcessor::copyElementContentExcept(&xml[pos], SYNC, "Atomic&Sequence", &pos);
}
if (t) { delete [] t; t = NULL; }
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
// get the Sequence commands. Not belonging to Atomic and Sync
t = XMLProcessor::copyElementContentExcept(xml, SEQUENCE, "Atomic&Sync", &pos);
sequence = getSequence(t);
if (t) {delete [] t; t = NULL;}
if (sequence) {
ret->add(*sequence);
deleteSequence(&sequence);
}
// get the Sequence commands. Not belonging to Sequence and Sync and Atomic
t = XMLProcessor::copyElementContentExcept(xml, ATOMIC, "Atomic&Sync&Sequence", &pos);
atomic = getAtomic(t);
if (t) {delete [] t; t = NULL;}
if (atomic) {
ret->add(*atomic);
deleteAtomic(&atomic);
}
list = getCommonCommandList(xml, "Atomic&Sync&Sequence");
if (list && list->size() > 0) {
for (int i = 0; i < list->size(); i++) {
ret->add(*list->get(i));
}
}
deleteArrayList(&list);
return ret;
}
Status* Parser::getStatus(const char*xml) {
if (!xml)
return NULL;
Status* ret = NULL;
CmdID* cmdID = NULL;
char* msgRef = NULL;
char* cmdRef = NULL;
char* cmd = NULL;
ArrayList* targetRefs = new ArrayList();
ArrayList* sourceRefs = new ArrayList();
Cred* cred = NULL;
Chal* chal = NULL;
Data* data = NULL;
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);
cmd = XMLProcessor::copyElementContent (xml, CMD, NULL);
t = XMLProcessor::copyElementContent (xml, CRED , NULL);
cred = getCred (t);
if (t) {delete [] t; t = NULL;}
// get Data <Data>200</Data>
t = XMLProcessor::copyElementContent (xml, DATA , NULL);
data = getData (t);
if (t) {delete [] t; t = NULL;}
items = getItems (xml);
targetRefs = getTargetRefs(xml);
sourceRefs = getSourceRefs(xml);
t = XMLProcessor::copyElementContent (xml, CHAL , NULL);
chal = getChal (t);
if (t) {delete [] t; t = NULL;}
if (NotNullCheck(2, msgRef, cmdRef) || (cred)
|| (data)
|| (cmdID)
|| (chal)
|| NotZeroArrayLenght(3, items, targetRefs, sourceRefs)
) {
ret = new Status(cmdID, msgRef, cmdRef, cmd, targetRefs, sourceRefs, cred, chal, data, items);
}
deleteArrayList(&sourceRefs);
deleteArrayList(&targetRefs);
deleteArrayList(&items);
deleteAll(3, &msgRef, &cmdRef, &cmd);
deleteCmdID(&cmdID);
deleteCred(&cred);
deleteData(&data);
deleteChal(&chal);
return ret;
}
Chal* Parser::getChal(const char*xml) {
Chal* ret = NULL;
Meta* meta = NULL;
meta = getMeta (xml);
if (meta) {
ret = new Chal(meta);
deleteMeta(&meta);
}
return ret;
}
ArrayList* Parser::getTargetRefs(const char*xml) {
ArrayList* list = new ArrayList();
TargetRef* targetRef = NULL;
unsigned int pos = 0, previous = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent(&xml[pos], TARGET_REF, &pos);
while ((targetRef = getTargetRef(t)) != NULL) {
if (targetRef) {
list->add(*targetRef); // in the ArrayList NULL element cannot be inserted
deleteTargetRef(&targetRef);
}
pos += previous;
previous = pos;
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(&xml[pos], TARGET_REF, &pos);
}
if (t) {delete [] t; t = NULL;}
return list;
}
ArrayList* Parser::getSourceRefs(const char*xml) {
ArrayList* list = new ArrayList();
SourceRef* sourceRef = NULL;
unsigned int pos = 0, previous = 0;
char* t = NULL;
t = XMLProcessor::copyElementContent(&xml[pos], SOURCE_REF, &pos);
while ((sourceRef = getSourceRef(t)) != NULL) {
if (sourceRef) {
list->add(*sourceRef); // in the ArrayList NULL element cannot be inserted
deleteSourceRef(&sourceRef);
}
pos += previous;
previous = pos;
if (t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent(&xml[pos], SOURCE_REF, &pos);
}
if (t) {delete [] t; t = NULL;}
return list;
}
SourceRef* Parser::getSourceRef(const char*xml) {
SourceRef* ret = NULL;
Source* source;
source = getSource(xml);
if (source) {
ret = new SourceRef(source);
} else if (xml) {
ret = new SourceRef(xml);
}
return ret;
}
TargetRef* Parser::getTargetRef(const char*xml) {
TargetRef* ret = NULL;
Target* target;
target = getTarget(xml);
if (target) {
ret = new TargetRef(target);
} else if (xml) {
ret = new TargetRef(xml);
}
return ret;
}
Alert* Parser::getAlert(const char*xml) {
Alert* ret = NULL;
ArrayList* items = new ArrayList();
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, DATA , NULL);
int data = getDataCode(t);
if(t) {delete [] t; t = NULL;}
t = XMLProcessor::copyElementContent (xml, NO_RESP, NULL);
BOOL noResp = getNoResp (t);
if(t) {delete [] t; t = NULL;}
items = getItems(xml);
if (items && items->size() > 0) {
ret = new Alert(cmdID, noResp, cred, data, items); //Item[]
}
deleteCmdID(&cmdID);
deleteCred(&cred);
deleteArrayList(&items);
return ret;
}
Exec* Parser::getExec(const char*xml) {
Exec* ret = NULL;
CmdID* cmdID = NULL;
BOOL noResp = FALSE;
Cred* cred = NULL;
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;}
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;}
items = getItems(xml);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -