1
0
Fork 0

Alex Romosan: Make GpsPage::GetId() pure virtual, and pass strings by reference not value

This commit is contained in:
daveluff 2005-12-02 22:50:10 +00:00
parent 00e0546cab
commit 1de61c8afd
2 changed files with 24 additions and 25 deletions

View file

@ -194,8 +194,7 @@ string GPSPage::GPSitoa(int n) {
void GPSPage::CleanUp() {} void GPSPage::CleanUp() {}
void GPSPage::LooseFocus() {} void GPSPage::LooseFocus() {}
void GPSPage::SetId(string s) {} void GPSPage::SetId(const string& s) {}
string GPSPage::GetId() { return(""); }
// ------------------------------------------------------------------------------------- // // ------------------------------------------------------------------------------------- //
@ -888,7 +887,7 @@ double DCLGPS::GetCDIDeflection() const {
return((xtd / _currentCdiScale) * 5.0 * 2.5 * -1.0); return((xtd / _currentCdiScale) * 5.0 * 2.5 * -1.0);
} }
void DCLGPS::DtoInitiate(string s) { void DCLGPS::DtoInitiate(const string& s) {
cout << "DtoInitiate, s = " << s << '\n'; cout << "DtoInitiate, s = " << s << '\n';
bool multi; bool multi;
const GPSWaypoint* wp = FindFirstById(s, multi, true); const GPSWaypoint* wp = FindFirstById(s, multi, true);
@ -1013,7 +1012,7 @@ double DCLGPS::GetETE() {
// returns -1 if groundspeed is less than 30kts. // returns -1 if groundspeed is less than 30kts.
// If the waypoint is an unreached part of the active flight plan the time will be via each leg. // If the waypoint is an unreached part of the active flight plan the time will be via each leg.
// otherwise it will be a direct-to time. // otherwise it will be a direct-to time.
double DCLGPS::GetTimeToWaypoint(string id) { double DCLGPS::GetTimeToWaypoint(const string& id) {
if(_groundSpeed_kts < 30.0) { if(_groundSpeed_kts < 30.0) {
return(-1.0); return(-1.0);
} }
@ -1089,7 +1088,7 @@ int DCLGPS::GetActiveWaypointIndex() {
return(-1); return(-1);
} }
int DCLGPS::GetWaypointIndex(string id) { int DCLGPS::GetWaypointIndex(const string& id) {
for(unsigned int i=0; i<_flightPlans[0]->waypoints.size(); ++i) { for(unsigned int i=0; i<_flightPlans[0]->waypoints.size(); ++i) {
if(_flightPlans[0]->waypoints[i]->id == id) return((int)i); if(_flightPlans[0]->waypoints[i]->id == id) return((int)i);
} }
@ -1240,7 +1239,7 @@ void DCLGPS::CreateFlightPlan(GPSFlightPlan* fp, vector<string> ids, vector<GPSW
/***************************************/ /***************************************/
const GPSWaypoint* DCLGPS::ActualFindFirstById(string id, bool exact) { const GPSWaypoint* DCLGPS::ActualFindFirstById(const string& id, bool exact) {
gps_waypoint_map_const_iterator itr; gps_waypoint_map_const_iterator itr;
if(exact) { if(exact) {
itr = _waypoints.find(id); itr = _waypoints.find(id);
@ -1255,7 +1254,7 @@ const GPSWaypoint* DCLGPS::ActualFindFirstById(string id, bool exact) {
} }
} }
const GPSWaypoint* DCLGPS::FindFirstById(string id, bool &multi, bool exact) { const GPSWaypoint* DCLGPS::FindFirstById(const string& id, bool &multi, bool exact) {
multi = false; multi = false;
if(exact) return(ActualFindFirstById(id, exact)); if(exact) return(ActualFindFirstById(id, exact));
@ -1317,7 +1316,7 @@ const GPSWaypoint* DCLGPS::FindFirstById(string id, bool &multi, bool exact) {
// Host specific lookup functions // Host specific lookup functions
// TODO - add the ASCII / alphabetical stuff from the Atlas version // TODO - add the ASCII / alphabetical stuff from the Atlas version
FGNavRecord* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) { FGNavRecord* DCLGPS::FindFirstVorById(const string& id, bool &multi, bool exact) {
// NOTE - at the moment multi is never set. // NOTE - at the moment multi is never set.
multi = false; multi = false;
//if(exact) return(_overlays->FindFirstVorById(id, exact)); //if(exact) return(_overlays->FindFirstVorById(id, exact));
@ -1336,7 +1335,7 @@ FGNavRecord* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) {
return(NULL); // Shouldn't get here! return(NULL); // Shouldn't get here!
} }
#if 0 #if 0
Overlays::NAV* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) { Overlays::NAV* DCLGPS::FindFirstVorById(const string& id, bool &multi, bool exact) {
// NOTE - at the moment multi is never set. // NOTE - at the moment multi is never set.
multi = false; multi = false;
if(exact) return(_overlays->FindFirstVorById(id, exact)); if(exact) return(_overlays->FindFirstVorById(id, exact));
@ -1386,7 +1385,7 @@ Overlays::NAV* DCLGPS::FindFirstVorById(string id, bool &multi, bool exact) {
#endif //0 #endif //0
// TODO - add the ASCII / alphabetical stuff from the Atlas version // TODO - add the ASCII / alphabetical stuff from the Atlas version
FGNavRecord* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) { FGNavRecord* DCLGPS::FindFirstNDBById(const string& id, bool &multi, bool exact) {
// NOTE - at the moment multi is never set. // NOTE - at the moment multi is never set.
multi = false; multi = false;
//if(exact) return(_overlays->FindFirstVorById(id, exact)); //if(exact) return(_overlays->FindFirstVorById(id, exact));
@ -1405,7 +1404,7 @@ FGNavRecord* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) {
return(NULL); // Shouldn't get here! return(NULL); // Shouldn't get here!
} }
#if 0 #if 0
Overlays::NAV* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) { Overlays::NAV* DCLGPS::FindFirstNDBById(const string& id, bool &multi, bool exact) {
// NOTE - at the moment multi is never set. // NOTE - at the moment multi is never set.
multi = false; multi = false;
if(exact) return(_overlays->FindFirstNDBById(id, exact)); if(exact) return(_overlays->FindFirstNDBById(id, exact));
@ -1455,7 +1454,7 @@ Overlays::NAV* DCLGPS::FindFirstNDBById(string id, bool &multi, bool exact) {
#endif //0 #endif //0
// TODO - add the ASCII / alphabetical stuff from the Atlas version // TODO - add the ASCII / alphabetical stuff from the Atlas version
const FGFix* DCLGPS::FindFirstIntById(string id, bool &multi, bool exact) { const FGFix* DCLGPS::FindFirstIntById(const string& id, bool &multi, bool exact) {
// NOTE - at the moment multi is never set, and indeed can't be // NOTE - at the moment multi is never set, and indeed can't be
// since FG can only map one Fix per ID at the moment. // since FG can only map one Fix per ID at the moment.
multi = false; multi = false;
@ -1516,7 +1515,7 @@ const FGFix* DCLGPS::FindFirstIntById(string id, bool &multi, bool exact) {
return NULL; // Don't think we can ever get here. return NULL; // Don't think we can ever get here.
} }
const FGAirport* DCLGPS::FindFirstAptById(string id, bool &multi, bool exact) { const FGAirport* DCLGPS::FindFirstAptById(const string& id, bool &multi, bool exact) {
// NOTE - at the moment multi is never set. // NOTE - at the moment multi is never set.
//cout << "FindFirstAptById, id = " << id << '\n'; //cout << "FindFirstAptById, id = " << id << '\n';
multi = false; multi = false;

View file

@ -179,14 +179,14 @@ public:
virtual void LooseFocus(); virtual void LooseFocus();
// Allows pages that display info for a given ID to have it set/get if they implement these functions. // Allows pages that display info for a given ID to have it set/get if they implement these functions.
virtual void SetId(string s); virtual void SetId(const string& s);
virtual string GetId(); virtual const string& GetId()=0;
inline int GetSubPage() { return(_subPage); } inline int GetSubPage() { return(_subPage); }
inline int GetNSubPages() { return(_nSubPages); } inline int GetNSubPages() { return(_nSubPages); }
inline string GetName() { return(_name); } inline const string& GetName() { return(_name); }
protected: protected:
DCLGPS* _parent; DCLGPS* _parent;
@ -274,7 +274,7 @@ public:
// Returns -1 if no active waypoint. // Returns -1 if no active waypoint.
int GetActiveWaypointIndex(); int GetActiveWaypointIndex();
// Ditto for an arbitrary waypoint id // Ditto for an arbitrary waypoint id
int GetWaypointIndex(string id); int GetWaypointIndex(const string& id);
// Returns meters // Returns meters
inline float GetDistToActiveWaypoint() { return _dist2Act; } inline float GetDistToActiveWaypoint() { return _dist2Act; }
@ -292,7 +292,7 @@ public:
// returns -1 if groundspeed is less than 30kts. // returns -1 if groundspeed is less than 30kts.
// If the waypoint is an unreached part of the active flight plan the time will be via each leg. // If the waypoint is an unreached part of the active flight plan the time will be via each leg.
// otherwise it will be a direct-to time. // otherwise it will be a direct-to time.
double GetTimeToWaypoint(string id); double GetTimeToWaypoint(const string& id);
// Return true if waypoint alerting is occuring // Return true if waypoint alerting is occuring
inline bool GetWaypointAlert() const { return(_waypointAlert); } inline bool GetWaypointAlert() const { return(_waypointAlert); }
@ -313,7 +313,7 @@ public:
inline bool GetToFlag() const { return(_headingBugTo); } inline bool GetToFlag() const { return(_headingBugTo); }
// Initiate Direct To operation to the supplied ID. // Initiate Direct To operation to the supplied ID.
void DtoInitiate(string id); void DtoInitiate(const string& id);
// Cancel Direct To operation // Cancel Direct To operation
void DtoCancel(); void DtoCancel();
@ -377,14 +377,14 @@ protected:
gps_waypoint_map _waypoints; gps_waypoint_map _waypoints;
private: private:
// Worker function for the below. // Worker function for the below.
const GPSWaypoint* ActualFindFirstById(string id, bool exact = false); const GPSWaypoint* ActualFindFirstById(const string& id, bool exact = false);
protected: protected:
// Find first of any type of waypoint by id. (TODO - Possibly we should return multiple waypoints here). // Find first of any type of waypoint by id. (TODO - Possibly we should return multiple waypoints here).
const GPSWaypoint* FindFirstById(string id, bool &multi, bool exact = false); const GPSWaypoint* FindFirstById(const string& id, bool &multi, bool exact = false);
FGNavRecord* FindFirstVorById(string id, bool &multi, bool exact = false); FGNavRecord* FindFirstVorById(const string& id, bool &multi, bool exact = false);
FGNavRecord* FindFirstNDBById(string id, bool &multi, bool exact = false); FGNavRecord* FindFirstNDBById(const string& id, bool &multi, bool exact = false);
const FGAirport* FindFirstAptById(string id, bool &multi, bool exact = false); const FGAirport* FindFirstAptById(const string& id, bool &multi, bool exact = false);
const FGFix* FindFirstIntById(string id, bool &multi, bool exact = false); const FGFix* FindFirstIntById(const string& id, bool &multi, bool exact = false);
// Find the closest VOR to a position in RADIANS. // Find the closest VOR to a position in RADIANS.
FGNavRecord* FindClosestVor(double lat_rad, double lon_rad); FGNavRecord* FindClosestVor(double lat_rad, double lon_rad);