]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.hxx
Replaced gdbm with metakit. Involves a new simgear version and a new database
[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 FG_HAVE_STD_INCLUDES
42 #  include <istream>
43 #elif defined( FG_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 #define NDEBUG                  // she don't work without it.
55 #include <mk4.h>
56 #include <mk4str.h>
57 #undef NDEBUG
58
59 FG_USING_STD(string);
60 FG_USING_STD(set);
61
62 #if ! defined( FG_HAVE_NATIVE_SGI_COMPILERS )
63 FG_USING_STD(istream);
64 #endif
65
66
67 class FGAirport {
68
69 public:
70
71     FGAirport( const string& name = "",
72                double lon = 0.0,
73                double lat = 0.0,
74                double ele = 0.0 )
75         : id(name), longitude(lon), latitude(lat), elevation(ele) {}
76
77     bool operator < ( const FGAirport& a ) const {
78         return id < a.id;
79     }
80
81 public:
82
83     string id;
84     double longitude;
85     double latitude;
86     double elevation;
87
88 };
89
90 inline istream&
91 operator >> ( istream& in, FGAirport& a )
92 {
93     return in >> a.id >> a.longitude >> a.latitude >> a.elevation;
94 }
95
96
97 class FGAirports {
98
99 private:
100
101     c4_Storage *storage;
102     c4_View *vAirport;
103
104 public:
105
106     // Constructor
107     FGAirports( const string& file );
108
109     // Destructor
110     ~FGAirports();
111
112     // search for the specified id.
113     // Returns true if successful, otherwise returns false.
114     // On success, airport data is returned thru "airport" pointer.
115     // "airport" is not changed if "apt" is not found.
116     bool search( const string& id, FGAirport* airport ) const;
117     FGAirport search( const string& id ) const;
118 };
119
120
121 class FGAirportsUtil {
122 public:
123 #ifdef FG_NO_DEFAULT_TEMPLATE_ARGS
124     typedef set< FGAirport, less< FGAirport > > container;
125 #else
126     typedef set< FGAirport > container;
127 #endif
128     typedef container::iterator iterator;
129     typedef container::const_iterator const_iterator;
130
131 private:
132     container airports;
133
134 public:
135
136     // Constructor
137     FGAirportsUtil();
138
139     // Destructor
140     ~FGAirportsUtil();
141
142     // load the data
143     int load( const string& file );
144
145     // save the data in metakit format
146     bool dump_mk4( const string& file );
147
148     // search for the specified id.
149     // Returns true if successful, otherwise returns false.
150     // On success, airport data is returned thru "airport" pointer.
151     // "airport" is not changed if "id" is not found.
152     bool search( const string& id, FGAirport* airport ) const;
153     FGAirport search( const string& id ) const;
154 };
155
156
157 #endif // _SIMPLE_HXX
158
159