]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.cxx
c31cce339a00305a40e2102e9e25e280db325d49
[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
27 #include <simgear/compiler.h>
28
29 #include <simgear/logstream.hxx>
30 #include <simgear/fgpath.hxx>
31 #include <simgear/fgstream.hxx>
32
33 #include <Main/options.hxx>
34
35 #include STL_STRING
36 #include STL_FUNCTIONAL
37 #include STL_ALGORITHM
38
39 #include "simple.hxx"
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     FGPath path( current_options.get_fg_root() );
52     path.append( "Airports" );
53     path.append( file );
54
55     airports.erase( airports.begin(), airports.end() );
56
57     fg_gzifstream in( path.str() );
58     if ( !in.is_open() ) {
59         FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path.str() );
60         exit(-1);
61     }
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
73 #ifdef __MWERKS__
74
75     in >> skipcomment;
76     char c = 0;
77     while ( in.get(c) && c != '\0' ) {
78         in.putback(c);
79         in >> a;
80         airports.insert(a);
81         in >> skipcomment;
82     }
83
84 #else
85
86     in >> skipcomment;
87     while ( ! in.eof() ) {
88         in >> a;
89         airports.insert(a);
90         in >> skipcomment;
91     }
92
93 #endif
94
95     return 1;
96 }
97
98
99 // search for the specified id
100 bool
101 fgAIRPORTS::search( const string& id, fgAIRPORT* a ) const
102 {
103     const_iterator it = airports.find( fgAIRPORT(id) );
104     if ( it != airports.end() )
105     {
106         *a = *it;
107         return true;
108     }
109     else
110     {
111         return false;
112     }
113 }
114
115
116 fgAIRPORT
117 fgAIRPORTS::search( const string& id ) const
118 {
119     fgAIRPORT a;
120     this->search( id, &a );
121     return a;
122 }
123
124
125 // Destructor
126 fgAIRPORTS::~fgAIRPORTS( void ) {
127 }
128
129