-
Notifications
You must be signed in to change notification settings - Fork 3
/
tinyxml2_wrapper.cpp
72 lines (61 loc) · 1.98 KB
/
tinyxml2_wrapper.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
#include "tinyxml2_wrapper.h"
#include <sstream>
#include <iostream>
using namespace tinyxml2;
double getDoubleValue(XMLElement *e, const char *name) {
// get the child element
XMLElement *child = e->FirstChildElement(name);
if (child == NULL) {
std::stringstream error_stream;
error_stream << "Error getting child element: " << name;
std::string msg = error_stream.str();
throw msg;
}
// get the value
double value;
if (child->QueryDoubleText(&value) != XML_SUCCESS) {
std::stringstream error_stream;
error_stream << "Error getting double value for child element: " << name;
std::string msg = error_stream.str();
throw msg;
}
return value;
}
float getFloatValue(XMLElement *e, const char *name) {
// get the child element
XMLElement *child = e->FirstChildElement(name);
if (child == NULL) {
std::stringstream error_stream;
error_stream << "Error getting child element: " << name;
std::string msg = error_stream.str();
throw msg;
}
// get the value
float value;
if (child->QueryFloatText(&value) != XML_SUCCESS) {
std::stringstream error_stream;
error_stream << "Error getting double value for child element: " << name;
std::string msg = error_stream.str();
throw msg;
}
return value;
}
int getIntValue(XMLElement *e, const char *name) {
// get the child element
XMLElement *child = e->FirstChildElement(name);
if (child == NULL) {
std::stringstream error_stream;
error_stream << "Error getting child element: " << name;
std::string msg = error_stream.str();
throw msg;
}
// get the value
int value;
if (child->QueryIntText(&value) != XML_SUCCESS) {
std::stringstream error_stream;
error_stream << "Error getting int value for child element: " << name;
std::string msg = error_stream.str();
throw msg;
}
return value;
}