]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Fix line endings
[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 #include <simgear/math/point3d.hxx>
40
41 #include <simgear/compiler.h>
42 //#include <simgear/xml/easyxml.hxx>
43
44 #include STL_STRING
45 #include <map>
46 #include <set>
47 #include <vector>
48
49 #include "runwayprefs.hxx"
50 #include "parking.hxx"
51 #include "groundnetwork.hxx"
52 #include "dynamics.hxx"
53
54 SG_USING_STD(string);
55 SG_USING_STD(map);
56 SG_USING_STD(set);
57 SG_USING_STD(vector);
58
59
60
61
62 /***************************************************************************************
63  *
64  **************************************************************************************/
65 class FGAirport {
66 private:
67   string _id;
68   double _longitude;    // degrees
69   double _latitude;     // degrees
70   double _elevation;    // ft
71   string _name;
72   bool _has_metar;
73   FGAirportDynamics *dynamics;
74
75 public:
76   FGAirport();
77   // FGAirport(const FGAirport &other);
78   FGAirport(const string& id, double lon, double lat, double elev, const string& name, bool has_metar);
79   ~FGAirport();
80
81   string getId() const { return _id;};
82   const string &getName() const { return _name;};
83   double getLongitude() const { return _longitude;};
84   // Returns degrees
85   double getLatitude()  const { return _latitude; };
86   // Returns ft
87   double getElevation() const { return _elevation;};
88   bool   getMetar()     const { return _has_metar;};
89
90   void setId(const string& id) { _id = id;};
91   void setMetar(bool value) { _has_metar = value; };
92
93   FGAirportDynamics *getDynamics();
94 private:
95   FGAirport operator=(FGAirport &other);
96   FGAirport(const FGAirport&);
97 };
98
99 typedef map < string, FGAirport* > airport_map;
100 typedef airport_map::iterator airport_map_iterator;
101 typedef airport_map::const_iterator const_airport_map_iterator;
102
103 typedef vector < FGAirport * > airport_list;
104 typedef airport_list::iterator airport_list_iterator;
105 typedef airport_list::const_iterator const_airport_list_iterator;
106
107
108 class FGAirportList {
109
110 private:
111
112     airport_map airports_by_id;
113     airport_list airports_array;
114   //set < string > ai_dirs;
115
116 public:
117
118     // Constructor (new)
119     FGAirportList();
120
121     // Destructor
122     ~FGAirportList();
123
124     // add an entry to the list
125     void add( const string& id, const double longitude, const double latitude,
126               const double elevation, const string& name, const bool has_metar );
127
128     // search for the specified id.
129     // Returns NULL if unsucessfull.
130     FGAirport* search( const string& id );
131         
132     // Search for the next airport in ASCII sequence to the supplied id.
133     // eg. id = "KDC" or "KDCA" would both return "KDCA".
134     // If exact = true then only exact matches are returned.
135     // NOTE: Numbers come prior to A-Z in ASCII sequence so id = "LD" would return "LD57", not "LDDP"
136     // Implementation assumes airport codes are unique.
137     // Returns NULL if unsucessfull.
138     const FGAirport* findFirstById( const string& id, bool exact = false );
139
140     // search for the airport closest to the specified position
141     // (currently a linear inefficient search so it's probably not
142     // best to use this at runtime.)  If with_metar is true, then only
143     // return station id's marked as having metar data.
144         // Returns NULL if fails (unlikely unless none have metar and with_metar spec'd!)
145     FGAirport* search( double lon_deg, double lat_deg, bool with_metar );
146
147     /**
148      * Return the number of airports in the list.
149      */
150     int size() const;
151
152     /**
153      * Return a specific airport, by position.
154      */
155     const FGAirport *getAirport( unsigned int index ) const;
156         
157     /**
158      * Return a pointer to the raw airport list
159      */
160      inline const airport_list* getAirportList() { return(&airports_array); }
161
162     /**
163      * Mark the specified airport record as not having metar
164      */
165     void no_metar( const string &id );
166
167     /**
168      * Mark the specified airport record as (yes) having metar
169      */
170     void has_metar( const string &id );
171
172 };
173
174 // find basic airport location info from airport database
175 const FGAirport *fgFindAirportID( const string& id);
176
177 // get airport elevation
178 double fgGetAirportElev( const string& id );
179
180 // get airport position
181 Point3D fgGetAirportPos( const string& id );
182
183 #endif // _FG_SIMPLE_HXX
184
185