Debian Codegraph @

src/Airports/runwayprefloader.cxx

raw symbols SCIP
1 /*
2 * SPDX-License-Identifier: GPL-2.0-or-later
3 */
4
5 #include <cstdlib>
6 #include <cstring>
7
8 #include <simgear/debug/logstream.hxx>
9
10 #include "runwayprefloader.hxx"
11
12
13 using namespace std;
14
15
16 FGRunwayPreferenceXMLLoader::FGRunwayPreferenceXMLLoader(FGRunwayPreference* p) : XMLVisitor(), _pref(p) {}
17
18 void FGRunwayPreferenceXMLLoader::startXML()
19 {
20 // cout << "Start XML" << endl;
21 }
22
23 void FGRunwayPreferenceXMLLoader::endXML()
24 {
25 //cout << "End XML" << endl;
26 }
27
28 void FGRunwayPreferenceXMLLoader::startElement(const char* name, const XMLAttributes& atts)
29 {
30 //cout << "StartElement " << name << endl;
31 value = string("");
32 if (!(strcmp(name, "wind"))) {
33 //cerr << "Will be processing Wind" << endl;
34 for (int i = 0; i < atts.size(); i++) {
35 //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
36 //attname = atts.getName(i);
37 if (atts.getName(i) == string("tail")) {
38 //cerr << "Tail Wind = " << atts.getValue(i) << endl;
39 currTimes.setTailWind(atof(atts.getValue(i)));
40 }
41 if (atts.getName(i) == string("cross")) {
42 //cerr << "Cross Wind = " << atts.getValue(i) << endl;
43 currTimes.setCrossWind(atof(atts.getValue(i)));
44 }
45 }
46 }
47 if (!(strcmp(name, "time"))) {
48 //cerr << "Will be processing time" << endl;
49 for (int i = 0; i < atts.size(); i++) {
50 if (atts.getName(i) == string("start")) {
51 //cerr << "Start Time = " << atts.getValue(i) << endl;
52 currTimes.addStartTime(processTime(atts.getValue(i)));
53 }
54 if (atts.getName(i) == string("end")) {
55 //cerr << "End time = " << atts.getValue(i) << endl;
56 currTimes.addEndTime(processTime(atts.getValue(i)));
57 }
58 if (atts.getName(i) == string("schedule")) {
59 //cerr << "Schedule Name = " << atts.getValue(i) << endl;
60 currTimes.addScheduleName(atts.getValue(i));
61 }
62 }
63 }
64 if (!(strcmp(name, "takeoff"))) {
65 rwyList.clear();
66 }
67 if (!(strcmp(name, "landing"))) {
68 rwyList.clear();
69 }
70 if (!(strcmp(name, "schedule"))) {
71 for (int i = 0; i < atts.size(); i++) {
72 //cout << " " << atts.getName(i) << '=' << atts.getValue(i) << endl;
73 //attname = atts.getName(i);
74 if (atts.getName(i) == string("name")) {
75 //cerr << "Schedule name = " << atts.getValue(i) << endl;
76 scheduleName = atts.getValue(i);
77 }
78 }
79 }
80 }
81
82 //based on a string containing hour and minute, return nr seconds since day start.
83 time_t FGRunwayPreferenceXMLLoader::processTime(const string& tme)
84 {
85 string hour = tme.substr(0, tme.find(":", 0));
86 string minute = tme.substr(tme.find(":", 0) + 1, tme.length());
87
88 //cerr << "hour = " << hour << " Minute = " << minute << endl;
89 return (atoi(hour.c_str()) * 3600 + atoi(minute.c_str()) * 60);
90 }
91
92 void FGRunwayPreferenceXMLLoader::endElement(const char* name)
93 {
94 //cout << "End element " << name << endl;
95 if (!(strcmp(name, "rwyuse"))) {
96 _pref->setInitialized(true);
97 }
98 if (!(strcmp(name, "com"))) { // Commercial Traffic
99 //cerr << "Setting time table for commercial traffic" << endl;
100 _pref->setComTimes(currTimes);
101 currTimes.clear();
102 }
103 if (!(strcmp(name, "gen"))) { // General Aviation
104 //cerr << "Setting time table for general aviation" << endl;
105 _pref->setGenTimes(currTimes);
106 currTimes.clear();
107 }
108 if (!(strcmp(name, "mil"))) { // Military Traffic
109 //cerr << "Setting time table for military traffic" << endl;
110 _pref->setMilTimes(currTimes);
111 currTimes.clear();
112 }
113 if (!(strcmp(name, "ul"))) { // Military Traffic
114 //cerr << "Setting time table for military traffic" << endl;
115 _pref->setULTimes(currTimes);
116 currTimes.clear();
117 }
118
119
120 if (!(strcmp(name, "takeoff"))) {
121 //cerr << "Adding takeoff: " << value << endl;
122 rwyList.set(name, value);
123 rwyGroup.add(rwyList);
124 }
125 if (!(strcmp(name, "landing"))) {
126 //cerr << "Adding landing: " << value << endl;
127 rwyList.set(name, value);
128 rwyGroup.add(rwyList);
129 }
130 if (!(strcmp(name, "schedule"))) {
131 //cerr << "Adding schedule" << scheduleName << endl;
132 rwyGroup.setName(scheduleName);
133 //rwyGroup.addRunways(rwyList);
134 _pref->addRunwayGroup(rwyGroup);
135 rwyGroup.clear();
136 //exit(1);
137 }
138 }
139
140 void FGRunwayPreferenceXMLLoader::data(const char* s, int len)
141 {
142 string token = string(s, len);
143 //cout << "Character data " << string(s,len) << endl;
144 //if ((token.find(" ") == string::npos && (token.find('\n')) == string::npos))
145 // value += token;
146 //else
147 // value = string("");
148 value += token;
149 }
150
151 void FGRunwayPreferenceXMLLoader::pi(const char* target, const char* data)
152 {
153 //cout << "Processing instruction " << target << ' ' << data << endl;
154 }
155
156 void FGRunwayPreferenceXMLLoader::warning(const char* message, int line, int column)
157 {
158 SG_LOG(SG_IO, SG_WARN, "Warning: " << message << " (" << line << ',' << column << ')');
159 }
160
161 void FGRunwayPreferenceXMLLoader::error(const char* message, int line, int column)
162 {
163 SG_LOG(SG_IO, SG_ALERT, "Error: " << message << " (" << line << ',' << column << ')');
164 }