]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/simple.cxx
This should apply, and everything should build cleanly, in isolation from the
[flightgear.git] / src / Airports / simple.cxx
index 6efac4c0e25a853ee85d117a983184d65c0a34cd..5c9330bd59142762e635a6daaff86973a5201d50 100644 (file)
@@ -47,7 +47,7 @@
 #include <Main/fg_props.hxx>
 #include <Airports/runways.hxx>
 
-#include STL_STRING
+#include <string>
 
 #include "simple.hxx"
 #include "xmlloader.hxx"
@@ -187,25 +187,35 @@ const FGAirport* FGAirportList::findFirstById( const string& id, bool exact )
 
 
 // search for the airport nearest the specified position
-FGAirport* FGAirportList::search( double lon_deg, double lat_deg,
-                                  bool with_metar )
+FGAirport* FGAirportList::search(double lon_deg, double lat_deg)
+{
+    static FGAirportSearchFilter accept_any;
+    return search(lon_deg, lat_deg, accept_any);
+}
+
+
+// search for the airport nearest the specified position and
+// passing the filter
+FGAirport* FGAirportList::search(double lon_deg, double lat_deg,
+        FGAirportSearchFilter& filter)
 {
-    int closest = -1;
     double min_dist = 360.0;
-    unsigned int i;
-    for ( i = 0; i < airports_array.size(); ++i ) {
+    airport_list_iterator it = airports_array.begin();
+    airport_list_iterator end = airports_array.end();
+    airport_list_iterator closest = end;
+    for (; it != end; ++it) {
+        if (!filter.pass(*it))
+            continue;
+
         // crude manhatten distance based on lat/lon difference
-        double d = fabs(lon_deg - airports_array[i]->getLongitude())
-            + fabs(lat_deg - airports_array[i]->getLatitude());
-        if ( d < min_dist ) {
-            if ( !with_metar || (with_metar&&airports_array[i]->getMetar()) ) {
-                closest = i;
-                min_dist = d;
-            }
+        double d = fabs(lon_deg - (*it)->getLongitude())
+                + fabs(lat_deg - (*it)->getLatitude());
+        if (d < min_dist) {
+            closest = it;
+            min_dist = d;
         }
     }
-
-    return ( closest > -1 ? airports_array[closest] : NULL );
+    return closest != end ? *closest : 0;
 }