]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Mathias Fröhölöiööhlich:
[flightgear.git] / src / Airports / simple.hxx
1 // simple.hxx -- a really simplistic class to manage airport ID,
2 //                 lat, lon of the center of one of it's runways, and 
3 //                 elevation in feet.
4 //
5 // Written by Curtis Olson, started April 1998.
6 // Updated by Durk Talsma, started December 2004.
7 //
8 // Copyright (C) 1998  Curtis L. Olson  - http://www.flightgear.org/~curt
9 //
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.
14 //
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.
19 //
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.
23 //
24 // $Id$
25
26
27 #ifndef _FG_SIMPLE_HXX
28 #define _FG_SIMPLE_HXX
29
30
31 #ifndef __cplusplus                                                          
32 # error This library requires C++
33 #endif                                   
34
35
36 #ifdef HAVE_CONFIG_H
37 #  include <config.h>
38 #endif
39
40 #include <simgear/compiler.h>
41 #include <simgear/xml/easyxml.hxx>
42
43 #include STL_STRING
44 #include <map>
45 #include <set>
46 #include <vector>
47
48 SG_USING_STD(string);
49 SG_USING_STD(map);
50 SG_USING_STD(set);
51 SG_USING_STD(vector);
52
53 typedef vector<string> stringVec;
54 typedef vector<string>::iterator stringVecIterator;
55 typedef vector<string>::const_iterator stringVecConstIterator;
56
57 typedef vector<time_t> timeVec;
58 typedef vector<time_t>::const_iterator timeVecConstIterator;
59 /***************************************************************************/
60 class ScheduleTime {
61 private:
62   timeVec   start;
63   timeVec   end;
64   stringVec scheduleNames;
65   double tailWind;
66   double crssWind;
67 public:
68   ScheduleTime() {};
69   ScheduleTime(const ScheduleTime &other);
70   ScheduleTime &operator= (const ScheduleTime &other);
71   string getName(time_t dayStart);
72
73   void clear();
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;                        };
79
80   double getTailWind()  { return tailWind;                               };
81   double getCrossWind() { return crssWind;                               };
82 };
83
84 //typedef vector<ScheduleTime> ScheduleTimes;
85 /*****************************************************************************/
86
87 class RunwayList
88 {
89 private:
90   string type;
91   stringVec preferredRunways;
92 public:
93   RunwayList() {};
94   RunwayList(const RunwayList &other);
95   RunwayList& operator= (const RunwayList &other);
96
97   void set(string, string);
98   void clear();
99
100   string getType() { return type; };
101   stringVec *getRwyList() { return &preferredRunways;    };
102   string getRwyList(int j) { return preferredRunways[j]; };
103 };
104
105 typedef vector<RunwayList> RunwayListVec;
106 typedef vector<RunwayList>::iterator RunwayListVectorIterator;
107 typedef vector<RunwayList>::const_iterator RunwayListVecConstIterator;
108
109
110 /*****************************************************************************/
111
112 class RunwayGroup
113 {
114 private:
115   string name;
116   RunwayListVec rwyList;
117   int active;
118   //stringVec runwayNames;
119   int choice[2];
120   int nrActive;
121 public:
122   RunwayGroup() {};
123   RunwayGroup(const RunwayGroup &other);
124   RunwayGroup &operator= (const RunwayGroup &other);
125
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);
129
130   int getNrActiveRunways() { return nrActive;};
131   void getActive(int i, string *name, string *type);
132
133   string getName() { return name; };
134   void clear() { rwyList.clear(); }; 
135   //void add(string, string);
136 };
137
138 typedef vector<RunwayGroup> PreferenceList;
139 typedef vector<RunwayGroup>::iterator PreferenceListIterator;
140 typedef vector<RunwayGroup>::const_iterator PreferenceListConstIterator;
141 /******************************************************************************/
142
143 class FGRunwayPreference  : public XMLVisitor {
144 private:
145   string value;
146   string scheduleName;
147
148   ScheduleTime comTimes; // Commercial Traffic;
149   ScheduleTime genTimes; // General Aviation;
150   ScheduleTime milTimes; // Military Traffic;
151   ScheduleTime currTimes; // Needed for parsing;
152
153   RunwayList  rwyList;
154   RunwayGroup rwyGroup;
155   PreferenceList preferences;
156
157   time_t processTime(string);
158   bool initialized;
159
160 public:
161   FGRunwayPreference();
162   FGRunwayPreference(const FGRunwayPreference &other);
163   
164   FGRunwayPreference & operator= (const FGRunwayPreference &other);
165   ScheduleTime *getSchedule(const char *trafficType);
166   RunwayGroup *getGroup(const string groupName);
167   bool available() { return initialized; };
168
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);
178 };
179
180 class FGParking {
181 private:
182   double latitude;
183   double longitude;
184   double heading;
185   double radius;
186   int index;
187   string parkingName;
188   string type;
189   string airlineCodes;
190  
191
192   bool available;
193
194   double processPosition(string pos);
195
196 public:
197   FGParking() { available = true;};
198   //FGParking(FGParking &other);
199   FGParking(double lat,
200             double lon,
201             double hdg,
202             double rad,
203             int idx,
204             string name,
205             string tpe,
206             string codes);
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;};
215
216   bool isAvailable ()         { return available;};
217   void setAvailable(bool val) { available = val; };
218   
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; };
227
228   bool operator< (const FGParking &other) const {return radius < other.radius; };
229 };
230
231 typedef vector<FGParking> FGParkingVec;
232 typedef vector<FGParking>::iterator FGParkingVecIterator;
233 typedef vector<FGParking>::const_iterator FGParkingVecConstIterator;
234
235
236 class FGAirport : public XMLVisitor{
237 private:
238   string _id;
239   double _longitude;
240   double _latitude;
241   double _elevation;
242   string _code;               // depricated and can be removed
243   string _name;
244   bool _has_metar;
245   FGParkingVec parkings;
246   FGRunwayPreference rwyPrefs;
247
248  time_t lastUpdate;
249   string prevTrafficType;
250   stringVec landing;
251   stringVec takeoff;
252
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
256   // constistent
257   double avWindHeading [10];
258   double avWindSpeed   [10];
259
260 public:
261   FGAirport();
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;};
280   
281
282   void setId(string id) { _id = id;};
283   void setMetar(bool value) { _has_metar = value; };
284
285   void setRwyUse(FGRunwayPreference& ref);
286
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);
296 };
297
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;
301
302 typedef vector < FGAirport * > airport_list;
303
304
305 class FGAirportList {
306
307 private:
308
309     airport_map airports_by_id;
310     airport_list airports_array;
311     set < string > ai_dirs;
312
313 public:
314
315     // Constructor (new)
316     FGAirportList();
317
318     // Destructor
319     ~FGAirportList();
320
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 );
324
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 );
330
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 );
336
337     // search and return a pointer;
338     FGAirport* search( const string& id, FGAirport *result);
339
340     /**
341      * Return the number of airports in the list.
342      */
343     int size() const;
344
345
346     /**
347      * Return a specific airport, by position.
348      */
349     const FGAirport *getAirport( int index ) const;
350
351
352     /**
353      * Mark the specified airport record as not having metar
354      */
355     void no_metar( const string &id );
356
357     /**
358      * Mark the specified airport record as (yes) having metar
359      */
360     void has_metar( const string &id );
361
362 };
363
364
365 #endif // _FG_SIMPLE_HXX
366
367