X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FAirports%2Frunways.cxx;h=78c1c6db2928c7c05ea5772caf896aa2aa750bd6;hb=2bc09e5268284b4d7009fa66930bcfc937400f3b;hp=ff45f4c7e7e00fe17c31a514d343e0fdb91de38b;hpb=df2ce45ab71442cd24d6bb9f8da3a0c2e13a8c7c;p=flightgear.git diff --git a/src/Airports/runways.cxx b/src/Airports/runways.cxx index ff45f4c7e..78c1c6db2 100644 --- a/src/Airports/runways.cxx +++ b/src/Airports/runways.cxx @@ -34,59 +34,58 @@ #include #include STL_STRING -#include STL_FUNCTIONAL -#include STL_ALGORITHM +#include STL_IOSTREAM +#include #include "runways.hxx" SG_USING_NAMESPACE(std); - -#ifndef _MSC_VER -#define NDEBUG // MSVC needs this -#endif // !_MSC_VER - -#include -#include - -#ifndef _MSC_VER -#undef NDEBUG -#endif // !_MSC_VER - -#ifdef SG_HAVE_STD_INCLUDES -# include -#elif defined( __BORLANDC__ ) || defined (__APPLE__) -# include -#else -# include -#endif - SG_USING_STD(istream); +SG_USING_STD(multimap); inline istream& operator >> ( istream& in, FGRunway& a ) { + string type; int tmp; - return in >> a.rwy_no >> a.lat >> a.lon >> a.heading >> a.length >> a.width - >> a.surface_flags >> a.end1_flags >> tmp >> tmp >> a.end2_flags - >> tmp >> tmp; + in >> a.type; + if ( a.type == "R" ) { + in >> a.id >> a.rwy_no >> a.lat >> a.lon >> a.heading + >> a.length >> a.width >> a.surface_flags >> a.end1_flags + >> tmp >> tmp >> a.end2_flags >> tmp >> tmp; + } else if ( a.type == "T" ) { + // in >> a.id >> a.rwy_no >> a.lat >> a.lon >> a.heading + // >> a.length >> a.width >> a.surface_flags; + in >> skipeol; + } else { + in >> skipeol; + } + + return in; } -FGRunways::FGRunways( const string& file ) { - // open the specified database readonly - storage = new c4_Storage( file.c_str(), false ); +FGRunwayList::FGRunwayList( const string& file ) { + SG_LOG( SG_GENERAL, SG_DEBUG, "Reading runway list: " << file ); - if ( !storage->Strategy().IsValid() ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file ); + // 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); } - vRunway = new c4_View; - *vRunway = - storage->GetAs("runway[ID:S,Rwy:S,Longitude:F,Latitude:F,Heading:F,Length:F,Width:F,SurfaceFlags:S,End1Flags:S,End2Flags:S]"); + // skip header line + in >> skipeol; - next_index = 0; + FGRunway rwy; + while ( in ) { + in >> rwy; + if(rwy.type == "R") { + runways.insert(pair(rwy.id, rwy)); + } + } } @@ -101,8 +100,8 @@ static string GetReverseRunwayNo(string rwyno) { if (( tmp == "L" || tmp == "R" || tmp == "C" ) || (rwyno.size() == 1)) { tmp = rwyno; rwyno = "0" + tmp; - SG_LOG( SG_GENERAL, SG_INFO, "Standardising rwy number from " << tmp - << " to " << rwyno ); + SG_LOG( SG_GENERAL, SG_INFO, + "Standardising rwy number from " << tmp << " to " << rwyno ); } char buf[4]; @@ -122,188 +121,93 @@ static string GetReverseRunwayNo(string rwyno) { } else if (rwyno.substr(2,1) == "C") { buf[2] = 'C'; buf[3] = '\0'; + } else if (rwyno.substr(2,1) == "T") { + buf[2] = 'T'; + buf[3] = '\0'; } else { SG_LOG(SG_GENERAL, SG_ALERT, "Unknown runway code " << rwyno << " passed to GetReverseRunwayNo(...)"); } } - return((string)buf); + return(buf); } -// search for the specified apt id -bool FGRunways::search( const string& aptid, FGRunway* r ) { - c4_StringProp pID ("ID"); - c4_StringProp pRwy ("Rwy"); - c4_FloatProp pLon ("Longitude"); - c4_FloatProp pLat ("Latitude"); - c4_FloatProp pHdg ("Heading"); - c4_FloatProp pLen ("Length"); - c4_FloatProp pWid ("Width"); - c4_StringProp pSurf ("SurfaceFlags"); - c4_StringProp pEnd1 ("End1Flags"); - c4_StringProp pEnd2 ("End2Flags"); - - int index = vRunway->Find(pID[aptid.c_str()]); - // cout << "index = " << index << endl; - - if ( index == -1 ) { - return false; - } - - next_index = index + 1; - - c4_RowRef row = vRunway->GetAt(index); +// search for the specified apt id (wierd!) +bool FGRunwayList::search( const string& aptid, FGRunway* r ) { + runway_map_iterator pos; - r->id = (const char *) pID(row); - r->rwy_no = (const char *) pRwy(row); - r->lon = (double) pLon(row); - r->lat = (double) pLat(row); - r->heading = (double) pHdg(row); - r->length = (double) pLen(row); - r->width = (double) pWid(row); - r->surface_flags = (const char *) pSurf(row); - r->end1_flags = (const char *) pEnd1(row); - r->end2_flags = (const char *) pEnd2(row); - - return true; + pos = runways.lower_bound(aptid); + if ( pos != runways.end() ) { + current = pos; + *r = pos->second; + return true; + } else { + return false; + } } // search for the specified apt id and runway no -bool FGRunways::search( const string& aptid, const string& rwyno, FGRunway* r ) +bool FGRunwayList::search( const string& aptid, const string& rwyno, + FGRunway *r ) { + string revrwyno = ""; string runwayno = rwyno; - c4_StringProp pID ("ID"); - c4_StringProp pRwy ("Rwy"); - c4_FloatProp pLon ("Longitude"); - c4_FloatProp pLat ("Latitude"); - c4_FloatProp pHdg ("Heading"); - c4_FloatProp pLen ("Length"); - c4_FloatProp pWid ("Width"); - c4_StringProp pSurf ("SurfaceFlags"); - c4_StringProp pEnd1 ("End1Flags"); - c4_StringProp pEnd2 ("End2Flags"); - - int index = vRunway->Find(pID[aptid.c_str()]); - // cout << "index = " << index << endl; - - if ( index == -1 ) { - return false; - } - - // standardize input number - string tmp = runwayno.substr(1, 1); - if (( tmp == "L" || tmp == "R" || tmp == "C" ) || (runwayno.size() == 1)) { - tmp = runwayno; - runwayno = "0" + tmp; - SG_LOG(SG_GENERAL, SG_INFO, "Standardising rwy number from " << tmp - << " to " << runwayno ); + if ( runwayno.length() ) { + // standardize input number + string tmp = runwayno.substr(1, 1); + if (( tmp == "L" || tmp == "R" || tmp == "C" ) + || (runwayno.size() == 1)) + { + tmp = runwayno; + runwayno = "0" + tmp; + SG_LOG( SG_GENERAL, SG_INFO, "Standardising rwy number from " + << tmp << " to " << runwayno ); + } + revrwyno = GetReverseRunwayNo(runwayno); } - c4_RowRef row = vRunway->GetAt(index); - string rowid = (const char *) pID(row); - string rowrwyno = (const char *) pRwy(row); - while ( rowid == aptid ) { - next_index = index + 1; - - if ( rowrwyno == runwayno ) { - r->id = (const char *) pID(row); - r->rwy_no = (const char *) pRwy(row); - r->lon = (double) pLon(row); - r->lat = (double) pLat(row); - r->heading = (double) pHdg(row); - r->length = (double) pLen(row); - r->width = (double) pWid(row); - r->surface_flags = (const char *) pSurf(row); - r->end1_flags = (const char *) pEnd1(row); - r->end2_flags = (const char *) pEnd2(row); - + runway_map_iterator pos; + for ( pos = runways.lower_bound( aptid ); + pos != runways.upper_bound( aptid ); ++pos) + { + if ( pos->second.rwy_no == runwayno ) { + current = pos; + *r = pos->second; + return true; + } else if ( pos->second.rwy_no == revrwyno ) { + // Search again with the other-end runway number. + // Remember we have to munge the heading and rwy_no + // results if this one matches + current = pos; + *r = pos->second; + // NOTE - matching revrwyno implies that runwayno was + // actually correct. + r->rwy_no = runwayno; + r->heading += 180.0; + string tmp = r->end1_flags; + r->end1_flags = r->end2_flags; + r->end2_flags = tmp; return true; } - - // Search again with the other-end runway number - // Remember we have to munge the heading and rwy_no results if this one matches - rowrwyno = GetReverseRunwayNo(rowrwyno); - // cout << "New rowrwyno = " << rowrwyno << '\n'; - if ( rowrwyno == runwayno ) { - r->id = (const char *) pID(row); - r->rwy_no = rowrwyno; - r->lon = (double) pLon(row); - r->lat = (double) pLat(row); - r->heading = (double) pHdg(row) + 180.0; - r->length = (double) pLen(row); - r->width = (double) pWid(row); - r->surface_flags = (const char *) pSurf(row); - r->end1_flags = (const char *) pEnd2(row); - r->end2_flags = (const char *) pEnd1(row); - // I've swapped the end flags as well - - return true; - } - - index++; - row = vRunway->GetAt(index); - rowid = (const char *) pID(row); - rowrwyno = (const char *) pRwy(row); } return false; } -FGRunway FGRunways::search( const string& aptid ) { +// (wierd!) +FGRunway FGRunwayList::search( const string& aptid ) { FGRunway a; search( aptid, &a ); return a; } -// search for the specified id -bool FGRunways::next( FGRunway* r ) { - c4_StringProp pID ("ID"); - c4_StringProp pRwy ("Rwy"); - c4_FloatProp pLon ("Longitude"); - c4_FloatProp pLat ("Latitude"); - c4_FloatProp pHdg ("Heading"); - c4_FloatProp pLen ("Length"); - c4_FloatProp pWid ("Width"); - c4_StringProp pSurf ("SurfaceFlags"); - c4_StringProp pEnd1 ("End1Flags"); - c4_StringProp pEnd2 ("End2Flags"); - - int size = vRunway->GetSize(); - // cout << "total records = " << size << endl; - - int index = next_index; - // cout << "index = " << index << endl; - - if ( index == -1 || index >= size ) { - return false; - } - - next_index = index + 1; - - c4_RowRef row = vRunway->GetAt(index); - - r->id = (const char *) pID(row); - r->rwy_no = (const char *) pRwy(row); - r->lon = (double) pLon(row); - r->lat = (double) pLat(row); - r->heading = (double) pHdg(row); - r->length = (double) pLen(row); - r->width = (double) pWid(row); - r->surface_flags = (const char *) pSurf(row); - r->end1_flags = (const char *) pEnd1(row); - r->end2_flags = (const char *) pEnd2(row); - - return true; -} - - // Return the runway closest to a given heading -bool FGRunways::search( const string& aptid, const int tgt_hdg, - FGRunway* runway ) +bool FGRunwayList::search( const string& aptid, const int tgt_hdg, + FGRunway *runway ) { string rwyNo = search(aptid, tgt_hdg); return(rwyNo == "NN" ? false : search(aptid, rwyNo, runway)); @@ -311,7 +215,7 @@ bool FGRunways::search( const string& aptid, const int tgt_hdg, // Return the runway number of the runway closest to a given heading -string FGRunways::search( const string& aptid, const int tgt_hdg ) { +string FGRunwayList::search( const string& aptid, const int tgt_hdg ) { FGRunway r; FGRunway tmp_r; string rn; @@ -374,160 +278,29 @@ string FGRunways::search( const string& aptid, const int tgt_hdg ) { } -// Destructor -FGRunways::~FGRunways( void ) { - delete storage; -} - - -// Constructor -FGRunwaysUtil::FGRunwaysUtil() { -} - - -// load the data -int FGRunwaysUtil::load( const string& file ) { - FGRunway r; - string apt_id; - - runways.erase( runways.begin(), runways.end() ); - - sg_gzifstream in( file ); - if ( !in.is_open() ) { - SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file ); - exit(-1); - } - - // skip first line of file - char tmp[2048]; - in.getline( tmp, 2048 ); - - // read in each line of the file - -#ifdef __MWERKS__ - - in >> ::skipws; - char c = 0; - while ( in.get(c) && c != '\0' ) { - if ( c == 'A' ) { - in >> apt_id; - in >> skipeol; - } else if ( c == 'R' ) { - in >> r; - r.id = apt_id; - runways.push_back(r); - } else { - in >> skipeol; - } - in >> ::skipws; - } - -#else - - in >> ::skipws; - while ( ! in.eof() ) { - char c = 0; - in.get(c); - if ( c == 'A' ) { - in >> apt_id; - in >> skipeol; - } else if ( c == 'R' ) { - in >> r; - r.id = apt_id; - // cout << apt_id << " " << r.rwy_no << endl; - runways.push_back(r); - } else { - in >> skipeol; - } - in >> ::skipws; +bool FGRunwayList::next( FGRunway* runway ) { + ++current; + if ( current != runways.end() ) { + *runway = current->second; + return true; + } else { + return false; } - -#endif - - return 1; } -// save the data in gdbm format -bool FGRunwaysUtil::dump_mk4( const string& file ) { - // open database for writing - c4_Storage storage( file.c_str(), true ); - - // need to do something about error handling here! - - // define the properties - c4_StringProp pID ("ID"); - c4_StringProp pRwy ("Rwy"); - c4_FloatProp pLon ("Longitude"); - c4_FloatProp pLat ("Latitude"); - c4_FloatProp pHdg ("Heading"); - c4_FloatProp pLen ("Length"); - c4_FloatProp pWid ("Width"); - c4_StringProp pSurf ("SurfaceFlags"); - c4_StringProp pEnd1 ("End1Flags"); - c4_StringProp pEnd2 ("End2Flags"); - - // Start with an empty view of the proper structure. - c4_View vRunway = - storage.GetAs("runway[ID:S,Rwy:S,Longitude:F,Latitude:F,Heading:F,Length:F,Width:F,SurfaceFlags:S,End1Flags:S,End2Flags:S]"); - - c4_Row row; - - iterator current = runways.begin(); - const_iterator end = runways.end(); - while ( current != end ) { - // add each runway record - pID (row) = current->id.c_str(); - pRwy (row) = current->rwy_no.c_str(); - pLon (row) = current->lon; - pLat (row) = current->lat; - pHdg (row) = current->heading; - pLen (row) = current->length; - pWid (row) = current->width; - pSurf (row) = current->surface_flags.c_str(); - pEnd1 (row) = current->end1_flags.c_str(); - pEnd2 (row) = current->end2_flags.c_str(); - vRunway.Add(row); - - ++current; - } - - // commit our changes - storage.Commit(); +FGRunway FGRunwayList::next() { + FGRunway result; - return true; -} - - -#if 0 -// search for the specified id -bool -FGRunwaysUtil::search( const string& id, FGRunway* a ) const -{ - const_iterator it = runways.find( FGRunway(id) ); - if ( it != runways.end() ) - { - *a = *it; - return true; + ++current; + if ( current != runways.end() ) { + result = current->second; } - else - { - return false; - } -} - -FGRunway -FGRunwaysUtil::search( const string& id ) const -{ - FGRunway a; - this->search( id, &a ); - return a; + return result; } -#endif + // Destructor -FGRunwaysUtil::~FGRunwaysUtil( void ) { +FGRunwayList::~FGRunwayList( void ) { } - -