]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.cxx
7bfe300a115d014dcd0d24b74f4a8628c83a4772
[flightgear.git] / src / 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
26 #ifdef HAVE_CONFIG_H
27 #  include <config.h>
28 #endif
29
30 #include <simgear/compiler.h>
31
32 #include <simgear/debug/logstream.hxx>
33 #include <simgear/misc/sgstream.hxx>
34
35 #include STL_STRING
36 #include STL_FUNCTIONAL
37 #include STL_ALGORITHM
38 #include STL_IOSTREAM
39
40 #include "simple.hxx"
41
42 SG_USING_NAMESPACE(std);
43 SG_USING_STD(istream);
44
45
46 inline istream&
47 operator >> ( istream& in, FGAirport& a )
48 {
49     string junk;
50     in >> junk >> a.id >> a.latitude >> a.longitude >> a.elevation
51        >> a.code;
52
53     char name[256];             // should never be longer than this, right? :-)
54     in.getline( name, 256 );
55     a.name = name;
56
57     return in;
58 }
59
60
61 FGAirportList::FGAirportList( const string& file ) {
62     SG_LOG( SG_GENERAL, SG_DEBUG, "Reading simple airport list: " << file );
63
64     // open the specified file for reading
65     sg_gzifstream in( file );
66     if ( !in.is_open() ) {
67         SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file );
68         exit(-1);
69     }
70
71     // skip header line
72     in >> skipeol;
73
74     while ( in ) {
75         FGAirport a;
76         in >> a;
77         airports[a.id] = a;
78     }
79 }
80
81
82 // search for the specified id
83 FGAirport FGAirportList::search( const string& id) {
84     return airports[id];
85 }
86
87
88 // Destructor
89 FGAirportList::~FGAirportList( void ) {
90 }