]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
- FGBinding now extends FGConditional
[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 //
7 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 //
23 // $Id$
24
25
26 #ifndef _SIMPLE_HXX
27 #define _SIMPLE_HXX
28
29
30 #ifndef __cplusplus                                                          
31 # error This library requires C++
32 #endif                                   
33
34
35 #ifdef HAVE_CONFIG_H
36 #  include <config.h>
37 #endif
38
39 #include <simgear/compiler.h>
40
41 #ifdef SG_HAVE_STD_INCLUDES
42 #  include <istream>
43 #elif defined( SG_HAVE_NATIVE_SGI_COMPILERS )
44 #  include <iostream.h>
45 #elif defined( __BORLANDC__ )
46 #  include <iostream>
47 #else
48 #  include <istream.h>
49 #endif
50
51 #include STL_STRING
52 #include <set>
53
54 #ifndef _MSC_VER
55 #   define NDEBUG                       // she don't work without it.
56 #endif
57 #include <mk4.h>
58 #include <mk4str.h>
59 #ifndef _MSC_VER
60 #  undef NDEBUG
61 #endif
62
63 SG_USING_STD(string);
64 SG_USING_STD(set);
65
66 #if ! defined( SG_HAVE_NATIVE_SGI_COMPILERS )
67 SG_USING_STD(istream);
68 #endif
69
70
71 class FGAirport {
72
73 public:
74
75     FGAirport( const string& name = "",
76                double lon = 0.0,
77                double lat = 0.0,
78                double ele = 0.0 )
79         : id(name), longitude(lon), latitude(lat), elevation(ele) {}
80
81     bool operator < ( const FGAirport& a ) const {
82         return id < a.id;
83     }
84
85 public:
86
87     string id;
88     double longitude;
89     double latitude;
90     double elevation;
91
92 };
93
94 inline istream&
95 operator >> ( istream& in, FGAirport& a )
96 {
97     return in >> a.id >> a.latitude >> a.longitude >> a.elevation;
98 }
99
100
101 class FGAirports {
102
103 private:
104
105     c4_Storage *storage;
106     c4_View *vAirport;
107
108 public:
109
110     // Constructor
111     FGAirports( const string& file );
112
113     // Destructor
114     ~FGAirports();
115
116     // search for the specified id.
117     // Returns true if successful, otherwise returns false.
118     // On success, airport data is returned thru "airport" pointer.
119     // "airport" is not changed if "apt" is not found.
120     bool search( const string& id, FGAirport* airport ) const;
121     FGAirport search( const string& id ) const;
122 };
123
124
125 class FGAirportsUtil {
126 public:
127 #ifdef SG_NO_DEFAULT_TEMPLATE_ARGS
128     typedef set< FGAirport, less< FGAirport > > container;
129 #else
130     typedef set< FGAirport > container;
131 #endif
132     typedef container::iterator iterator;
133     typedef container::const_iterator const_iterator;
134
135 private:
136     container airports;
137
138 public:
139
140     // Constructor
141     FGAirportsUtil();
142
143     // Destructor
144     ~FGAirportsUtil();
145
146     // load the data
147     int load( const string& file );
148
149     // save the data in metakit format
150     bool dump_mk4( const string& file );
151
152     // search for the specified id.
153     // Returns true if successful, otherwise returns false.
154     // On success, airport data is returned thru "airport" pointer.
155     // "airport" is not changed if "id" is not found.
156     bool search( const string& id, FGAirport* airport ) const;
157     FGAirport search( const string& id ) const;
158 };
159
160
161 #endif // _SIMPLE_HXX
162
163