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