]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/simple.cxx
Moved some of the low level scene graph construction code over to simgear.
[flightgear.git] / src / Airports / simple.cxx
index 8d02279ab7eb7605618bea94ffb8deb25fdcde8e..560b0d4668fc6092178cbdbcaee09cf82713ee16 100644 (file)
 //
 // $Id$
 
-
 #ifdef HAVE_CONFIG_H
 #  include <config.h>
 #endif
 
-// #include <sys/types.h>              // for gdbm open flags
-// #include <sys/stat.h>               // for gdbm open flags
-
-// #ifdef HAVE_GDBM
-// #  include <gdbm.h>
-// #else
-// #  include <simgear/gdbm/gdbm.h>
-// #endif
-
 #include <simgear/compiler.h>
 
 #include <simgear/debug/logstream.hxx>
 
 SG_USING_NAMESPACE(std);
 
+#ifndef _MSC_VER
+#   define NDEBUG                      // she don't work without it.
+#endif
+#include <mk4.h>
+#include <mk4str.h>
+#ifndef _MSC_VER
+#  undef NDEBUG
+#endif
+
+#ifdef SG_HAVE_STD_INCLUDES
+#  include <istream>
+#elif defined( __BORLANDC__ ) || defined (__APPLE__)
+#  include <iostream>
+#else
+#  include <istream.h>
+#endif
+SG_USING_STD(istream);
+
+
+inline istream&
+operator >> ( istream& in, FGAirport& a )
+{
+    return in >> a.id >> a.latitude >> a.longitude >> a.elevation;
+}
+
+
 FGAirports::FGAirports( const string& file ) {
     // open the specified database readonly
     storage = new c4_Storage( file.c_str(), false );
@@ -75,16 +91,16 @@ FGAirports::search( const string& id, FGAirport* a ) const
     c4_FloatProp pElev ("Elevation");
 
     int idx = vAirport->Find(pID[id.c_str()]);
-    cout << "idx = " << idx << endl;
+    SG_LOG( SG_TERRAIN, SG_INFO, "idx = " << idx );
 
     if ( idx == -1 ) {
        return false;
     }
 
-    c4_RowRef r = vAirport->GetAt(idx);
-
+    c4_RowRef r  = vAirport->GetAt(idx);
+    a->id        = (const char *) pID(r); /// NHV fix wrong case crash
     a->longitude = (double) pLon(r);
-    a->latitude =  (double) pLat(r);
+    a->latitude  =  (double) pLat(r);
     a->elevation = (double) pElev(r);
 
     return true;
@@ -121,12 +137,13 @@ int FGAirportsUtil::load( const string& file ) {
     if ( !in.is_open() ) {
        SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file );
        exit(-1);
+    } else {
+       SG_LOG( SG_GENERAL, SG_ALERT, "opened: " << file );
     }
 
     // skip first line of file
-    char tmp[256];
-    in.getline( tmp, 256 );
-
+    char tmp[2048];
+    in.getline( tmp, 2048 );
 
     // read in each line of the file
 
@@ -137,6 +154,7 @@ int FGAirportsUtil::load( const string& file ) {
     while ( in.get(c) && c != '\0' ) {
        if ( c == 'A' ) {
            in >> a;
+            SG_LOG( SG_GENERAL, SG_INFO, a.id );
            in >> skipeol;
            airports.insert(a);
        } else if ( c == 'R' ) {
@@ -150,15 +168,15 @@ int FGAirportsUtil::load( const string& file ) {
 #else
 
     in >> ::skipws;
+    string token;
     while ( ! in.eof() ) {
-       char c = 0;
-       in.get(c);
-       if ( c == 'A' ) {
+       in >> token;
+       if ( token == "A" ) {
            in >> a;
-           cout << "in <- " << a.id << endl;
+            SG_LOG( SG_GENERAL, SG_INFO, "in <- " << a.id );
            in >> skipeol;
            airports.insert(a);
-       } else if ( c == 'R' ) {
+       } else if ( token == "R" ) {
            in >> skipeol;
        } else {
            in >> skipeol;
@@ -196,7 +214,7 @@ bool FGAirportsUtil::dump_mk4( const string& file ) {
     const_iterator end = airports.end();
     while ( current != end ) {
        // add each airport record
-       cout << "out -> " << current->id << endl;
+       SG_LOG( SG_TERRAIN, SG_BULK, "out -> " << current->id );
        pID (row) = current->id.c_str();
        pLon (row) = current->longitude;
        pLat (row) = current->latitude;