#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 =
// Destructor
FGAirports::~FGAirports( void ) {
- // gdbm_close( dbf );
+ delete storage;
}
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
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;