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