//
// simple.cxx -- a really simplistic class to manage airport ID,
-// lat, lon of the center of one of it's runways, and
-// elevation in feet.
+// lat, lon of the center of one of it's runways, and
+// elevation in feet.
//
// Written by Curtis Olson, started April 1998.
//
//
// $Id$
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
-#include <Include/compiler.h>
+#include <simgear/compiler.h>
-#include <Debug/logstream.hxx>
-#include <Misc/fgstream.hxx>
-#include <Main/options.hxx>
+#include <simgear/debug/logstream.hxx>
+#include <simgear/misc/sgstream.hxx>
#include STL_STRING
-#include STL_FUNCTIONAL
-#include STL_ALGORITHM
+#include STL_IOSTREAM
#include "simple.hxx"
+SG_USING_NAMESPACE(std);
+SG_USING_STD(istream);
-fgAIRPORTS::fgAIRPORTS() {
-}
+inline istream&
+operator >> ( istream& in, FGAirport& a )
+{
+ string junk;
+ in >> junk >> a.id >> a.latitude >> a.longitude >> a.elevation
+ >> a.code;
-// load the data
-int fgAIRPORTS::load( const string& file ) {
- fgAIRPORT a;
+ char name[256]; // should never be longer than this, right? :-)
+ in.getline( name, 256 );
+ a.name = name;
- // build the path name to the airport file
- string path = current_options.get_fg_root() + "/Airports/" + file;
+ return in;
+}
- airports.erase( airports.begin(), airports.end() );
- fg_gzifstream in( path );
- if ( !in ) {
- FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << path );
- exit(-1);
- }
+FGAirportList::FGAirportList( const string& file ) {
+ SG_LOG( SG_GENERAL, SG_DEBUG, "Reading simple airport list: " << file );
- /*
- // 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() ) );
- */
-
- // read in each line of the file
- in >> skipcomment;
- while ( ! in.eof() )
- {
- in >> a;
- airports.insert(a);
- in >> skipcomment;
+ // open the specified file for reading
+ sg_gzifstream in( file );
+ if ( !in.is_open() ) {
+ SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file );
+ exit(-1);
}
- return 1;
-}
-
+ // skip header line
+ in >> skipeol;
-// search for the specified id
-bool
-fgAIRPORTS::search( const string& id, fgAIRPORT* a ) const
-{
- const_iterator it = airports.find( fgAIRPORT(id) );
- if ( it != airports.end() )
- {
- *a = *it;
- return true;
- }
- else
- {
- return false;
+ FGAirport a;
+ while ( in ) {
+ in >> a;
+ airports[a.id] = a;
}
}
-fgAIRPORT
-fgAIRPORTS::search( const string& id ) const
-{
- fgAIRPORT a;
- this->search( id, &a );
- return a;
+// search for the specified id
+FGAirport FGAirportList::search( const string& id) {
+ return airports[id];
}
// Destructor
-fgAIRPORTS::~fgAIRPORTS( void ) {
+FGAirportList::~FGAirportList( void ) {
}
-
-