diff --git a/src/Airports/apt_loader.cxx b/src/Airports/apt_loader.cxx index d0602ac69..ef825295f 100644 --- a/src/Airports/apt_loader.cxx +++ b/src/Airports/apt_loader.cxx @@ -57,7 +57,7 @@ static FGPositioned::Type fptypeFromRobinType(int aType) } } -FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const string& apt_name, +FGAirport* addAirport(const string& apt_id, const string& apt_name, int rwy_count, double rwy_lat_accum, double rwy_lon_accum, double last_rwy_heading, double apt_elev, SGGeod& tower, bool got_tower, int type) { @@ -82,17 +82,14 @@ FGAirport* addAirport(FGAirportList *airports, const string& apt_id, const strin tower = SGGeod::fromDegFt(lon + fudge_lon, lat + fudge_lat, apt_elev + tower_height); } - - - return airports->add(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false, + return new FGAirport(apt_id, SGGeod::fromDegFt(lon, lat, apt_elev), tower, apt_name, false, fptypeFromRobinType(type)); } // Load the airport data base from the specified aptdb file. The // metar file is used to mark the airports as having metar available // or not. -bool fgAirportDBLoad( FGAirportList *airports, - const string &aptdb_file, const string &metar_file ) +bool fgAirportDBLoad( const string &aptdb_file, const string &metar_file ) { // // Load the apt.dat file @@ -166,7 +163,7 @@ bool fgAirportDBLoad( FGAirportList *airports, SG_LOG( SG_GENERAL, SG_BULK, "Next airport = " << id << " " << elev ); - FGAirport* apt = addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum, + FGAirport* apt = addAirport(last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum, last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type); for (unsigned int r=0; r< runways.size(); ++r) { @@ -269,7 +266,7 @@ bool fgAirportDBLoad( FGAirportList *airports, } // add the last airport being processed if any - addAirport(airports, last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum, + addAirport( last_apt_id, last_apt_name, rwy_count, rwy_lat_accum, rwy_lon_accum, last_rwy_heading, last_apt_elev, last_tower, got_tower, last_apt_type); diff --git a/src/Airports/apt_loader.hxx b/src/Airports/apt_loader.hxx index 883e0384d..af2d46aeb 100644 --- a/src/Airports/apt_loader.hxx +++ b/src/Airports/apt_loader.hxx @@ -35,7 +35,7 @@ // Load the airport data base from the specified aptdb file. The // metar file is used to mark the airports as having metar available // or not. -bool fgAirportDBLoad( FGAirportList *airports, const string &aptdb_file, const std::string &metar_file ); +bool fgAirportDBLoad( const string &aptdb_file, const std::string &metar_file ); #endif // _FG_APT_LOADER_HXX diff --git a/src/Airports/simple.cxx b/src/Airports/simple.cxx index af1e0de19..0907030fb 100644 --- a/src/Airports/simple.cxx +++ b/src/Airports/simple.cxx @@ -28,29 +28,19 @@ # include #endif -#include -#include +#include "simple.hxx" -#include +#include +#include +#include +#include #include #include -#include -#include -#include -#include -#include
#include
#include #include - -#include - -#include "simple.hxx" -#include "xmlloader.hxx" - -using std::sort; -using std::random_shuffle; +#include // magic import of a helper which uses FGPositioned internals extern char** searchAirportNamesAndIdents(const std::string& aFilter); @@ -151,19 +141,6 @@ FGAirport::getIteratorForRunwayIdent(const string& aIdent) const return it; // end() } -static double normaliseBearing(double aBearing) -{ - while (aBearing < -180) { - aBearing += 360.0; - } - - while (aBearing > 180.0) { - aBearing -= 360.0; - } - - return aBearing; -} - FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const { Runway_iterator it = mRunways.begin(); @@ -179,7 +156,8 @@ FGRunway* FGAirport::findBestRunwayForHeading(double aHeading) const for (; it != mRunways.end(); ++it) { double good = (*it)->score(lengthWeight, widthWeight, surfaceWeight); - double dev = normaliseBearing(aHeading - (*it)->headingDeg()); + double dev = aHeading - (*it)->headingDeg(); + SG_NORMALIZE_RANGE(dev, -180.0, 180.0); double bad = fabs(deviationWeight * dev) + 1e-20; double quality = good / bad; @@ -308,49 +286,6 @@ char** FGAirport::searchNamesAndIdents(const std::string& aFilter) return searchAirportNamesAndIdents(aFilter); } -/****************************************************************************** - * FGAirportList - *****************************************************************************/ - -FGAirportList::FGAirportList() -{ -} - - -FGAirportList::~FGAirportList( void ) -{ - for (unsigned int i = 0; i < airports_array.size(); ++i) { - delete airports_array[i]; - } -} - - -// add an entry to the list -FGAirport* FGAirportList::add( const string &id, const SGGeod& location, const SGGeod& tower_location, - const string &name, bool has_metar, FGPositioned::Type aType) -{ - FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar, aType); - // try and read in an auxilary file - airports_array.push_back( a ); - return a; -} - -int -FGAirportList::size () const -{ - return airports_array.size(); -} - - -const FGAirport *FGAirportList::getAirport( unsigned int index ) const -{ - if (index < airports_array.size()) { - return(airports_array[index]); - } else { - return(NULL); - } -} - // find basic airport location info from airport database const FGAirport *fgFindAirportID( const string& id) { diff --git a/src/Airports/simple.hxx b/src/Airports/simple.hxx index 6d95bcf87..f79b6187b 100644 --- a/src/Airports/simple.hxx +++ b/src/Airports/simple.hxx @@ -156,40 +156,6 @@ private: std::vector mTaxiways; }; -typedef std::vector < FGAirport * > airport_list; -typedef airport_list::iterator airport_list_iterator; -typedef airport_list::const_iterator const_airport_list_iterator; - - - -class FGAirportList { -private: - - airport_list airports_array; - -public: - // Constructor (new) - FGAirportList(); - - // Destructor - ~FGAirportList(); - - // add an entry to the list - FGAirport* add( const std::string& id, const SGGeod& location, const SGGeod& tower, - const std::string& name, bool has_metar, FGPositioned::Type aType); - - /** - * Return the number of airports in the list. - */ - int size() const; - - /** - * Return a specific airport, by position. - */ - const FGAirport *getAirport( unsigned int index ) const; - -}; - // find basic airport location info from airport database const FGAirport *fgFindAirportID( const std::string& id); diff --git a/src/GUI/AirportList.cxx b/src/GUI/AirportList.cxx index 133b2b9ea..bcbe06e09 100644 --- a/src/GUI/AirportList.cxx +++ b/src/GUI/AirportList.cxx @@ -2,17 +2,14 @@ # include "config.h" #endif -#include #include
#include #include "AirportList.hxx" - AirportList::AirportList(int x, int y, int width, int height) : puaList(x, y, width, height), GUI_ID(FGCLASS_AIRPORTLIST), - _airports(globals->get_airports()), _content(0) { create_list(); @@ -28,28 +25,9 @@ AirportList::~AirportList() void AirportList::create_list() { - const std::ctype &ct = std::use_facet >(std::locale()); - int num_apt = _airports->size(); - char **content = new char *[num_apt + 1]; - - int n = 0; - for (int i = 0; i < num_apt; i++) { - const FGAirport *apt = _airports->getAirport(i); - std::string entry(' ' + apt->getName() + " (" + apt->getId() + ')'); - - if (!_filter.empty()) { - std::string upper(entry.data()); - ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size()); - - if (upper.find(_filter) == std::string::npos) - continue; - } - - content[n] = new char[entry.size() + 1]; - strcpy(content[n], entry.c_str()); - n++; - } - content[n] = 0; + char **content = FGAirport::searchNamesAndIdents(_filter); + int n = (content[0] != NULL) ? 1 : 0; + // work around plib 2006/04/18 bug: lists with no entries cause crash on arrow-up newList(n > 0 ? content : 0); diff --git a/src/GUI/AirportList.hxx b/src/GUI/AirportList.hxx index dabd69778..bc745930c 100644 --- a/src/GUI/AirportList.hxx +++ b/src/GUI/AirportList.hxx @@ -19,7 +19,6 @@ public: virtual void setValue(const char *); private: - FGAirportList *_airports; char **_content; std::string _filter; }; diff --git a/src/Instrumentation/KLN89/kln89.cxx b/src/Instrumentation/KLN89/kln89.cxx index 70c948fd9..6ee1c21ac 100644 --- a/src/Instrumentation/KLN89/kln89.cxx +++ b/src/Instrumentation/KLN89/kln89.cxx @@ -577,7 +577,6 @@ void KLN89::DrawMap(bool draw_avs) { // Annotation then gets drawn by Nav page, NOT this function. if(_drawApt && draw_avs) { - airport_list apt; /* bool have_apt = _overlays->FindArpByRegion(&apt, bottomLeft.lat(), bottomLeft.lon(), topRight.lat(), topRight.lon()); //cout << "Vors enclosed are: "; diff --git a/src/Main/fg_init.cxx b/src/Main/fg_init.cxx index bc24739af..c3cebfe09 100644 --- a/src/Main/fg_init.cxx +++ b/src/Main/fg_init.cxx @@ -965,10 +965,7 @@ fgInitNav () SGPath p_metar( globals->get_fg_root() ); p_metar.append( "Airports/metar.dat" ); - FGAirportList *airports = new FGAirportList(); - globals->set_airports( airports ); - - fgAirportDBLoad( airports, aptdb.str(), p_metar.str() ); + fgAirportDBLoad( aptdb.str(), p_metar.str() ); FGNavList *navlist = new FGNavList; FGNavList *loclist = new FGNavList; diff --git a/src/Main/globals.cxx b/src/Main/globals.cxx index 1bcbbea67..782a229a8 100644 --- a/src/Main/globals.cxx +++ b/src/Main/globals.cxx @@ -47,7 +47,6 @@ #include #include #include -#include #include #include @@ -83,7 +82,6 @@ FGGlobals::FGGlobals() : route_mgr( NULL ), current_panel( NULL ), soundmgr( NULL ), - airports( NULL ), ATC_mgr( NULL ), AI_mgr( NULL ), controls( NULL ), @@ -133,7 +131,6 @@ FGGlobals::~FGGlobals() delete route_mgr; delete current_panel; delete soundmgr; - delete airports; delete ATC_mgr; delete AI_mgr; diff --git a/src/Main/globals.hxx b/src/Main/globals.hxx index 4b21c77f8..d962bae2c 100644 --- a/src/Main/globals.hxx +++ b/src/Main/globals.hxx @@ -54,7 +54,6 @@ class SGEventMgr; class SGSubsystemMgr; class SGSubsystem; -class FGAirportList; class FGAIMgr; class FGATCMgr; class FGAircraftModel; @@ -137,9 +136,6 @@ private: // sound manager SGSoundMgr *soundmgr; - // Simple Airport List - FGAirportList *airports; - // ATC manager FGATCMgr *ATC_mgr; @@ -243,9 +239,6 @@ public: inline SGMaterialLib *get_matlib() const { return matlib; } inline void set_matlib( SGMaterialLib *m ) { matlib = m; } - inline FGAirportList *get_airports() const { return airports; } - inline void set_airports( FGAirportList *a ) {airports = a; } - inline FGATCMgr *get_ATC_mgr() const { return ATC_mgr; } inline void set_ATC_mgr( FGATCMgr *a ) {ATC_mgr = a; } diff --git a/src/Navaids/positioned.cxx b/src/Navaids/positioned.cxx index a705c8495..b01418a17 100644 --- a/src/Navaids/positioned.cxx +++ b/src/Navaids/positioned.cxx @@ -370,6 +370,7 @@ char** searchAirportNamesAndIdents(const std::string& aFilter) // may get very large and smart-pointer-atomicity-locking then becomes a // bottleneck for this case. std::vector matches; + std::string upper; for (; it != end; ++it) { FGPositioned::Type ty = it->second->type(); @@ -377,10 +378,12 @@ char** searchAirportNamesAndIdents(const std::string& aFilter) continue; } - if (hasFilter && - (it->second->name().find(aFilter) == std::string::npos) && - (it->second->ident().find(aFilter) == std::string::npos)) { - continue; + if (hasFilter && (it->second->ident().find(aFilter) == std::string::npos)) { + upper = it->second->name(); // string copy, sadly + ct.toupper((char *)upper.data(), (char *)upper.data() + upper.size()); + if (upper.find(aFilter) == std::string::npos) { + continue; + } } matches.push_back(it->second); @@ -396,23 +399,27 @@ char** searchAirportNamesAndIdents(const std::string& aFilter) // nasty code to avoid excessive string copying and allocations. // We format results as follows (note whitespace!): - // ' name-of-airport-chars (icao)' + // ' name-of-airport-chars (ident)' // so the total length is: - // 1 + strlen(name) + 4 + 4 (for the ICAO) + 1 + 1 (for the null) + // 1 + strlen(name) + 4 + 4 (for the ident) + 1 + 1 (for the null) // which gives a grand total of 11 + the length of the name. - + // note the ident is sometimes only three letters for non-ICAO small strips for (unsigned int i=0; iname().size(); + int icaoLength = matches[i]->ident().size(); char* entry = new char[nameLength + 11]; - entry[0] = ' '; - memcpy(entry + 1, matches[i]->name().c_str(), nameLength); - entry[nameLength + 1] = ' '; - entry[nameLength + 2] = ' '; - entry[nameLength + 3] = ' '; - entry[nameLength + 4] = '('; - memcpy(entry + nameLength + 5, matches[i]->ident().c_str(), 4); - entry[nameLength + 9] = ')'; - entry[nameLength + 10] = 0; + char* dst = entry; + *dst++ = ' '; + memcpy(dst, matches[i]->name().c_str(), nameLength); + dst += nameLength; + *dst++ = ' '; + *dst++ = ' '; + *dst++ = ' '; + *dst++ = '('; + memcpy(dst, matches[i]->ident().c_str(), icaoLength); + dst += icaoLength; + *dst++ = ')'; + *dst++ = 0; result[i] = entry; }