-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlutils.h
executable file
·119 lines (88 loc) · 2.24 KB
/
xmlutils.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
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
/*
* File: xmlutils.h
* Author: guilh
*
* Created on 3 de outubro de 2019, 10:33
*/
#ifndef XMLUTILS_H
#define XMLUTILS_H
#include <exception>
#include <string>
#include "tinyxml/tinyxml.h"
using namespace std;
class MissingSVGShapeException : public std::exception {
private:
std::string name;
std::string msg;
public:
MissingSVGShapeException(const char* name) :
exception(), name(name) {
msg += "Missing <";
msg += name;
msg += ">";
}
virtual ~MissingSVGShapeException() noexcept {
}
const char* what() const noexcept {
return msg.c_str();
}
};
class IOException : public exception {
private:
string msg;
public:
IOException(const string& s) :
exception(), msg(s) {
}
IOException(const char* msg) :
exception(), msg(msg) {
}
virtual ~IOException() noexcept {
}
const char* what() const noexcept {
return msg.c_str();
}
};
class AttributeException : public exception {
private:
int type;
public:
AttributeException(int type) :
exception(), type(type) {
}
virtual ~AttributeException() noexcept {
}
const char* what() const noexcept {
switch (type) {
case TIXML_NO_ATTRIBUTE:
return "missing attribute";
case TIXML_WRONG_TYPE:
return "wrong type";
default:
return "unknown";
}
}
};
class MissingElementException : public exception {
private:
string tag;
string msg;
public:
MissingElementException(const string& s) :
exception(), tag(s) {
msg = "Missing tag <" + s + ">";
}
MissingElementException(const char* tag) :
exception(), tag(tag) {
msg = string("Missing tag <") + tag + ">";
}
virtual ~MissingElementException() noexcept {
}
const char* what() const noexcept {
return msg.c_str();
}
};
double readDoubleAttribute(const TiXmlElement* e, const char* name);
const char* readAttribute(const TiXmlElement* e, const char* name);
const char* getTextOrThrow(const TiXmlElement* e);
#endif /* XMLUTILS_H */