-
Notifications
You must be signed in to change notification settings - Fork 0
/
HighwayProjectXml.h
158 lines (130 loc) · 5.16 KB
/
HighwayProjectXml.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
/*
* File: HighwayProject.h
* Author: bdupont
*
* Created on September 19, 2011, 8:31 PM
*/
#ifndef _HIGHWAYPROJECTXML_H
#define _HIGHWAYPROJECTXML_H
#include <list>
#include <map>
#include <stdlib.h>
#include "tinyxml.h"
#include "HighwayXml.h"
#include "VehicleGeneratorXml.h"
#include "WifiConfigurationXml.h"
#include "TrafficLightGeneratorXml.h"
using namespace std;
class HighwayProjectXml {
private:
int m_numberOfRuns;
int m_totalTimeInSeconds;
double m_dt;
list<HighwayXml> m_highways;
list<WifiConfigurationXml> m_wifiConfigs;
list<VehicleGeneratorXml> m_vehicleGenerators;
list<TrafficLightGeneratorXml> m_trafficLightGenerators;
public:
list<HighwayXml> GetHighways() {
return m_highways;
}
void SetHighways(list<HighwayXml> highways) {
m_highways = highways;
}
int GetNumberOfRuns() {
return m_numberOfRuns;
}
void SetNumberOfRuns(int numberOfRuns) {
m_numberOfRuns = numberOfRuns;
}
int GetTotalTimeInSeconds() {
return m_totalTimeInSeconds;
}
double GetDt() {
return m_dt;
}
void SetDt(double dt) {
m_dt = dt;
}
void SetTotalTimeInSeconds(int totalTimeInSeconds) {
m_totalTimeInSeconds = totalTimeInSeconds;
}
list<VehicleGeneratorXml> GetVehicleGenerators() {
return m_vehicleGenerators;
}
void SetVehicleGenerators(list<VehicleGeneratorXml> vehicleGenerators) {
m_vehicleGenerators = vehicleGenerators;
}
list<WifiConfigurationXml> GetWifiConfigs() {
return m_wifiConfigs;
}
void SetWifiConfigs(list<WifiConfigurationXml> wifiConfigs) {
m_wifiConfigs = wifiConfigs;
}
list<TrafficLightGeneratorXml> GetTrafficLightGenerators() const {
return m_trafficLightGenerators;
}
void SetTrafficLightGenerators(list<TrafficLightGeneratorXml> trafficLightGenerators) {
this->m_trafficLightGenerators = trafficLightGenerators;
}
void LoadFromXml(TiXmlHandle root) {
m_numberOfRuns = 1;
m_totalTimeInSeconds = 30;
m_dt = 0.1;
m_highways = list<HighwayXml > ();
m_wifiConfigs = list<WifiConfigurationXml > ();
m_vehicleGenerators = list<VehicleGeneratorXml > ();
m_trafficLightGenerators = list<TrafficLightGeneratorXml > ();
TiXmlElement* rootPtr = root.Element();
if (rootPtr != NULL) {
rootPtr->QueryIntAttribute("numberOfRuns", &m_numberOfRuns);
rootPtr->QueryIntAttribute("totalTimeInSeconds", &m_totalTimeInSeconds);
rootPtr->QueryDoubleAttribute("dt", &m_dt);
TiXmlHandle highwaysRoot = root.FirstChildElement("highways");
TiXmlElement* highwaysRootPtr = highwaysRoot.Element();
if (highwaysRootPtr) {
TiXmlElement* highwayPtr = highwaysRootPtr->FirstChildElement("highway");
for (; highwayPtr; highwayPtr = highwayPtr->NextSiblingElement()) {
HighwayXml newHighway;
TiXmlHandle highwayHandle = TiXmlHandle(highwayPtr);
newHighway.LoadFromXml(highwayHandle);
m_highways.push_back(newHighway);
}
}
TiXmlHandle wifiConfigRoot = root.FirstChildElement("wifiConfigurations");
TiXmlElement* wifiConfigRootPtr = wifiConfigRoot.Element();
if (wifiConfigRootPtr) {
TiXmlElement* wifiConfig = wifiConfigRootPtr->FirstChildElement("wifiConfiguration");
for (; wifiConfig; wifiConfig = wifiConfig->NextSiblingElement()) {
WifiConfigurationXml newWifi;
TiXmlHandle wifiHandle = TiXmlHandle(wifiConfig);
newWifi.LoadFromXml(wifiHandle);
m_wifiConfigs.push_back(newWifi);
}
}
TiXmlHandle generatorRoot = root.FirstChildElement("vehicleGenerators");
TiXmlElement* generatorRootPtr = generatorRoot.Element();
if (generatorRootPtr) {
TiXmlElement* generator = generatorRoot.FirstChildElement("vehicleGenerator").Element();
for (; generator; generator = generator->NextSiblingElement()) {
VehicleGeneratorXml newGenerator;
TiXmlHandle generatorHandle = TiXmlHandle(generator);
newGenerator.LoadFromXml(generatorHandle);
m_vehicleGenerators.push_back(newGenerator);
}
}
TiXmlHandle trafficRoot = root.FirstChildElement("trafficLightGenerators");
TiXmlElement* trafficRootPtr = trafficRoot.Element();
if (trafficRootPtr) {
TiXmlElement* traffic = trafficRoot.FirstChildElement("trafficGenerator").Element();
for(; traffic; traffic = traffic->NextSiblingElement()) {
TiXmlHandle trafficHandle(traffic);
TrafficLightGeneratorXml tlGenerator;
tlGenerator.LoadFromXml(trafficHandle);
m_trafficLightGenerators.push_back(tlGenerator);
}
}
}
}
};
#endif /* _HIGHWAYPROJECTXML_H */