[prev in list] [next in list] [prev in thread] [next in thread] 

List:       flightgear-devel
Subject:    [Flightgear-devel] Re: KLN89 GPS added: cleanups [patch]
From:       Alex Romosan <romosan () sycorax ! lbl ! gov>
Date:       2005-11-30 23:22:39
Message-ID: 87y835sou8.fsf () sycorax ! lbl ! gov
[Download RAW message or body]

David Luff <daveluff@ntlworld.com> writes:

> I've added a KLN89 GPS unit hardcoded in C++ (OK'd by Curt).
> Briefly, since it's late, it's only included on the c172p 2D panel
> (--aircraft=c172p-2dpanel). It looks best at --geometry=1024x768
> since the fonts are at 1:1 pixellation at that resolution.

the attached patch replaces passing strings by value with passing them
by reference (string -> const string&) to avoid copying them
needlessly. also makes GetId() in GPSPage a pure virtual function.


["fgfs.patch" (text/x-patch)]

cvs diff: Diffing src/Instrumentation
Index: src/Instrumentation/dclgps.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/dclgps.cxx,v
retrieving revision 1.1
diff -u -r1.1 dclgps.cxx
--- src/Instrumentation/dclgps.cxx	30 Nov 2005 00:47:41 -0000	1.1
+++ src/Instrumentation/dclgps.cxx	30 Nov 2005 23:12:19 -0000
@@ -194,8 +194,7 @@
 
 void GPSPage::CleanUp() {}
 void GPSPage::LooseFocus() {}
-void GPSPage::SetId(string s) {}
-string GPSPage::GetId() { return(""); }
+void GPSPage::SetId(const string& s) {}
 
 // ------------------------------------------------------------------------------------- \
//  
@@ -888,7 +887,7 @@
 	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';
 	bool multi;
 	const GPSWaypoint* wp = FindFirstById(s, multi, true);
@@ -1013,7 +1012,7 @@
 // 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.  // otherwise it will be a direct-to time.
-double DCLGPS::GetTimeToWaypoint(string id) {
+double DCLGPS::GetTimeToWaypoint(const string& id) {
 	if(_groundSpeed_kts < 30.0) {
 		return(-1.0);
 	}
@@ -1089,7 +1088,7 @@
 	return(-1);
 }
 
-int DCLGPS::GetWaypointIndex(string id) {
+int DCLGPS::GetWaypointIndex(const string& id) {
 	for(unsigned int i=0; i<_flightPlans[0]->waypoints.size(); ++i) {
 		if(_flightPlans[0]->waypoints[i]->id == id) return((int)i);
 	}
@@ -1240,7 +1239,7 @@
 
 /***************************************/
 
-const GPSWaypoint* DCLGPS::ActualFindFirstById(string id, bool exact) {
+const GPSWaypoint* DCLGPS::ActualFindFirstById(const string& id, bool exact) {
     gps_waypoint_map_const_iterator itr;
     if(exact) {
         itr = _waypoints.find(id);
@@ -1255,7 +1254,7 @@
     }
 }
 
-const GPSWaypoint* DCLGPS::FindFirstById(string id, bool &multi, bool exact) {
+const GPSWaypoint* DCLGPS::FindFirstById(const string& id, bool &multi, bool exact) \
{  multi = false;
 	if(exact) return(ActualFindFirstById(id, exact));
 	
@@ -1317,7 +1316,7 @@
 
 // Host specific lookup functions
 // 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.
 	multi = false;
 	//if(exact) return(_overlays->FindFirstVorById(id, exact));
@@ -1336,7 +1335,7 @@
 	return(NULL);	// Shouldn't get here!
 }
 #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.
 	multi = false;
 	if(exact) return(_overlays->FindFirstVorById(id, exact));
@@ -1386,7 +1385,7 @@
 #endif //0
 
 // 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.
 	multi = false;
 	//if(exact) return(_overlays->FindFirstVorById(id, exact));
@@ -1405,7 +1404,7 @@
 	return(NULL);	// Shouldn't get here!
 }
 #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.
 	multi = false;
 	if(exact) return(_overlays->FindFirstNDBById(id, exact));
@@ -1455,7 +1454,7 @@
 #endif //0
 
 // 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
 	// since FG can only map one Fix per ID at the moment.
 	multi = false;
@@ -1516,7 +1515,7 @@
 	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.
 	//cout << "FindFirstAptById, id = " << id << '\n';
 	multi = false;
Index: src/Instrumentation/dclgps.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/dclgps.hxx,v
retrieving revision 1.1
diff -u -r1.1 dclgps.hxx
--- src/Instrumentation/dclgps.hxx	30 Nov 2005 00:47:41 -0000	1.1
+++ src/Instrumentation/dclgps.hxx	30 Nov 2005 23:12:19 -0000
@@ -179,14 +179,14 @@
 	virtual void LooseFocus();
 	
 	// 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 string GetId();
+	virtual void SetId(const string& s);
+	virtual const string& GetId()=0;
 	
 	inline int GetSubPage() { return(_subPage); }
 	
 	inline int GetNSubPages() { return(_nSubPages); }
 	
-	inline string GetName() { return(_name); }
+	inline const string& GetName() { return(_name); }
 	
 protected:
 	DCLGPS* _parent;
@@ -274,7 +274,7 @@
 	// Returns -1 if no active waypoint.
 	int GetActiveWaypointIndex();
 	// Ditto for an arbitrary waypoint id
-	int GetWaypointIndex(string id);
+	int GetWaypointIndex(const string& id);
 	
 	// Returns meters
 	inline float GetDistToActiveWaypoint() { return _dist2Act; }
@@ -292,7 +292,7 @@
 	// 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.  // otherwise it will be a direct-to time.
-	double GetTimeToWaypoint(string id);
+	double GetTimeToWaypoint(const string& id);
 	
 	// Return true if waypoint alerting is occuring
 	inline bool GetWaypointAlert() const { return(_waypointAlert); }
@@ -313,7 +313,7 @@
 	inline bool GetToFlag() const { return(_headingBugTo); }
 	
 	// Initiate Direct To operation to the supplied ID.
-	void DtoInitiate(string id);
+	void DtoInitiate(const string& id);
 	// Cancel Direct To operation
 	void DtoCancel();
 	
@@ -377,14 +377,14 @@
 	gps_waypoint_map _waypoints;
 private:
 	// Worker function for the below.
-	const GPSWaypoint* ActualFindFirstById(string id, bool exact = false);
+	const GPSWaypoint* ActualFindFirstById(const string& id, bool exact = false);
 protected:
 	// 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); 
-	FGNavRecord* FindFirstVorById(string id, bool &multi, bool exact = false);
-	FGNavRecord* FindFirstNDBById(string id, bool &multi, bool exact = false);
-	const FGAirport* FindFirstAptById(string id, bool &multi, bool exact = false);
-	const FGFix* FindFirstIntById(string id, bool &multi, bool exact = false);
+	const GPSWaypoint* FindFirstById(const string& id, bool &multi, bool exact = \
false);  +	FGNavRecord* FindFirstVorById(const string& id, bool &multi, bool exact = \
false); +	FGNavRecord* FindFirstNDBById(const string& id, bool &multi, bool exact = \
false); +	const FGAirport* FindFirstAptById(const 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.
 	FGNavRecord* FindClosestVor(double lat_rad, double lon_rad);
 
cvs diff: Diffing src/Instrumentation/KLN89
Index: src/Instrumentation/KLN89/kln89.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89.cxx,v
retrieving revision 1.1
diff -u -r1.1 kln89.cxx
--- src/Instrumentation/KLN89/kln89.cxx	30 Nov 2005 00:21:25 -0000	1.1
+++ src/Instrumentation/KLN89/kln89.cxx	30 Nov 2005 23:12:21 -0000
@@ -908,7 +908,7 @@
 // Draw an airport or waypoint label on the moving map
 // Specify position by the map pixel co-ordinate of the left or right, bottom, of \
the *visible* portion of the label.  // The black background quad will automatically \
                overlap this by 1 pixel.
-void KLN89::DrawLabel(string s, int x1, int y1, bool right_align) {
+void KLN89::DrawLabel(const string& s, int x1, int y1, bool right_align) {
 	MapToInstrument(x1, y1);
 	if(!right_align) {
 		for(unsigned int i=0; i<s.size(); ++i) {
Index: src/Instrumentation/KLN89/kln89.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89.hxx,v
retrieving revision 1.1
diff -u -r1.1 kln89.hxx
--- src/Instrumentation/KLN89/kln89.hxx	30 Nov 2005 00:21:25 -0000	1.1
+++ src/Instrumentation/KLN89/kln89.hxx	30 Nov 2005 23:12:21 -0000
@@ -240,7 +240,7 @@
 	// Draw an airport or waypoint label on the moving map
 	// Specify position by the map pixel co-ordinate of the left or right, bottom, of \
the *visible* portion of the label.  // The black background quad will automatically \
                overlap this by 1 pixel.
-	void DrawLabel(string s, int x1, int y1, bool right_align = false);
+	void DrawLabel(const string& s, int x1, int y1, bool right_align = false);
 	
 	int GetLabelQuadrant(double h);
 	int GetLabelQuadrant(double h1, double h2);
Index: src/Instrumentation/KLN89/kln89_page.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page.cxx,v
retrieving revision 1.1
diff -u -r1.1 kln89_page.cxx
--- src/Instrumentation/KLN89/kln89_page.cxx	30 Nov 2005 00:21:25 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page.cxx	30 Nov 2005 23:12:21 -0000
@@ -110,7 +110,7 @@
 	}
 }
 
-void KLN89Page::ShowScratchpadMessage(string line1, string line2) {
+void KLN89Page::ShowScratchpadMessage(const string& line1, const string& line2) {
 	_scratchpadLine1 = line1;
 	_scratchpadLine2 = line2;
 	_scratchpadTimer = 0.0;
@@ -195,10 +195,10 @@
 	_entInvert = false;
 }
 
-void KLN89Page::SetId(string s) {
+void KLN89Page::SetId(const string& s) {
 	_id = s;
 }
 
-string KLN89Page::GetId() {
+const string& KLN89Page::GetId() {
 	return(_id);
 }
Index: src/Instrumentation/KLN89/kln89_page.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page.hxx,v
retrieving revision 1.1
diff -u -r1.1 kln89_page.hxx
--- src/Instrumentation/KLN89/kln89_page.hxx	30 Nov 2005 00:21:25 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page.hxx	30 Nov 2005 23:12:21 -0000
@@ -60,8 +60,8 @@
 	inline void SetEntInvert(bool b) { _entInvert = b; }
 	
 	// Get / Set a waypoint id, NOT the page name!
-	virtual void SetId(string s);
-	virtual string GetId();
+	virtual void SetId(const string& s);
+	virtual const string& GetId();
 	
 protected:
 	KLN89* _kln89;
@@ -82,7 +82,7 @@
 	string _id;		// The ID of the waypoint that the page is displaying.
 					// Doesn't make sense for all pages, but does for all the data pages.
 					
-	void ShowScratchpadMessage(string line1, string line2);
+	void ShowScratchpadMessage(const string& line1, const string& line2);
 					
 	bool _scratchpadMsg;		// Set true when there is a scratchpad message to display
 	double _scratchpadTimer;	// Used for displaying the scratchpad messages for the \
                right amount of time.
Index: src/Instrumentation/KLN89/kln89_page_apt.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_apt.cxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_apt.cxx
--- src/Instrumentation/KLN89/kln89_page_apt.cxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_apt.cxx	30 Nov 2005 23:12:22 -0000
@@ -462,7 +462,7 @@
 	KLN89Page::Update(dt);
 }
 
-void KLN89AptPage::SetId(string s) {
+void KLN89AptPage::SetId(const string& s) {
 	_last_apt_id = _apt_id;
 	_save_apt_id = _apt_id;
 	_apt_id = s;
Index: src/Instrumentation/KLN89/kln89_page_apt.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_apt.hxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_apt.hxx
--- src/Instrumentation/KLN89/kln89_page_apt.hxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_apt.hxx	30 Nov 2005 23:12:22 -0000
@@ -49,7 +49,7 @@
 	void Knob2Left1();
 	void Knob2Right1();
 	
-	void SetId(string s);
+	void SetId(const string& s);
 	
 private:
 	// Update the cached airport details
Index: src/Instrumentation/KLN89/kln89_page_dir.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_dir.cxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_dir.cxx
--- src/Instrumentation/KLN89/kln89_page_dir.cxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_dir.cxx	30 Nov 2005 23:12:22 -0000
@@ -63,7 +63,7 @@
 	KLN89Page::Update(dt);
 }
 
-void KLN89DirPage::SetId(string s) {
+void KLN89DirPage::SetId(const string& s) {
 	if(s.size()) {
 		_id = s;
 		// TODO - fill in lat, lon, type
@@ -100,4 +100,4 @@
 	} else {
 		_kln89->DtoInitiate(_id);
 	}
-}
\ No newline at end of file
+}
Index: src/Instrumentation/KLN89/kln89_page_dir.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_dir.hxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_dir.hxx
--- src/Instrumentation/KLN89/kln89_page_dir.hxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_dir.hxx	30 Nov 2005 23:12:22 -0000
@@ -34,7 +34,7 @@
 	
 	void Update(double dt);
 	
-	void SetId(string s);
+	void SetId(const string& s);
 	
 	void ClrPressed();
 	void EntPressed();
Index: src/Instrumentation/KLN89/kln89_page_fpl.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_fpl.hxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_fpl.hxx
--- src/Instrumentation/KLN89/kln89_page_fpl.hxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_fpl.hxx	30 Nov 2005 23:12:22 -0000
@@ -48,7 +48,7 @@
 	// Override the base class GetId function to return the waypoint ID under the \
cursor  // on FPL0 page, if there is one and the cursor is on.
 	// Otherwise return an empty string.
-	inline string GetId() { return(_fp0SelWpId); } 
+	inline const string& GetId() { return(_fp0SelWpId); } 
 	
 private:
 	int _fpMode;	// 0 = Dis, 1 = Dtk
Index: src/Instrumentation/KLN89/kln89_page_int.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_int.cxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_int.cxx
--- src/Instrumentation/KLN89/kln89_page_int.cxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_int.cxx	30 Nov 2005 23:12:22 -0000
@@ -159,7 +159,7 @@
 	KLN89Page::Update(dt);
 }
 
-void KLN89IntPage::SetId(string s) {
+void KLN89IntPage::SetId(const string& s) {
 	_last_int_id = _int_id;
 	_save_int_id = _int_id;
 	_int_id = s;
Index: src/Instrumentation/KLN89/kln89_page_int.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_int.hxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_int.hxx
--- src/Instrumentation/KLN89/kln89_page_int.hxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_int.hxx	30 Nov 2005 23:12:22 -0000
@@ -40,7 +40,7 @@
 	void Knob2Left1();
 	void Knob2Right1();
 	
-	void SetId(string s);
+	void SetId(const string& s);
 	
 private:
 	string _int_id;
Index: src/Instrumentation/KLN89/kln89_page_ndb.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_ndb.cxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_ndb.cxx
--- src/Instrumentation/KLN89/kln89_page_ndb.cxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_ndb.cxx	30 Nov 2005 23:12:22 -0000
@@ -123,7 +123,7 @@
 	KLN89Page::Update(dt);
 }
 
-void KLN89NDBPage::SetId(string s) {
+void KLN89NDBPage::SetId(const string& s) {
 	_last_ndb_id = _ndb_id;
 	_save_ndb_id = _ndb_id;
 	_ndb_id = s;
Index: src/Instrumentation/KLN89/kln89_page_ndb.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_ndb.hxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_ndb.hxx
--- src/Instrumentation/KLN89/kln89_page_ndb.hxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_ndb.hxx	30 Nov 2005 23:12:22 -0000
@@ -40,7 +40,7 @@
 	void Knob2Left1();
 	void Knob2Right1();
 	
-	void SetId(string s);
+	void SetId(const string& s);
 	
 private:
 	string _ndb_id;	
Index: src/Instrumentation/KLN89/kln89_page_vor.cxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_vor.cxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_vor.cxx
--- src/Instrumentation/KLN89/kln89_page_vor.cxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_vor.cxx	30 Nov 2005 23:12:22 -0000
@@ -135,7 +135,7 @@
 	KLN89Page::Update(dt);
 }
 
-void KLN89VorPage::SetId(string s) {
+void KLN89VorPage::SetId(const string& s) {
 	_last_vor_id = _vor_id;
 	_save_vor_id = _vor_id;
 	_vor_id = s;
Index: src/Instrumentation/KLN89/kln89_page_vor.hxx
===================================================================
RCS file: /var/cvs/FlightGear-0.9/source/src/Instrumentation/KLN89/kln89_page_vor.hxx,v
 retrieving revision 1.1
diff -u -r1.1 kln89_page_vor.hxx
--- src/Instrumentation/KLN89/kln89_page_vor.hxx	30 Nov 2005 00:18:42 -0000	1.1
+++ src/Instrumentation/KLN89/kln89_page_vor.hxx	30 Nov 2005 23:12:22 -0000
@@ -40,7 +40,7 @@
 	void Knob2Left1();
 	void Knob2Right1();
 	
-	void SetId(string s);
+	void SetId(const string& s);
 	
 private:
 	string _vor_id;


--alex--

-- 
| I believe the moment is at hand when, by a paranoiac and active |
|  advance of the mind, it will be possible (simultaneously with  |
|  automatism and other passive states) to systematize confusion  |
|  and thus to help to discredit completely the world of reality. |


_______________________________________________
Flightgear-devel mailing list
Flightgear-devel@flightgear.org
http://mail.flightgear.org/mailman/listinfo/flightgear-devel
2f585eeea02e2c79d7b1d8c4963bae2d

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic