]> git.mxchange.org Git - flightgear.git/blob - src/Airports/simple.cxx
1e5d9a6940f87eb6b76e4acf03e6c02c9414b7e4
[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/fgstream.hxx>
31 #include <Main/options.hxx>
32
33 #include STL_STRING
34 #include STL_FUNCTIONAL
35 #include STL_ALGORITHM
36
37 #include "simple.hxx"
38
39
40 fgAIRPORTS::fgAIRPORTS() {
41 }
42
43
44 // load the data
45 int fgAIRPORTS::load( const string& file ) {
46     fgAIRPORT a;
47
48     // build the path name to the airport file
49     string path = current_options.get_fg_root() + "/Airports/" + file;
50
51     airports.erase( airports.begin(), airports.end() );
52
53     fg_gzifstream in( path );
54     if ( !in ) {
55         FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path );
56         exit(-1);
57     }
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 >> skipcomment;
69     while ( ! in.eof() )
70     {
71         in >> a;
72         airports.insert(a);
73         in >> skipcomment;
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