-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.h
83 lines (71 loc) · 1.76 KB
/
parser.h
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
#ifndef PARSER
#define PARSER
#include "tinyxml/tinystr.h"
#include "tinyxml/tinyxml.h"
#include "gl.const.h"
#include <unordered_map>
#include <sstream>
#include <string>
#include <iostream>
#include <cmath>
#include <random>
//general functions to convert information to abd from xml
//errors processing functions
inline void exit_error(const char *tag) {
std::cout << "ERROR: Reading map failed. Not foung tag '" << tag << "'" << std::endl;
exit(0);
}
inline void warning(const char *tag) {
std::cout << "WARNING: Not foung tag '" << tag << "'. Using default value." << std::endl;
}
template <typename T>
int convert_to_int(T a) {
std::istringstream myStream(a);
int uintVar = 0;
myStream >> uintVar;
return uintVar;
}
template <typename T>
double convert_to_double(T a) {
double var;
var = std::stod(a);
return var;
}
inline std::string get_info(TiXmlElement *b) {
if(b) {
const char *b_value = b->GetText();
return b_value;
}
return "-1";
}
template<typename T>
TiXmlText * convert_to_xml(T a) {
std::stringstream ss;
ss << a;
TiXmlText *text = new TiXmlText(ss.str().c_str());
return text;
}
template<typename T>
std::string convert_to_string(T a) {
std::stringstream so;
so << a;
std::string c = so.str();
return c;
}
template<typename T>
const char * convert_to_char(T a) {
std::ostringstream sc;
sc << a;
const char * c = sc.str().c_str();
return c;
}
inline TiXmlText * convert_string(int * a, int len) {
std::string st = "";
for (int i = 0; i < len-1; i++)
st += convert_to_string(a[i]) + ' ';
st += convert_to_string(a[len - 1]);
const char * c = st.c_str();
TiXmlText *text = new TiXmlText(c);
return text;
}
#endif // PARSER