1 // simple.hxx -- a really simplistic class to manage airport ID,
2 // lat, lon of the center of one of it's runways, and
5 // Written by Curtis Olson, started April 1998.
6 // Updated by Durk Talsma, started December 2004.
8 // Copyright (C) 1998 Curtis L. Olson - http://www.flightgear.org/~curt
10 // This program is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License as
12 // published by the Free Software Foundation; either version 2 of the
13 // License, or (at your option) any later version.
15 // This program is distributed in the hope that it will be useful, but
16 // WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // General Public License for more details.
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the Free Software
22 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 #ifndef _FG_SIMPLE_HXX
28 #define _FG_SIMPLE_HXX
32 # error This library requires C++
40 #include <simgear/compiler.h>
41 #include <simgear/xml/easyxml.hxx>
51 typedef vector<string> stringVec;
52 typedef vector<string>::iterator stringVecIterator;
53 typedef vector<string>::const_iterator stringVecConstIterator;
55 typedef vector<time_t> timeVec;
56 typedef vector<time_t>::const_iterator timeVecConstIterator;
57 /***************************************************************************/
62 stringVec scheduleNames;
67 ScheduleTime(const ScheduleTime &other);
68 ScheduleTime &operator= (const ScheduleTime &other);
69 string getName(time_t dayStart);
72 void addStartTime(time_t time) { start.push_back(time); };
73 void addEndTime (time_t time) { end. push_back(time); };
74 void addScheduleName(string sched) { scheduleNames.push_back(sched); };
75 void setTailWind(double wnd) { tailWind = wnd; };
76 void setCrossWind(double wnd) { tailWind = wnd; };
78 double getTailWind() { return tailWind; };
79 double getCrossWind() { return crssWind; };
82 //typedef vector<ScheduleTime> ScheduleTimes;
83 /*****************************************************************************/
89 stringVec preferredRunways;
92 RunwayList(const RunwayList &other);
93 RunwayList& operator= (const RunwayList &other);
95 void set(string, string);
98 string getType() { return type; };
99 stringVec *getRwyList() { return &preferredRunways; };
100 string getRwyList(int j) { return preferredRunways[j]; };
103 typedef vector<RunwayList> RunwayListVec;
104 typedef vector<RunwayList>::iterator RunwayListVectorIterator;
105 typedef vector<RunwayList>::const_iterator RunwayListVecConstIterator;
108 /*****************************************************************************/
114 RunwayListVec rwyList;
116 //stringVec runwayNames;
121 RunwayGroup(const RunwayGroup &other);
122 RunwayGroup &operator= (const RunwayGroup &other);
124 void setName(string nm) { name = nm; };
125 void add(RunwayList list) { rwyList.push_back(list);};
126 void setActive(string aptId, double windSpeed, double windHeading, double maxTail, double maxCross);
128 int getNrActiveRunways() { return nrActive;};
129 void getActive(int i, string *name, string *type);
131 string getName() { return name; };
132 void clear() { rwyList.clear(); };
133 //void add(string, string);
136 typedef vector<RunwayGroup> PreferenceList;
137 typedef vector<RunwayGroup>::iterator PreferenceListIterator;
138 typedef vector<RunwayGroup>::const_iterator PreferenceListConstIterator;
139 /******************************************************************************/
141 class FGRunwayPreference : public XMLVisitor {
146 ScheduleTime comTimes; // Commercial Traffic;
147 ScheduleTime genTimes; // General Aviation;
148 ScheduleTime milTimes; // Military Traffic;
149 ScheduleTime currTimes; // Needed for parsing;
152 RunwayGroup rwyGroup;
153 PreferenceList preferences;
155 time_t processTime(string);
159 FGRunwayPreference();
160 FGRunwayPreference(const FGRunwayPreference &other);
162 FGRunwayPreference & operator= (const FGRunwayPreference &other);
163 ScheduleTime *getSchedule(const char *trafficType);
164 RunwayGroup *getGroup(const string groupName);
165 bool available() { return initialized; };
167 // Some overloaded virtual XMLVisitor members
168 virtual void startXML ();
169 virtual void endXML ();
170 virtual void startElement (const char * name, const XMLAttributes &atts);
171 virtual void endElement (const char * name);
172 virtual void data (const char * s, int len);
173 virtual void pi (const char * target, const char * data);
174 virtual void warning (const char * message, int line, int column);
175 virtual void error (const char * message, int line, int column);
192 double processPosition(string pos);
195 FGParking() { available = true;};
196 //FGParking(FGParking &other);
197 FGParking(double lat,
205 void setLatitude (string lat) { latitude = processPosition(lat); };
206 void setLongitude(string lon) { longitude = processPosition(lon); };
207 void setHeading (double hdg) { heading = hdg; };
208 void setRadius (double rad) { radius = rad; };
209 void setIndex (int idx) { index = idx; };
210 void setName (string name) { parkingName = name; };
211 void setType (string tpe) { type = tpe; };
212 void setCodes (string codes){ airlineCodes= codes;};
214 bool isAvailable () { return available;};
215 void setAvailable(bool val) { available = val; };
217 double getLatitude () { return latitude; };
218 double getLongitude() { return longitude; };
219 double getHeading () { return heading; };
220 double getRadius () { return radius; };
221 int getIndex () { return index; };
222 string getType () { return type; };
223 string getCodes () { return airlineCodes;};
224 string getName () { return parkingName; };
226 bool operator< (const FGParking &other) const {return radius < other.radius; };
229 typedef vector<FGParking> FGParkingVec;
230 typedef vector<FGParking>::iterator FGParkingVecIterator;
231 typedef vector<FGParking>::const_iterator FGParkingVecConstIterator;
234 class FGAirport : public XMLVisitor{
240 string _code; // depricated and can be removed
243 FGParkingVec parkings;
244 FGRunwayPreference rwyPrefs;
247 string prevTrafficType;
251 // Experimental keep a running average of wind dir and speed to prevent
252 // Erratic runway changes.
253 // Note: I should add these to the copy constructor and assigment operator to be
255 double avWindHeading [10];
256 double avWindSpeed [10];
260 FGAirport(const FGAirport &other);
261 //operator= (FGAirport &other);
262 FGAirport(string id, double lon, double lat, double elev, string name, bool has_metar);
263 void getActiveRunway(string trafficType, int action, string *runway);
264 void chooseRunwayFallback(string *runway);
265 bool getAvailableParking(double *lat, double *lon, double *heading, int *gate, double rad, string fltype,
266 string acType, string airline);
267 void getParking (int id, double *lat, double* lon, double *heading);
268 FGParking *getParking(int i); // { if (i < parkings.size()) return parkings[i]; else return 0;};
269 void releaseParking(int id);
270 string getParkingName(int i);
271 const string getId() const { return _id;};
272 const string &getName() const { return _name;};
273 FGAirport *getAddress() { return this; };
274 double getLongitude() { return _longitude;};
275 double getLatitude() { return _latitude; };
276 double getElevation() { return _elevation;};
277 bool getMetar() { return _has_metar;};
280 void setId(string id) { _id = id;};
281 void setMetar(bool value) { _has_metar = value; };
283 void setRwyUse(FGRunwayPreference& ref);
285 // Some overloaded virtual XMLVisitor members
286 virtual void startXML ();
287 virtual void endXML ();
288 virtual void startElement (const char * name, const XMLAttributes &atts);
289 virtual void endElement (const char * name);
290 virtual void data (const char * s, int len);
291 virtual void pi (const char * target, const char * data);
292 virtual void warning (const char * message, int line, int column);
293 virtual void error (const char * message, int line, int column);
296 typedef map < string, FGAirport > airport_map;
297 typedef airport_map::iterator airport_map_iterator;
298 typedef airport_map::const_iterator const_airport_map_iterator;
300 typedef vector < FGAirport * > airport_list;
303 class FGAirportList {
307 airport_map airports_by_id;
308 airport_list airports_array;
318 // add an entry to the list
319 void add( const string id, const double longitude, const double latitude,
320 const double elevation, const string name, const bool has_metar );
322 // search for the specified id.
323 // Returns true if successful, otherwise returns false.
324 // On success, airport data is returned thru "airport" pointer.
325 // "airport" is not changed if "apt" is not found.
326 FGAirport search( const string& id );
328 // search for the airport closest to the specified position
329 // (currently a linear inefficient search so it's probably not
330 // best to use this at runtime.) If with_metar is true, then only
331 // return station id's marked as having metar data.
332 FGAirport search( double lon_deg, double lat_deg, bool with_metar );
334 // search and return a pointer;
335 FGAirport* search( const string& id, FGAirport *result);
338 * Return the number of airports in the list.
344 * Return a specific airport, by position.
346 const FGAirport *getAirport( int index ) const;
350 * Mark the specified airport record as not having metar
352 void no_metar( const string &id );
355 * Mark the specified airport record as (yes) having metar
357 void has_metar( const string &id );
362 #endif // _FG_SIMPLE_HXX