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>
53 typedef vector<string> stringVec;
54 typedef vector<string>::iterator stringVecIterator;
55 typedef vector<string>::const_iterator stringVecConstIterator;
57 typedef vector<time_t> timeVec;
58 typedef vector<time_t>::const_iterator timeVecConstIterator;
59 /***************************************************************************/
64 stringVec scheduleNames;
69 ScheduleTime(const ScheduleTime &other);
70 ScheduleTime &operator= (const ScheduleTime &other);
71 string getName(time_t dayStart);
74 void addStartTime(time_t time) { start.push_back(time); };
75 void addEndTime (time_t time) { end. push_back(time); };
76 void addScheduleName(string sched) { scheduleNames.push_back(sched); };
77 void setTailWind(double wnd) { tailWind = wnd; };
78 void setCrossWind(double wnd) { tailWind = wnd; };
80 double getTailWind() { return tailWind; };
81 double getCrossWind() { return crssWind; };
84 //typedef vector<ScheduleTime> ScheduleTimes;
85 /*****************************************************************************/
91 stringVec preferredRunways;
94 RunwayList(const RunwayList &other);
95 RunwayList& operator= (const RunwayList &other);
97 void set(string, string);
100 string getType() { return type; };
101 stringVec *getRwyList() { return &preferredRunways; };
102 string getRwyList(int j) { return preferredRunways[j]; };
105 typedef vector<RunwayList> RunwayListVec;
106 typedef vector<RunwayList>::iterator RunwayListVectorIterator;
107 typedef vector<RunwayList>::const_iterator RunwayListVecConstIterator;
110 /*****************************************************************************/
116 RunwayListVec rwyList;
118 //stringVec runwayNames;
123 RunwayGroup(const RunwayGroup &other);
124 RunwayGroup &operator= (const RunwayGroup &other);
126 void setName(string nm) { name = nm; };
127 void add(RunwayList list) { rwyList.push_back(list);};
128 void setActive(string aptId, double windSpeed, double windHeading, double maxTail, double maxCross);
130 int getNrActiveRunways() { return nrActive;};
131 void getActive(int i, string *name, string *type);
133 string getName() { return name; };
134 void clear() { rwyList.clear(); };
135 //void add(string, string);
138 typedef vector<RunwayGroup> PreferenceList;
139 typedef vector<RunwayGroup>::iterator PreferenceListIterator;
140 typedef vector<RunwayGroup>::const_iterator PreferenceListConstIterator;
141 /******************************************************************************/
143 class FGRunwayPreference : public XMLVisitor {
148 ScheduleTime comTimes; // Commercial Traffic;
149 ScheduleTime genTimes; // General Aviation;
150 ScheduleTime milTimes; // Military Traffic;
151 ScheduleTime currTimes; // Needed for parsing;
154 RunwayGroup rwyGroup;
155 PreferenceList preferences;
157 time_t processTime(string);
161 FGRunwayPreference();
162 FGRunwayPreference(const FGRunwayPreference &other);
164 FGRunwayPreference & operator= (const FGRunwayPreference &other);
165 ScheduleTime *getSchedule(const char *trafficType);
166 RunwayGroup *getGroup(const string groupName);
167 bool available() { return initialized; };
169 // Some overloaded virtual XMLVisitor members
170 virtual void startXML ();
171 virtual void endXML ();
172 virtual void startElement (const char * name, const XMLAttributes &atts);
173 virtual void endElement (const char * name);
174 virtual void data (const char * s, int len);
175 virtual void pi (const char * target, const char * data);
176 virtual void warning (const char * message, int line, int column);
177 virtual void error (const char * message, int line, int column);
194 double processPosition(string pos);
197 FGParking() { available = true;};
198 //FGParking(FGParking &other);
199 FGParking(double lat,
207 void setLatitude (string lat) { latitude = processPosition(lat); };
208 void setLongitude(string lon) { longitude = processPosition(lon); };
209 void setHeading (double hdg) { heading = hdg; };
210 void setRadius (double rad) { radius = rad; };
211 void setIndex (int idx) { index = idx; };
212 void setName (string name) { parkingName = name; };
213 void setType (string tpe) { type = tpe; };
214 void setCodes (string codes){ airlineCodes= codes;};
216 bool isAvailable () { return available;};
217 void setAvailable(bool val) { available = val; };
219 double getLatitude () { return latitude; };
220 double getLongitude() { return longitude; };
221 double getHeading () { return heading; };
222 double getRadius () { return radius; };
223 int getIndex () { return index; };
224 string getType () { return type; };
225 string getCodes () { return airlineCodes;};
226 string getName () { return parkingName; };
228 bool operator< (const FGParking &other) const {return radius < other.radius; };
231 typedef vector<FGParking> FGParkingVec;
232 typedef vector<FGParking>::iterator FGParkingVecIterator;
233 typedef vector<FGParking>::const_iterator FGParkingVecConstIterator;
236 class FGAirport : public XMLVisitor{
242 string _code; // depricated and can be removed
245 FGParkingVec parkings;
246 FGRunwayPreference rwyPrefs;
249 string prevTrafficType;
253 // Experimental keep a running average of wind dir and speed to prevent
254 // Erratic runway changes.
255 // Note: I should add these to the copy constructor and assigment operator to be
257 double avWindHeading [10];
258 double avWindSpeed [10];
262 FGAirport(const FGAirport &other);
263 //operator= (FGAirport &other);
264 FGAirport(string id, double lon, double lat, double elev, string name, bool has_metar);
265 void getActiveRunway(string trafficType, int action, string *runway);
266 void chooseRunwayFallback(string *runway);
267 bool getAvailableParking(double *lat, double *lon, double *heading, int *gate, double rad, string fltype,
268 string acType, string airline);
269 void getParking (int id, double *lat, double* lon, double *heading);
270 FGParking *getParking(int i); // { if (i < parkings.size()) return parkings[i]; else return 0;};
271 void releaseParking(int id);
272 string getParkingName(int i);
273 const string getId() const { return _id;};
274 const string &getName() const { return _name;};
275 FGAirport *getAddress() { return this; };
276 double getLongitude() { return _longitude;};
277 double getLatitude() { return _latitude; };
278 double getElevation() { return _elevation;};
279 bool getMetar() { return _has_metar;};
282 void setId(string id) { _id = id;};
283 void setMetar(bool value) { _has_metar = value; };
285 void setRwyUse(FGRunwayPreference& ref);
287 // Some overloaded virtual XMLVisitor members
288 virtual void startXML ();
289 virtual void endXML ();
290 virtual void startElement (const char * name, const XMLAttributes &atts);
291 virtual void endElement (const char * name);
292 virtual void data (const char * s, int len);
293 virtual void pi (const char * target, const char * data);
294 virtual void warning (const char * message, int line, int column);
295 virtual void error (const char * message, int line, int column);
298 typedef map < string, FGAirport > airport_map;
299 typedef airport_map::iterator airport_map_iterator;
300 typedef airport_map::const_iterator const_airport_map_iterator;
302 typedef vector < FGAirport * > airport_list;
305 class FGAirportList {
309 airport_map airports_by_id;
310 airport_list airports_array;
311 set < string > ai_dirs;
321 // add an entry to the list
322 void add( const string id, const double longitude, const double latitude,
323 const double elevation, const string name, const bool has_metar );
325 // search for the specified id.
326 // Returns true if successful, otherwise returns false.
327 // On success, airport data is returned thru "airport" pointer.
328 // "airport" is not changed if "apt" is not found.
329 FGAirport search( const string& id );
331 // search for the airport closest to the specified position
332 // (currently a linear inefficient search so it's probably not
333 // best to use this at runtime.) If with_metar is true, then only
334 // return station id's marked as having metar data.
335 FGAirport search( double lon_deg, double lat_deg, bool with_metar );
337 // search and return a pointer;
338 FGAirport* search( const string& id, FGAirport *result);
341 * Return the number of airports in the list.
347 * Return a specific airport, by position.
349 const FGAirport *getAirport( int index ) const;
353 * Mark the specified airport record as not having metar
355 void no_metar( const string &id );
358 * Mark the specified airport record as (yes) having metar
360 void has_metar( const string &id );
365 #endif // _FG_SIMPLE_HXX