13 : fDoc(nullptr), fParser(new TDOMParser), fOdb(nullptr)
18 while(buffer[size - 1] ==
'\0') {
27 fParser->ParseFile(buffer);
29 std::string odb(buffer, size);
30 fParser->ParseBuffer(buffer, size);
35 throw std::runtime_error(
"XmlOdb::XmlOdb: Malformed ODB dump: cannot get XML document");
38 if(strcmp(
fOdb->GetNodeName(),
"odb") != 0) {
39 throw std::runtime_error(
"XmlOdb::XmlOdb: Malformed ODB dump: cannot find <odb> tag");
60 if(!node->HasChildren()) {
63 node = node->GetChildren();
64 while(node !=
nullptr) {
66 if(nodename == name) {
69 node = node->GetNextNode();
85 std::string pathname = path;
86 std::vector<std::string> elems;
88 std::size_t slash = pathname.find_first_of(
'/');
93 slash = pathname.find_first_of(
'/', last);
94 elems.push_back(pathname.substr(last, slash - last));
96 if(slash == std::string::npos) {
101 for(
auto& elem : elems) {
102 node =
FindNode(elem.c_str(), node);
103 if(node !=
nullptr) {
116 TList* list = node->GetAttributes();
117 if(list !=
nullptr) {
118 std::string buffer = (
static_cast<TXMLAttr*
>(list->At(0)))->GetValue();
129 if(node ==
nullptr) {
139 std::vector<int> temp;
140 if(node ==
nullptr) {
143 if(!node->HasChildren()) {
146 TList* list = node->GetAttributes();
147 if(list ==
nullptr) {
152 while(
auto* attr =
static_cast<TXMLAttr*
>(iter.Next())) {
153 if(strcmp(attr->GetName(),
"num_values") == 0) {
154 size = atoi(attr->GetValue());
157 temp.assign(size, 0);
158 TXMLNode* child = node->GetChildren();
161 if(TList* index = child->GetAttributes()) {
162 int indexnum = atoi((
static_cast<TXMLAttr*
>(index->At(0)))->GetValue());
163 int value = atoi(child->GetText());
164 temp.at(indexnum) = value;
165 }
else if(child->GetText() !=
nullptr) {
166 int indexnum = counter++;
167 temp.at(indexnum) = atoi(child->GetText());
169 child = child->GetNextNode();
170 if(child ==
nullptr) {
181 std::vector<std::string> temp;
182 if(node ==
nullptr) {
185 if(!node->HasChildren()) {
188 TList* list = node->GetAttributes();
189 if(list ==
nullptr) {
194 while(
auto* attr =
static_cast<TXMLAttr*
>(iter.Next())) {
195 if(strcmp(attr->GetName(),
"num_values") == 0) {
196 size = atoi(attr->GetValue());
199 temp.assign(size,
"");
200 TXMLNode* child = node->GetChildren();
203 if(TList* index = child->GetAttributes()) {
204 int indexnum = atoi((
static_cast<TXMLAttr*
>(index->At(0)))->GetValue());
205 const char* value = child->GetText();
208 std::string value_str;
209 if(value ==
nullptr) {
214 temp.at(indexnum) = value_str;
215 }
else if(child->GetText() !=
nullptr) {
216 int indexnum = counter++;
217 temp.at(indexnum).assign(child->GetText());
219 child = child->GetNextNode();
220 if(child ==
nullptr) {
231 std::vector<double> temp;
232 if(node ==
nullptr) {
235 if(!node->HasChildren()) {
238 TList* list = node->GetAttributes();
239 if(list ==
nullptr) {
244 while(
auto* attr =
static_cast<TXMLAttr*
>(iter.Next())) {
245 if(strcmp(attr->GetName(),
"num_values") == 0) {
246 size = atoi(attr->GetValue());
249 temp.assign(size, 0.0);
250 TXMLNode* child = node->GetChildren();
253 if(TList* index = child->GetAttributes()) {
254 int indexnum = atoi((
static_cast<TXMLAttr*
>(index->At(0)))->GetValue());
255 double value = atof(child->GetText());
256 temp.at(indexnum) = value;
257 }
else if(child->GetText() !=
nullptr) {
258 int indexnum = counter++;
259 temp.at(indexnum) = atof(child->GetText());
261 child = child->GetNextNode();
262 if(child ==
nullptr) {
std::vector< std::string > ReadStringArray(TXMLNode *node)
TXMLOdb(char *buffer, int size=0)
const char * GetNodeName(TXMLNode *)
std::vector< double > ReadDoubleArray(TXMLNode *node)
int ReadInt(const char *path, int index=0, int defaultValue=0xffffffff)
TXMLNode * FindPath(const char *path, TXMLNode *node=nullptr)
TXMLNode * FindNode(const char *name, TXMLNode *node=nullptr)
std::vector< int > ReadIntArray(TXMLNode *node)
static std::array< char, 256 > fTextBuffer