-
Notifications
You must be signed in to change notification settings - Fork 2
/
XMLReader.cpp
95 lines (77 loc) · 2.64 KB
/
XMLReader.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
#include <stdio.h>
#include "XMLReader.h"
XMLReader::XMLReader(std::string path) {
videoTag = "video";
deviceTag = "device";
sourceTag = "source";
widthTag = "width";
heightTag = "height";
fullscreenTag = "fullscreen";
monitorTag = "monitor";
debugTag = "debug";
markersTag = "markers";
markerTag = "marker";
slidesTag = "slides";
slideTag = "slide";
TiXmlDocument doc(path);
bool loadOkay = doc.LoadFile();
if (loadOkay) {
TiXmlNode* pParent = &doc;
TiXmlElement* pElement;
TiXmlNode* pVideo = pParent->FirstChildElement(videoTag);
device = pVideo->FirstChildElement(deviceTag)->FirstChild()->Value(); // TODO: Validate the fields
source = pVideo->FirstChildElement(sourceTag)->FirstChild()->Value();
if ((pElement = pVideo->FirstChildElement(widthTag)))
width = pElement->FirstChild()->Value();
if ((pElement = pVideo->FirstChildElement(heightTag)))
height = pElement->FirstChild()->Value();
fullscreen = std::string("true").compare(pVideo->FirstChildElement(fullscreenTag)->FirstChild()->Value()) == 0;
monitor = pVideo->FirstChildElement(monitorTag)->FirstChild()->Value();
debug = std::string("true").compare(pVideo->FirstChildElement(debugTag)->FirstChild()->Value()) == 0;
TiXmlNode* pMarkers = pParent->FirstChildElement(markersTag)->FirstChildElement(markerTag);
for ( int i = 0 ; pMarkers != 0; pMarkers = pMarkers->NextSibling())
{
if (pMarkers->Type() == TiXmlNode::TINYXML_ELEMENT) // If it is of type ELEMENT (used to bypass commented nodes)
markers.insert(std::pair<int, std::string>(i++, pMarkers->FirstChild()->Value()));
}
TiXmlNode* pSlides = pParent->FirstChildElement(slidesTag)->FirstChildElement(slideTag);
for ( int i = 0 ; pSlides != 0; pSlides = pSlides->NextSibling())
{
if (pSlides->Type() == TiXmlNode::TINYXML_ELEMENT) // If it is of type ELEMENT (used to bypass commented nodes)
slides.insert(std::pair<int, std::string>(i++, pSlides->FirstChild()->Value()));
}
}
}
std::map<int, std::string> XMLReader::getMarkers(void) {
return markers;
}
std::map<int, std::string> XMLReader::getSlides(void) {
return slides;
}
std::string XMLReader::getDevice(void) {
return device;
}
std::string XMLReader::getSource(void) {
return source;
}
std::string XMLReader::getWidth(void) {
return width;
}
std::string XMLReader::getHeight(void) {
return height;
}
bool XMLReader::getFullscreen(void) {
return fullscreen;
}
std::string XMLReader::getMonitor(void) {
return monitor;
}
bool XMLReader::getDebug(void) {
return debug;
}
bool XMLReader::hasWidth(void) {
return std::string("").compare(width) != 0;
}
bool XMLReader::hasHeight(void) {
return std::string("").compare(height) != 0;
}