- unify coding style (though not to the last detail)
- remove trailing spaces - fix mixed indentation (tabs -> 8 spaces) - throw out braindead FSF coding style that has somehow sneaked in
This commit is contained in:
parent
2c20ef1c7f
commit
62bdd89fd7
2 changed files with 120 additions and 118 deletions
|
@ -1,6 +1,6 @@
|
||||||
//
|
//
|
||||||
// simple.cxx -- a really simplistic class to manage airport ID,
|
// simple.cxx -- a really simplistic class to manage airport ID,
|
||||||
// lat, lon of the center of one of it's runways, and
|
// lat, lon of the center of one of it's runways, and
|
||||||
// elevation in feet.
|
// elevation in feet.
|
||||||
//
|
//
|
||||||
// Written by Curtis Olson, started April 1998.
|
// Written by Curtis Olson, started April 1998.
|
||||||
|
@ -57,28 +57,27 @@ SG_USING_STD(random_shuffle);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***************************************************************************
|
/***************************************************************************
|
||||||
* FGAirport
|
* FGAirport
|
||||||
***************************************************************************/
|
***************************************************************************/
|
||||||
FGAirport::FGAirport() : _longitude(0), _latitude(0), _elevation(0)
|
FGAirport::FGAirport() : _longitude(0), _latitude(0), _elevation(0)
|
||||||
{
|
{
|
||||||
dynamics = 0;
|
dynamics = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FGAirport::FGAirport(const string &id, double lon, double lat, double elev, const string &name, bool has_metar)
|
FGAirport::FGAirport(const string &id, double lon, double lat, double elev, const string &name, bool has_metar)
|
||||||
{
|
{
|
||||||
_id = id;
|
_id = id;
|
||||||
_longitude = lon;
|
_longitude = lon;
|
||||||
_latitude = lat;
|
_latitude = lat;
|
||||||
_elevation = elev;
|
_elevation = elev;
|
||||||
_name = name;
|
_name = name;
|
||||||
_has_metar = has_metar;
|
_has_metar = has_metar;
|
||||||
dynamics = 0;
|
dynamics = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FGAirport::~FGAirport()
|
FGAirport::~FGAirport()
|
||||||
{
|
{
|
||||||
delete dynamics;
|
delete dynamics;
|
||||||
|
@ -87,52 +86,48 @@ FGAirport::~FGAirport()
|
||||||
|
|
||||||
FGAirportDynamics * FGAirport::getDynamics()
|
FGAirportDynamics * FGAirport::getDynamics()
|
||||||
{
|
{
|
||||||
|
if (dynamics != 0) {
|
||||||
if (dynamics != 0)
|
return dynamics;
|
||||||
return dynamics;
|
} else {
|
||||||
else
|
FGRunwayPreference rwyPrefs;
|
||||||
{
|
//cerr << "Trying to load dynamics for " << _id << endl;
|
||||||
FGRunwayPreference rwyPrefs;
|
dynamics = new FGAirportDynamics(_latitude, _longitude, _elevation, _id);
|
||||||
//cerr << "Trying to load dynamics for " << _id << endl;
|
|
||||||
dynamics = new FGAirportDynamics(_latitude, _longitude, _elevation, _id);
|
|
||||||
|
|
||||||
SGPath parkpath( globals->get_fg_root() );
|
SGPath parkpath( globals->get_fg_root() );
|
||||||
parkpath.append( "/Airports/AI/" );
|
parkpath.append( "/Airports/AI/" );
|
||||||
parkpath.append(_id);
|
parkpath.append(_id);
|
||||||
parkpath.append("parking.xml");
|
parkpath.append("parking.xml");
|
||||||
|
|
||||||
SGPath rwyPrefPath( globals->get_fg_root() );
|
SGPath rwyPrefPath( globals->get_fg_root() );
|
||||||
rwyPrefPath.append( "/Airports/AI/" );
|
rwyPrefPath.append( "/Airports/AI/" );
|
||||||
rwyPrefPath.append(_id);
|
rwyPrefPath.append(_id);
|
||||||
rwyPrefPath.append("rwyuse.xml");
|
rwyPrefPath.append("rwyuse.xml");
|
||||||
//if (ai_dirs.find(id.c_str()) != ai_dirs.end()
|
|
||||||
// && parkpath.exists())
|
//if (ai_dirs.find(id.c_str()) != ai_dirs.end()
|
||||||
if (parkpath.exists())
|
// && parkpath.exists())
|
||||||
{
|
if (parkpath.exists()) {
|
||||||
try {
|
try {
|
||||||
readXML(parkpath.str(),*dynamics);
|
readXML(parkpath.str(),*dynamics);
|
||||||
dynamics->init();
|
dynamics->init();
|
||||||
}
|
} catch (const sg_exception &e) {
|
||||||
catch (const sg_exception &e) {
|
//cerr << "unable to read " << parkpath.str() << endl;
|
||||||
//cerr << "unable to read " << parkpath.str() << endl;
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
//if (ai_dirs.find(id.c_str()) != ai_dirs.end()
|
//if (ai_dirs.find(id.c_str()) != ai_dirs.end()
|
||||||
// && rwyPrefPath.exists())
|
// && rwyPrefPath.exists())
|
||||||
if (rwyPrefPath.exists())
|
if (rwyPrefPath.exists()) {
|
||||||
{
|
try {
|
||||||
try {
|
readXML(rwyPrefPath.str(), rwyPrefs);
|
||||||
readXML(rwyPrefPath.str(), rwyPrefs);
|
dynamics->setRwyUse(rwyPrefs);
|
||||||
dynamics->setRwyUse(rwyPrefs);
|
} catch (const sg_exception &e) {
|
||||||
}
|
//cerr << "unable to read " << rwyPrefPath.str() << endl;
|
||||||
catch (const sg_exception &e) {
|
//exit(1);
|
||||||
//cerr << "unable to read " << rwyPrefPath.str() << endl;
|
}
|
||||||
//exit(1);
|
}
|
||||||
}
|
//exit(1);
|
||||||
}
|
|
||||||
//exit(1);
|
|
||||||
}
|
}
|
||||||
return dynamics;
|
return dynamics;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -151,7 +146,7 @@ FGAirportDynamics * FGAirport::getDynamics()
|
||||||
// in the base package.
|
// in the base package.
|
||||||
//
|
//
|
||||||
// Note: 2005/12/23: This is probably not necessary anymore, because I'm
|
// Note: 2005/12/23: This is probably not necessary anymore, because I'm
|
||||||
// Switching to runtime airport dynamics loading (DT).
|
// Switching to runtime airport dynamics loading (DT).
|
||||||
FGAirportList::FGAirportList()
|
FGAirportList::FGAirportList()
|
||||||
{
|
{
|
||||||
// ulDir* d;
|
// ulDir* d;
|
||||||
|
@ -168,8 +163,9 @@ FGAirportList::FGAirportList()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
FGAirportList::~FGAirportList( void ) {
|
FGAirportList::~FGAirportList( void )
|
||||||
for(unsigned int i = 0; i < airports_array.size(); ++i) {
|
{
|
||||||
|
for (unsigned int i = 0; i < airports_array.size(); ++i) {
|
||||||
delete airports_array[i];
|
delete airports_array[i];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -183,10 +179,9 @@ void FGAirportList::add( const string &id, const double longitude,
|
||||||
FGRunwayPreference rwyPrefs;
|
FGRunwayPreference rwyPrefs;
|
||||||
FGAirport* a = new FGAirport(id, longitude, latitude, elevation, name, has_metar);
|
FGAirport* a = new FGAirport(id, longitude, latitude, elevation, name, has_metar);
|
||||||
|
|
||||||
|
|
||||||
airports_by_id[a->getId()] = a;
|
airports_by_id[a->getId()] = a;
|
||||||
// try and read in an auxilary file
|
// try and read in an auxilary file
|
||||||
|
|
||||||
airports_array.push_back( a );
|
airports_array.push_back( a );
|
||||||
SG_LOG( SG_GENERAL, SG_BULK, "Adding " << id << " pos = " << longitude
|
SG_LOG( SG_GENERAL, SG_BULK, "Adding " << id << " pos = " << longitude
|
||||||
<< ", " << latitude << " elev = " << elevation );
|
<< ", " << latitude << " elev = " << elevation );
|
||||||
|
@ -194,31 +189,34 @@ void FGAirportList::add( const string &id, const double longitude,
|
||||||
|
|
||||||
|
|
||||||
// search for the specified id
|
// search for the specified id
|
||||||
FGAirport* FGAirportList::search( const string& id) {
|
FGAirport* FGAirportList::search( const string& id)
|
||||||
airport_map_iterator itr = airports_by_id.find(id);
|
{
|
||||||
return(itr == airports_by_id.end() ? NULL : itr->second);
|
airport_map_iterator itr = airports_by_id.find(id);
|
||||||
|
return (itr == airports_by_id.end() ? NULL : itr->second);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// search for first subsequent alphabetically to supplied id
|
// search for first subsequent alphabetically to supplied id
|
||||||
const FGAirport* FGAirportList::findFirstById( const string& id, bool exact ) {
|
const FGAirport* FGAirportList::findFirstById( const string& id, bool exact )
|
||||||
|
{
|
||||||
airport_map_iterator itr;
|
airport_map_iterator itr;
|
||||||
if(exact) {
|
if (exact) {
|
||||||
itr = airports_by_id.find(id);
|
itr = airports_by_id.find(id);
|
||||||
} else {
|
} else {
|
||||||
itr = airports_by_id.lower_bound(id);
|
itr = airports_by_id.lower_bound(id);
|
||||||
}
|
}
|
||||||
if(itr == airports_by_id.end()) {
|
if (itr == airports_by_id.end()) {
|
||||||
return(NULL);
|
return (NULL);
|
||||||
} else {
|
} else {
|
||||||
return(itr->second);
|
return (itr->second);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// search for the airport nearest the specified position
|
// search for the airport nearest the specified position
|
||||||
FGAirport* FGAirportList::search( double lon_deg, double lat_deg,
|
FGAirport* FGAirportList::search( double lon_deg, double lat_deg,
|
||||||
bool with_metar ) {
|
bool with_metar )
|
||||||
|
{
|
||||||
int closest = -1;
|
int closest = -1;
|
||||||
double min_dist = 360.0;
|
double min_dist = 360.0;
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
|
@ -244,9 +242,10 @@ FGAirportList::size () const
|
||||||
return airports_array.size();
|
return airports_array.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
const FGAirport *FGAirportList::getAirport( unsigned int index ) const
|
const FGAirport *FGAirportList::getAirport( unsigned int index ) const
|
||||||
{
|
{
|
||||||
if(index < airports_array.size()) {
|
if (index < airports_array.size()) {
|
||||||
return(airports_array[index]);
|
return(airports_array[index]);
|
||||||
} else {
|
} else {
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
@ -257,8 +256,9 @@ const FGAirport *FGAirportList::getAirport( unsigned int index ) const
|
||||||
/**
|
/**
|
||||||
* Mark the specified airport record as not having metar
|
* Mark the specified airport record as not having metar
|
||||||
*/
|
*/
|
||||||
void FGAirportList::no_metar( const string &id ) {
|
void FGAirportList::no_metar( const string &id )
|
||||||
if(airports_by_id.find(id) != airports_by_id.end()) {
|
{
|
||||||
|
if(airports_by_id.find(id) != airports_by_id.end()) {
|
||||||
airports_by_id[id]->setMetar(false);
|
airports_by_id[id]->setMetar(false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -267,14 +267,17 @@ void FGAirportList::no_metar( const string &id ) {
|
||||||
/**
|
/**
|
||||||
* Mark the specified airport record as (yes) having metar
|
* Mark the specified airport record as (yes) having metar
|
||||||
*/
|
*/
|
||||||
void FGAirportList::has_metar( const string &id ) {
|
void FGAirportList::has_metar( const string &id )
|
||||||
if(airports_by_id.find(id) != airports_by_id.end()) {
|
{
|
||||||
|
if(airports_by_id.find(id) != airports_by_id.end()) {
|
||||||
airports_by_id[id]->setMetar(true);
|
airports_by_id[id]->setMetar(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// find basic airport location info from airport database
|
// find basic airport location info from airport database
|
||||||
const FGAirport *fgFindAirportID( const string& id) {
|
const FGAirport *fgFindAirportID( const string& id)
|
||||||
|
{
|
||||||
const FGAirport* result = NULL;
|
const FGAirport* result = NULL;
|
||||||
if ( id.length() ) {
|
if ( id.length() ) {
|
||||||
SG_LOG( SG_GENERAL, SG_BULK, "Searching for airport code = " << id );
|
SG_LOG( SG_GENERAL, SG_BULK, "Searching for airport code = " << id );
|
||||||
|
@ -299,10 +302,8 @@ const FGAirport *fgFindAirportID( const string& id) {
|
||||||
|
|
||||||
|
|
||||||
// get airport elevation
|
// get airport elevation
|
||||||
double fgGetAirportElev( const string& id ) {
|
double fgGetAirportElev( const string& id )
|
||||||
|
{
|
||||||
// double lon, lat;
|
|
||||||
|
|
||||||
SG_LOG( SG_GENERAL, SG_BULK,
|
SG_LOG( SG_GENERAL, SG_BULK,
|
||||||
"Finding elevation for airport: " << id );
|
"Finding elevation for airport: " << id );
|
||||||
|
|
||||||
|
@ -314,15 +315,15 @@ double fgGetAirportElev( const string& id ) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// get airport position
|
|
||||||
Point3D fgGetAirportPos( const string& id ) {
|
|
||||||
// double lon, lat;
|
|
||||||
|
|
||||||
|
// get airport position
|
||||||
|
Point3D fgGetAirportPos( const string& id )
|
||||||
|
{
|
||||||
SG_LOG( SG_ATC, SG_BULK,
|
SG_LOG( SG_ATC, SG_BULK,
|
||||||
"Finding position for airport: " << id );
|
"Finding position for airport: " << id );
|
||||||
|
|
||||||
const FGAirport *a = fgFindAirportID( id);
|
const FGAirport *a = fgFindAirportID( id);
|
||||||
|
|
||||||
if (a) {
|
if (a) {
|
||||||
return Point3D(a->getLongitude(), a->getLatitude(), a->getElevation());
|
return Point3D(a->getLongitude(), a->getLatitude(), a->getElevation());
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
// simple.hxx -- a really simplistic class to manage airport ID,
|
// simple.hxx -- a really simplistic class to manage airport ID,
|
||||||
// lat, lon of the center of one of it's runways, and
|
// lat, lon of the center of one of it's runways, and
|
||||||
// elevation in feet.
|
// elevation in feet.
|
||||||
//
|
//
|
||||||
// Written by Curtis Olson, started April 1998.
|
// Written by Curtis Olson, started April 1998.
|
||||||
|
@ -28,9 +28,9 @@
|
||||||
#define _FG_SIMPLE_HXX
|
#define _FG_SIMPLE_HXX
|
||||||
|
|
||||||
|
|
||||||
#ifndef __cplusplus
|
#ifndef __cplusplus
|
||||||
# error This library requires C++
|
# error This library requires C++
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifdef HAVE_CONFIG_H
|
#ifdef HAVE_CONFIG_H
|
||||||
|
@ -39,7 +39,6 @@
|
||||||
#include <simgear/math/point3d.hxx>
|
#include <simgear/math/point3d.hxx>
|
||||||
|
|
||||||
#include <simgear/compiler.h>
|
#include <simgear/compiler.h>
|
||||||
//#include <simgear/xml/easyxml.hxx>
|
|
||||||
|
|
||||||
#include STL_STRING
|
#include STL_STRING
|
||||||
#include <map>
|
#include <map>
|
||||||
|
@ -64,38 +63,41 @@ SG_USING_STD(vector);
|
||||||
**************************************************************************************/
|
**************************************************************************************/
|
||||||
class FGAirport {
|
class FGAirport {
|
||||||
private:
|
private:
|
||||||
string _id;
|
string _id;
|
||||||
double _longitude; // degrees
|
double _longitude; // degrees
|
||||||
double _latitude; // degrees
|
double _latitude; // degrees
|
||||||
double _elevation; // ft
|
double _elevation; // ft
|
||||||
string _name;
|
string _name;
|
||||||
bool _has_metar;
|
bool _has_metar;
|
||||||
FGAirportDynamics *dynamics;
|
FGAirportDynamics *dynamics;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
FGAirport();
|
FGAirport();
|
||||||
// FGAirport(const FGAirport &other);
|
// FGAirport(const FGAirport &other);
|
||||||
FGAirport(const string& id, double lon, double lat, double elev, const string& name, bool has_metar);
|
FGAirport(const string& id, double lon, double lat, double elev, const string& name, bool has_metar);
|
||||||
~FGAirport();
|
~FGAirport();
|
||||||
|
|
||||||
string getId() const { return _id;};
|
string getId() const { return _id; }
|
||||||
const string &getName() const { return _name;};
|
const string &getName() const { return _name; }
|
||||||
double getLongitude() const { return _longitude;};
|
double getLongitude() const { return _longitude; }
|
||||||
// Returns degrees
|
// Returns degrees
|
||||||
double getLatitude() const { return _latitude; };
|
double getLatitude() const { return _latitude; }
|
||||||
// Returns ft
|
// Returns ft
|
||||||
double getElevation() const { return _elevation;};
|
double getElevation() const { return _elevation; }
|
||||||
bool getMetar() const { return _has_metar;};
|
bool getMetar() const { return _has_metar; }
|
||||||
|
|
||||||
void setId(const string& id) { _id = id;};
|
void setId(const string& id) { _id = id; }
|
||||||
void setMetar(bool value) { _has_metar = value; };
|
void setMetar(bool value) { _has_metar = value; }
|
||||||
|
|
||||||
|
FGAirportDynamics *getDynamics();
|
||||||
|
|
||||||
FGAirportDynamics *getDynamics();
|
|
||||||
private:
|
private:
|
||||||
FGAirport operator=(FGAirport &other);
|
FGAirport operator=(FGAirport &other);
|
||||||
FGAirport(const FGAirport&);
|
FGAirport(const FGAirport&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
typedef map < string, FGAirport* > airport_map;
|
typedef map < string, FGAirport* > airport_map;
|
||||||
typedef airport_map::iterator airport_map_iterator;
|
typedef airport_map::iterator airport_map_iterator;
|
||||||
typedef airport_map::const_iterator const_airport_map_iterator;
|
typedef airport_map::const_iterator const_airport_map_iterator;
|
||||||
|
@ -105,16 +107,15 @@ typedef airport_list::iterator airport_list_iterator;
|
||||||
typedef airport_list::const_iterator const_airport_list_iterator;
|
typedef airport_list::const_iterator const_airport_list_iterator;
|
||||||
|
|
||||||
|
|
||||||
class FGAirportList {
|
|
||||||
|
|
||||||
|
class FGAirportList {
|
||||||
private:
|
private:
|
||||||
|
|
||||||
airport_map airports_by_id;
|
airport_map airports_by_id;
|
||||||
airport_list airports_array;
|
airport_list airports_array;
|
||||||
//set < string > ai_dirs;
|
//set < string > ai_dirs;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
// Constructor (new)
|
// Constructor (new)
|
||||||
FGAirportList();
|
FGAirportList();
|
||||||
|
|
||||||
|
@ -128,7 +129,7 @@ public:
|
||||||
// search for the specified id.
|
// search for the specified id.
|
||||||
// Returns NULL if unsucessfull.
|
// Returns NULL if unsucessfull.
|
||||||
FGAirport* search( const string& id );
|
FGAirport* search( const string& id );
|
||||||
|
|
||||||
// Search for the next airport in ASCII sequence to the supplied id.
|
// Search for the next airport in ASCII sequence to the supplied id.
|
||||||
// eg. id = "KDC" or "KDCA" would both return "KDCA".
|
// eg. id = "KDC" or "KDCA" would both return "KDCA".
|
||||||
// If exact = true then only exact matches are returned.
|
// If exact = true then only exact matches are returned.
|
||||||
|
@ -141,7 +142,7 @@ public:
|
||||||
// (currently a linear inefficient search so it's probably not
|
// (currently a linear inefficient search so it's probably not
|
||||||
// best to use this at runtime.) If with_metar is true, then only
|
// best to use this at runtime.) If with_metar is true, then only
|
||||||
// return station id's marked as having metar data.
|
// return station id's marked as having metar data.
|
||||||
// Returns NULL if fails (unlikely unless none have metar and with_metar spec'd!)
|
// Returns NULL if fails (unlikely unless none have metar and with_metar spec'd!)
|
||||||
FGAirport* search( double lon_deg, double lat_deg, bool with_metar );
|
FGAirport* search( double lon_deg, double lat_deg, bool with_metar );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -153,11 +154,11 @@ public:
|
||||||
* Return a specific airport, by position.
|
* Return a specific airport, by position.
|
||||||
*/
|
*/
|
||||||
const FGAirport *getAirport( unsigned int index ) const;
|
const FGAirport *getAirport( unsigned int index ) const;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return a pointer to the raw airport list
|
* Return a pointer to the raw airport list
|
||||||
*/
|
*/
|
||||||
inline const airport_list* getAirportList() { return(&airports_array); }
|
inline const airport_list* getAirportList() { return (&airports_array); }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mark the specified airport record as not having metar
|
* Mark the specified airport record as not having metar
|
||||||
|
|
Loading…
Add table
Reference in a new issue