return (itr == airports_by_id.end() ? NULL : itr->second);
}
-// wrap an FGIdentOrdering in an STL-compatible functor. not the most
-// efficent / pretty thing in the world, but avoids template nastiness in the
-// headers, and we're only doing O(log(N)) comparisoms per search
-class orderingFunctor
-{
-public:
- orderingFunctor(FGIdentOrdering* aOrder) :
- mOrdering(aOrder)
- { assert(aOrder); }
-
- bool operator()(const airport_map::value_type& aA, const std::string& aB) const
- {
- return mOrdering->compare(aA.first,aB);
- }
-
- bool operator()(const std::string& aA, const airport_map::value_type& aB) const
- {
- return mOrdering->compare(aA, aB.first);
- }
-
- bool operator()(const airport_map::value_type& aA, const airport_map::value_type& aB) const
- {
- return mOrdering->compare(aA.first, aB.first);
- }
-
-private:
- FGIdentOrdering* mOrdering;
-};
-
-const FGAirport* FGAirportList::findFirstById(const std::string& aIdent, FGIdentOrdering* aOrder)
-{
- airport_map_iterator itr;
- if (aOrder) {
- orderingFunctor func(aOrder);
- itr = std::lower_bound(airports_by_id.begin(),airports_by_id.end(), aIdent, func);
- } else {
- itr = airports_by_id.lower_bound(aIdent);
- }
-
- if (itr == airports_by_id.end()) {
- return NULL;
- }
-
- return itr->second;
-}
-
// search for the airport nearest the specified position
FGAirport* FGAirportList::search(double lon_deg, double lat_deg, double max_range)
{
virtual bool pass(FGAirport*) { return true; }
};
-class FGIdentOrdering {
-public:
- virtual ~FGIdentOrdering()
- { ; }
-
- virtual bool compare(const std::string& aA, const std::string& aB) const
- { return aA < aB; }
-};
-
typedef std::map < std::string, FGAirport* > airport_map;
typedef airport_map::iterator airport_map_iterator;
typedef airport_map::const_iterator const_airport_map_iterator;
// Returns NULL if unsucessfull.
FGAirport* search( const std::string& id );
- // Search for the next airport in ASCII sequence to the supplied id.
- // eg. id = "KDC" or "KDCA" would both return "KDCA".
- // NOTE: Numbers come prior to A-Z in ASCII sequence so id = "LD" would return "LD57", not "LDDP"
- // optional ordering can make letters come before numbers
- // Implementation assumes airport codes are unique.
- // Returns NULL if unsucessfull.
- const FGAirport* findFirstById(const std::string& aIdent, FGIdentOrdering* aOrder = NULL);
-
// search for the airport closest to the specified position
// (currently a linear inefficient search so it's probably not
// best to use this at runtime.) An FGAirportSearchFilter class
*/
const FGAirport *getAirport( unsigned int index ) const;
- /**
- * Return a pointer to the raw airport list
- */
- inline const airport_list* getAirportList() { return (&airports_array); }
-
/**
* Mark the specified airport record as not having metar
*/
/***************************************/
-/**
- * STL functor for use with algorithms. This comapres strings according to
- * the KLN-89's notion of ordering, with digits after letters.
- * Also implements FGIdentOrdering so it can be passed into the various list
- * find helpers.
- */
-
-class stringOrderKLN89 : public FGIdentOrdering
-{
-public:
- bool operator()(const gps_waypoint_map::value_type& aA, const std::string& aB) const
- {
- return compare(aA.first, aB);
- }
-
- bool operator()(const std::string& aS1, const std::string& aS2) const
- {
- return compare(aS1, aS2);
- }
-
- virtual bool compare(const std::string& aS1, const std::string& aS2) const
- {
- if (aS1.empty()) return true;
- if (aS2.empty()) return false;
-
- char* a = (char*) aS1.c_str();
- char* b = (char*) aS2.c_str();
-
- for ( ; *a && *b; ++a, ++b) {
- if (*a == *b) continue;
-
- bool aDigit = isdigit(*a);
- bool bDigit = isdigit(*b);
-
- if (aDigit == bDigit) {
- return (*a < *b); // we already know they're not equal
- }
-
- // digit-ness differs
- if (aDigit) return false; // s1 = KS9 goes *after* s2 = KSA
- assert(bDigit);
- return true; // s1 = KSF, s2 = KS5, s1 is indeed < s2
- }
-
- if (*b) return true; // *a == 0, s2 is longer
- return false; // s1 is longer, or strings are equal
- }
-};
-
class DCLGPSFilter : public FGPositioned::Filter
{
public: