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