-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQBXML.cpp
executable file
·204 lines (166 loc) · 4.44 KB
/
QBXML.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
/*
* Copyright Notice : Copyright 2015, Josiah Bruner, All Rights Reserved.
*/
#include "QBXML.h"
QBXML::QBXML(XMLRead *read) {
if (read) {
_xmlData = read;
}
else {
_xmlData = new XMLRead;
_xmlData->Load("");
}
}
QBXML::~QBXML() {
}
void QBXML::Dealloc() {
if (_xmlData) {
delete _xmlData;
}
delete this;
}
XMLResult QBXML::GetAction() {
return _GetResult("action");
}
XMLResult QBXML::GetErrCode() {
return _GetResult("errcode");
}
XMLResult QBXML::GetErrText() {
return _GetResult("errtext");
}
XMLResult QBXML::GetTicket() {
return _GetResult("ticket");
}
XMLResult QBXML::GetUserID() {
return _GetResult("userid");
}
XMLResult QBXML::GetUData() {
return _GetResult("udata");
}
XMLResult QBXML::GetRID() {
return _GetResult("rid");
}
XMLResult QBXML::GetUpdateID() {
return _GetResult("update_id");
}
XMLResult QBXML::GetFID() {
return _GetResult("fid");
}
XMLResult QBXML::GetLabel() {
return _GetResult("label");
}
XMLResult QBXML::GetNumFieldsChanged() {
return _GetResult("num_fields_changed");
}
XMLResult QBXML::GetNewDBID() {
return _GetResult("newdbid");
}
XMLResult QBXML::GetRecord() {
// Unfortunately, due to poor API design, <record> tags may or may not possess an rid attribute.
// Since these attributes are much harder to parse, we instead move the attribute into an <rid> child.
_xmlData->MoveAttributesIntoChildren("record");
return _GetResult("record");
}
XMLResult QBXML::GetNumFields() {
return _GetResult("num_fields");
}
XMLResult QBXML::GetValue() {
return _GetResult("value");
}
XMLResult QBXML::GetAncestorAppId() {
return _GetResult("ancestorappid");
}
XMLResult QBXML::GetOldEstancestorAppId() {
return _GetResult("oldestancestorappid");
}
XMLResult QBXML::GetUsers() {
return _GetResult("users");
}
XMLResult QBXML::GetID()
{
return _GetResult("id");
}
XMLResult QBXML::GetFieldType()
{
return _GetResult("field_type");
}
std::vector<std::string> QBXML::GetChildDBIDs()
{
std::string children = _GetResult("chdbids").text;
std::vector<std::string> dbids;
while (children.find("\">") != -1 && children.find("</") != -1) {
unsigned first = children.find("\">");
unsigned last = children.find("</");
std::string result = children.substr(first + 2, last - first - 2);
dbids.push_back(result);
children.erase(first - 1, last - first + 3);
}
return dbids;
}
std::vector<QBXML> QBXML::GetFields() {
std::vector<QBXML> results;
std::string originalData = _xmlData->GetRawXML();
bool flag = true;
while (flag) {
_xmlData->MoveAttributesIntoChildren("field");
XMLResult aRes = _GetResult("field");
if (aRes.valid) {
XMLRead *reducedRead = new XMLRead;
reducedRead->Load(aRes.text);
QBXML newXML(reducedRead);
results.push_back(newXML);
// Strip remainingData for repeat
_xmlData->Load(_RemoveSubstring(_xmlData->GetRawXML(), "<field>" + aRes.text + "</field>"));
}
else {
flag = false;
}
}
_xmlData->Load(originalData);
return results;
}
std::vector<QBXML> QBXML::GetRecords() {
std::vector<QBXML> results;
std::string originalData = _xmlData->GetRawXML();
bool flag = true;
while (flag && originalData != "") {
_xmlData->MoveAttributesIntoChildren("record");
XMLResult aRes = _GetResult("record");
if (aRes.valid) {
XMLRead *reducedRead = new XMLRead;
reducedRead->Load(aRes.text);
QBXML newXML(reducedRead);
results.push_back(newXML);
// Strip remainingData for repeat
_xmlData->Load(_RemoveSubstring(_xmlData->GetRawXML(), "<record>" + aRes.text + "</record>"));
}
else {
flag = false;
}
}
_xmlData->Load(originalData);
return results;
}
XMLResult QBXML::_GetResult(std::string type) {
XMLResult xmlRes;
std::string result = _xmlData->GetFieldContents(type);
if (result != "ERROR") {
xmlRes.valid = true;
}
else {
xmlRes.valid = false;
}
xmlRes.type = type;
xmlRes.text = result;
return xmlRes;
}
// Removes first occurance of substring.
std::string QBXML::_RemoveSubstring(std::string mainString, std::string subString) {
std::string t = mainString;
std::string s = subString;
size_t i = t.find(s);
if (i != std::string::npos) {
t.erase(i, s.length());
}
return t;
}