From: James Turner Date: Sat, 26 Oct 2013 21:53:24 +0000 (+0100) Subject: Experimental sorter for airports. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=c72ac270989d5725ac5a4105a12b210bdb0bf51a;p=flightgear.git Experimental sorter for airports. Sort by size (cumulative runway length). --- diff --git a/src/Airports/airport.cxx b/src/Airports/airport.cxx index 6d463fd54..42d76f5ba 100644 --- a/src/Airports/airport.cxx +++ b/src/Airports/airport.cxx @@ -889,6 +889,46 @@ FGAirport::commStationsOfType(FGPositioned::Type aTy) const return result; } +class AirportWithSize +{ +public: + AirportWithSize(FGPositionedRef pos) : + _pos(pos), + _sizeMetric(0) + { + assert(pos->type() == FGPositioned::AIRPORT); + FGAirport* apt = static_cast(pos.get()); + BOOST_FOREACH(FGRunway* rwy, apt->getRunwaysWithoutReciprocals()) { + _sizeMetric += static_cast(rwy->lengthFt()); + } + } + + bool operator<(const AirportWithSize& other) const + { + return _sizeMetric < other._sizeMetric; + } + + FGPositionedRef pos() const + { return _pos; } +private: + FGPositionedRef _pos; + unsigned int _sizeMetric; + +}; + +void FGAirport::sortBySize(FGPositionedList& airportList) +{ + std::vector annotated; + BOOST_FOREACH(FGPositionedRef p, airportList) { + annotated.push_back(AirportWithSize(p)); + } + std::sort(annotated.begin(), annotated.end()); + + for (unsigned int i=0; i