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