]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/simple.cxx
- adjusted for no-value constructor for FGPanel
[flightgear.git] / src / Airports / simple.cxx
index e9a04b9fb19aa643b028bcdd437f3e16adfa22bf..8d02279ab7eb7605618bea94ffb8deb25fdcde8e 100644 (file)
@@ -40,9 +40,7 @@
 #include <simgear/compiler.h>
 
 #include <simgear/debug/logstream.hxx>
-#include <simgear/misc/fgstream.hxx>
-
-#include <Main/options.hxx>
+#include <simgear/misc/sgstream.hxx>
 
 #include STL_STRING
 #include STL_FUNCTIONAL
 
 #include "simple.hxx"
 
-FG_USING_NAMESPACE(std);
+SG_USING_NAMESPACE(std);
 
 FGAirports::FGAirports( const string& file ) {
     // open the specified database readonly
     storage = new c4_Storage( file.c_str(), false );
 
-    // need to do something about error handling here!
+    if ( !storage->Strategy().IsValid() ) {
+       SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file );
+       exit(-1);
+    }
 
     vAirport = new c4_View;
     *vAirport = 
@@ -101,7 +102,7 @@ FGAirports::search( const string& id ) const
 
 // Destructor
 FGAirports::~FGAirports( void ) {
-    // gdbm_close( dbf );
+    delete storage;
 }
 
 
@@ -116,40 +117,53 @@ int FGAirportsUtil::load( const string& file ) {
 
     airports.erase( airports.begin(), airports.end() );
 
-    fg_gzifstream in( file );
+    sg_gzifstream in( file );
     if ( !in.is_open() ) {
-       FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << file );
+       SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file );
        exit(-1);
     }
 
-    /*
-    // 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() ) );
-    */
+    // skip first line of file
+    char tmp[256];
+    in.getline( tmp, 256 );
+
 
     // read in each line of the file
 
 #ifdef __MWERKS__
 
-    in >> skipcomment;
+    in >> ::skipws;
     char c = 0;
     while ( in.get(c) && c != '\0' ) {
-       in.putback(c);
-       in >> a;
-       airports.insert(a);
-       in >> skipcomment;
+       if ( c == 'A' ) {
+           in >> a;
+           in >> skipeol;
+           airports.insert(a);
+       } else if ( c == 'R' ) {
+           in >> skipeol;
+       } else {
+           in >> skipeol;
+       }
+       in >> ::skipws;
     }
 
 #else
 
-    in >> skipcomment;
+    in >> ::skipws;
     while ( ! in.eof() ) {
-       in >> a;
-       airports.insert(a);
-       in >> skipcomment;
+       char c = 0;
+       in.get(c);
+       if ( c == 'A' ) {
+           in >> a;
+           cout << "in <- " << a.id << endl;
+           in >> skipeol;
+           airports.insert(a);
+       } else if ( c == 'R' ) {
+           in >> skipeol;
+       } else {
+           in >> skipeol;
+       }
+       in >> ::skipws;
     }
 
 #endif
@@ -178,10 +192,11 @@ bool FGAirportsUtil::dump_mk4( const string& file ) {
 
     c4_Row row;
 
-    iterator current = airports.begin();
+    const_iterator current = airports.begin();
     const_iterator end = airports.end();
     while ( current != end ) {
        // add each airport record
+       cout << "out -> " << current->id << endl;
        pID (row) = current->id.c_str();
        pLon (row) = current->longitude;
        pLat (row) = current->latitude;