]> git.mxchange.org Git - flightgear.git/blob - Simulator/Airports/simple.cxx
Initial revision
[flightgear.git] / Simulator / Airports / simple.cxx
1 //
2 // simple.cxx -- a really simplistic class to manage airport ID,
3 //                 lat, lon of the center of one of it's runways, and 
4 //                 elevation in feet.
5 //
6 // Written by Curtis Olson, started April 1998.
7 //
8 // Copyright (C) 1998  Curtis L. Olson  - curt@me.umn.edu
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 // (Log is kept at end of this file)
26
27
28 #include <Include/compiler.h>
29
30 #include <Debug/logstream.hxx>
31 #include <Misc/fgstream.hxx>
32 #include <Main/options.hxx>
33
34 #include STL_STRING
35 #include STL_FUNCTIONAL
36 #include STL_ALGORITHM
37
38 #include "simple.hxx"
39
40
41 fgAIRPORTS::fgAIRPORTS() {
42 }
43
44
45 // load the data
46 int fgAIRPORTS::load( const string& file ) {
47     fgAIRPORT a;
48
49     // build the path name to the airport file
50     string path = current_options.get_fg_root() + "/Airports/" + file;
51
52     airports.erase( airports.begin(), airports.end() );
53
54     fg_gzifstream in( path );
55     if ( !in ) {
56         FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path );
57         exit(-1);
58     }
59
60     /*
61     // We can use the STL copy algorithm because the input
62     // file doesn't contain and comments or blank lines.
63     copy( istream_iterator<fgAIRPORT,ptrdiff_t>(in.stream()),
64           istream_iterator<fgAIRPORT,ptrdiff_t>(),
65           inserter( airports, airports.begin() ) );
66     */
67
68     // read in each line of the file
69     in >> skipcomment;
70     while ( ! in.eof() )
71     {
72         in >> a;
73         airports.insert(a);
74         in >> skipcomment;
75     }
76
77     return 1;
78 }
79
80
81 // search for the specified id
82 bool
83 fgAIRPORTS::search( const string& id, fgAIRPORT* a ) const
84 {
85     const_iterator it = airports.find( fgAIRPORT(id) );
86     if ( it != airports.end() )
87     {
88         *a = *it;
89         return true;
90     }
91     else
92     {
93         return false;
94     }
95 }
96
97
98 fgAIRPORT
99 fgAIRPORTS::search( const string& id ) const
100 {
101     fgAIRPORT a;
102     this->search( id, &a );
103     return a;
104 }
105
106
107 // Destructor
108 fgAIRPORTS::~fgAIRPORTS( void ) {
109 }
110
111
112 // $Log$
113 // Revision 1.1  1999/04/05 21:32:48  curt
114 // Initial revision
115 //
116 // Revision 1.10  1999/02/26 22:08:35  curt
117 // Added initial support for native SGI compilers.
118 //
119 // Revision 1.9  1998/11/06 21:17:34  curt
120 // Converted to new logstream debugging facility.  This allows release
121 // builds with no messages at all (and no performance impact) by using
122 // the -DFG_NDEBUG flag.
123 //
124 // Revision 1.8  1998/11/06 14:47:01  curt
125 // Changes to track Bernie's updates to fgstream.
126 //
127 // Revision 1.7  1998/09/08 21:38:41  curt
128 // Changes by Bernie Bright.
129 //
130 // Revision 1.6  1998/09/03 21:25:02  curt
131 // tweaked in data file comment handling.
132 //
133 // Revision 1.5  1998/09/02 14:35:38  curt
134 // Rewrote simple airport loader so it can deal with comments and blank lines.
135 //
136 // Revision 1.4  1998/09/01 19:02:53  curt
137 // Changes contributed by Bernie Bright <bbright@c031.aone.net.au>
138 //  - The new classes in libmisc.tgz define a stream interface into zlib.
139 //    I've put these in a new directory, Lib/Misc.  Feel free to rename it
140 //    to something more appropriate.  However you'll have to change the
141 //    include directives in all the other files.  Additionally you'll have
142 //    add the library to Lib/Makefile.am and Simulator/Main/Makefile.am.
143 //
144 //    The StopWatch class in Lib/Misc requires a HAVE_GETRUSAGE autoconf
145 //    test so I've included the required changes in config.tgz.
146 //
147 //    There are a fair few changes to Simulator/Objects as I've moved
148 //    things around.  Loading tiles is quicker but thats not where the delay
149 //    is.  Tile loading takes a few tenths of a second per file on a P200
150 //    but it seems to be the post-processing that leads to a noticeable
151 //    blip in framerate.  I suppose its time to start profiling to see where
152 //    the delays are.
153 //
154 //    I've included a brief description of each archives contents.
155 //
156 // Lib/Misc/
157 //   zfstream.cxx
158 //   zfstream.hxx
159 //     C++ stream interface into zlib.
160 //     Taken from zlib-1.1.3/contrib/iostream/.
161 //     Minor mods for STL compatibility.
162 //     There's no copyright associated with these so I assume they're
163 //     covered by zlib's.
164 //
165 //   fgstream.cxx
166 //   fgstream.hxx
167 //     FlightGear input stream using gz_ifstream.  Tries to open the
168 //     given filename.  If that fails then filename is examined and a
169 //     ".gz" suffix is removed or appended and that file is opened.
170 //
171 //   stopwatch.hxx
172 //     A simple timer for benchmarking.  Not used in production code.
173 //     Taken from the Blitz++ project.  Covered by GPL.
174 //
175 //   strutils.cxx
176 //   strutils.hxx
177 //     Some simple string manipulation routines.
178 //
179 // Simulator/Airports/
180 //   Load airports database using fgstream.
181 //   Changed fgAIRPORTS to use set<> instead of map<>.
182 //   Added bool fgAIRPORTS::search() as a neater way doing the lookup.
183 //   Returns true if found.
184 //
185 // Simulator/Astro/
186 //   Modified fgStarsInit() to load stars database using fgstream.
187 //
188 // Simulator/Objects/
189 //   Modified fgObjLoad() to use fgstream.
190 //   Modified fgMATERIAL_MGR::load_lib() to use fgstream.
191 //   Many changes to fgMATERIAL.
192 //   Some changes to fgFRAGMENT but I forget what!
193 //
194 // Revision 1.3  1998/08/27 17:01:55  curt
195 // Contributions from Bernie Bright <bbright@c031.aone.net.au>
196 // - use strings for fg_root and airport_id and added methods to return
197 //   them as strings,
198 // - inlined all access methods,
199 // - made the parsing functions private methods,
200 // - deleted some unused functions.
201 // - propogated some of these changes out a bit further.
202 //
203 // Revision 1.2  1998/08/25 20:53:24  curt
204 // Shuffled $FG_ROOT file layout.
205 //
206 // Revision 1.1  1998/08/25 17:19:13  curt
207 // Moved from ../Main/
208 //
209 // Revision 1.8  1998/07/13 21:01:37  curt
210 // Wrote access functions for current fgOPTIONS.
211 //
212 // Revision 1.7  1998/06/03 22:01:07  curt
213 // Tweaking sound library usage.
214 //
215 // Revision 1.6  1998/06/03 00:47:13  curt
216 // Updated to compile in audio support if OSS available.
217 // Updated for new version of Steve's audio library.
218 // STL includes don't use .h
219 // Small view optimizations.
220 //
221 // Revision 1.5  1998/05/29 20:37:22  curt
222 // Tweaked material properties & lighting a bit in GLUTmain.cxx.
223 // Read airport list into a "map" STL for dynamic list sizing and fast tree
224 // based lookups.
225 //
226 // Revision 1.4  1998/05/13 18:26:25  curt
227 // Root path info moved to fgOPTIONS.
228 //
229 // Revision 1.3  1998/05/06 03:16:24  curt
230 // Added an averaged global frame rate counter.
231 // Added an option to control tile radius.
232 //
233 // Revision 1.2  1998/04/28 21:42:50  curt
234 // Wrapped zlib calls up so we can conditionally comment out zlib support.
235 //
236 // Revision 1.1  1998/04/25 15:11:11  curt
237 // Added an command line option to set starting position based on airport ID.
238 //
239 //