#include <Main/fg_props.hxx>
#include <Airports/runways.hxx>
-#include STL_STRING
+#include <string>
#include "simple.hxx"
#include "xmlloader.hxx"
/***************************************************************************
* FGAirport
***************************************************************************/
-FGAirport::FGAirport()
+FGAirport::FGAirport() : _dynamics(0)
{
- dynamics = 0;
}
-FGAirport::FGAirport(const string &id, const SGGeod& location, const SGGeod& tower_location, const string &name, bool has_metar)
+FGAirport::FGAirport(const string &id, const SGGeod& location, const SGGeod& tower_location,
+ const string &name, bool has_metar, bool is_airport, bool is_seaport,
+ bool is_heliport) :
+ _id(id),
+ _location(location),
+ _tower_location(tower_location),
+ _name(name),
+ _has_metar(has_metar),
+ _is_airport(is_airport),
+ _is_seaport(is_seaport),
+ _is_heliport(is_heliport),
+ _dynamics(0)
{
- _id = id;
- _location = location;
- _tower_location = tower_location;
- _name = name;
- _has_metar = has_metar;
- dynamics = 0;
}
FGAirport::~FGAirport()
{
- delete dynamics;
+ delete _dynamics;
}
FGAirportDynamics * FGAirport::getDynamics()
{
- if (dynamics != 0) {
- return dynamics;
+ if (_dynamics != 0) {
+ return _dynamics;
} else {
//cerr << "Trying to load dynamics for " << _id << endl;
- dynamics = new FGAirportDynamics(this);
- XMLLoader::load(dynamics);
+ _dynamics = new FGAirportDynamics(this);
+ XMLLoader::load(_dynamics);
FGRunwayPreference rwyPrefs(this);
XMLLoader::load(&rwyPrefs);
- dynamics->setRwyUse(rwyPrefs);
+ _dynamics->setRwyUse(rwyPrefs);
}
- return dynamics;
+ return _dynamics;
}
// add an entry to the list
void FGAirportList::add( const string &id, const SGGeod& location, const SGGeod& tower_location,
- const string &name, const bool has_metar )
+ const string &name, bool has_metar, bool is_airport, bool is_seaport,
+ bool is_heliport)
{
- FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar);
-
+ FGAirport* a = new FGAirport(id, location, tower_location, name, has_metar,
+ is_airport, is_seaport, is_heliport);
+
airports_by_id[a->getId()] = a;
// try and read in an auxilary file
-
+
airports_array.push_back( a );
SG_LOG( SG_GENERAL, SG_BULK, "Adding " << id << " pos = " << location.getLongitudeDeg()
<< ", " << location.getLatitudeDeg() << " elev = " << location.getElevationFt() );
// 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;
}