1998-08-25 17:19:13 +00:00
|
|
|
//
|
1999-02-26 22:08:34 +00:00
|
|
|
// simple.cxx -- a really simplistic class to manage airport ID,
|
1998-08-25 17:19:13 +00:00
|
|
|
// lat, lon of the center of one of it's runways, and
|
|
|
|
// elevation in feet.
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started April 1998.
|
|
|
|
//
|
|
|
|
// Copyright (C) 1998 Curtis L. Olson - curt@me.umn.edu
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#include <Include/compiler.h>
|
1998-08-25 17:19:13 +00:00
|
|
|
|
1998-11-06 21:17:31 +00:00
|
|
|
#include <Debug/logstream.hxx>
|
1998-09-01 19:02:53 +00:00
|
|
|
#include <Misc/fgstream.hxx>
|
1999-02-26 22:08:34 +00:00
|
|
|
#include <Main/options.hxx>
|
1998-08-25 17:19:13 +00:00
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#include STL_STRING
|
1998-09-01 19:02:53 +00:00
|
|
|
#include STL_FUNCTIONAL
|
|
|
|
#include STL_ALGORITHM
|
1998-08-25 17:19:13 +00:00
|
|
|
|
1999-02-26 22:08:34 +00:00
|
|
|
#include "simple.hxx"
|
|
|
|
|
1998-09-02 14:35:38 +00:00
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
fgAIRPORTS::fgAIRPORTS() {
|
1998-08-25 17:19:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// load the data
|
1998-08-27 17:01:55 +00:00
|
|
|
int fgAIRPORTS::load( const string& file ) {
|
1998-09-02 14:35:38 +00:00
|
|
|
fgAIRPORT a;
|
|
|
|
|
1998-08-25 17:19:13 +00:00
|
|
|
// build the path name to the airport file
|
1998-09-01 19:02:53 +00:00
|
|
|
string path = current_options.get_fg_root() + "/Airports/" + file;
|
1998-08-25 17:19:13 +00:00
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
airports.erase( airports.begin(), airports.end() );
|
1998-08-25 17:19:13 +00:00
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
fg_gzifstream in( path );
|
1998-11-06 21:17:31 +00:00
|
|
|
if ( !in ) {
|
|
|
|
FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path );
|
|
|
|
exit(-1);
|
|
|
|
}
|
1998-09-01 19:02:53 +00:00
|
|
|
|
1998-09-02 14:35:38 +00:00
|
|
|
/*
|
1998-09-01 19:02:53 +00:00
|
|
|
// We can use the STL copy algorithm because the input
|
|
|
|
// file doesn't contain and comments or blank lines.
|
|
|
|
copy( istream_iterator<fgAIRPORT,ptrdiff_t>(in.stream()),
|
|
|
|
istream_iterator<fgAIRPORT,ptrdiff_t>(),
|
|
|
|
inserter( airports, airports.begin() ) );
|
1998-09-02 14:35:38 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
// read in each line of the file
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> skipcomment;
|
1998-09-02 14:35:38 +00:00
|
|
|
while ( ! in.eof() )
|
|
|
|
{
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> a;
|
1998-09-02 14:35:38 +00:00
|
|
|
airports.insert(a);
|
1998-11-06 14:46:59 +00:00
|
|
|
in >> skipcomment;
|
1998-09-02 14:35:38 +00:00
|
|
|
}
|
1998-08-25 17:19:13 +00:00
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
return 1;
|
1998-08-25 17:19:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// search for the specified id
|
1998-09-01 19:02:53 +00:00
|
|
|
bool
|
|
|
|
fgAIRPORTS::search( const string& id, fgAIRPORT* a ) const
|
|
|
|
{
|
|
|
|
const_iterator it = airports.find( fgAIRPORT(id) );
|
|
|
|
if ( it != airports.end() )
|
|
|
|
{
|
|
|
|
*a = *it;
|
|
|
|
return true;
|
1998-08-25 17:19:13 +00:00
|
|
|
}
|
1998-09-01 19:02:53 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-08-25 17:19:13 +00:00
|
|
|
|
1998-09-01 19:02:53 +00:00
|
|
|
fgAIRPORT
|
|
|
|
fgAIRPORTS::search( const string& id ) const
|
|
|
|
{
|
|
|
|
fgAIRPORT a;
|
|
|
|
this->search( id, &a );
|
|
|
|
return a;
|
1998-08-25 17:19:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
fgAIRPORTS::~fgAIRPORTS( void ) {
|
|
|
|
}
|
|
|
|
|
|
|
|
|