]> git.mxchange.org Git - flightgear.git/commitdiff
Vassilii Khachaturov:
authorehofman <ehofman>
Tue, 25 Oct 2005 08:57:33 +0000 (08:57 +0000)
committerehofman <ehofman>
Tue, 25 Oct 2005 08:57:33 +0000 (08:57 +0000)
this patch eliminates some cut-and-paste,
as well as makes some frequently used strings const static at the same
time. A couple of interfaces are decorated with 'const' on the parameters
that are such, in line with other such interfaces where const is used.

"NINE" changed to "NINER", to match ICAO practice and the current FGFS
voice data.

A fixed buffer, sprintf and a warning comment replaced w/ostringstream.

Alex Romosan:

+string ConvertRwyNumToSpokenString(const string s) {

this should be string ConvertRwyNumToSpokenString(const string& s)
so we don't make unnecessary copies.

src/ATC/ATCutils.cxx
src/ATC/ATCutils.hxx

index 88657ca316951edd7169b78bc6fce19e37eec5ec..0b51b550fac36aae6e5afb4f090a82a05e774af8 100644 (file)
@@ -22,6 +22,8 @@
 #  include <config.h>
 #endif
 
+#include <sstream>
+
 #include <math.h>
 #include <simgear/math/point3d.hxx>
 #include <simgear/constants.h>
 #include "ATCutils.hxx"
 #include "ATCProjection.hxx"
 
+static const string nums[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "niner"};
+
 // Convert any number to spoken digits
-string ConvertNumToSpokenDigits(string n) {
+string ConvertNumToSpokenDigits(const string &n) {
        //cout << "n = " << n << endl;
-       string nums[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
-       string pt = "decimal";
+       static const string pt = "decimal";
        string str = "";
        
        for(unsigned int i=0; i<n.length(); ++i) {
@@ -62,16 +65,14 @@ string ConvertNumToSpokenDigits(string n) {
 
 // Convert an integer to spoken digits
 string ConvertNumToSpokenDigits(int n) {
-       char buf[12];   // should be big enough!!
-       sprintf(buf, "%i", n);
-       string tempstr1 = buf;
-       return(ConvertNumToSpokenDigits(tempstr1));
+       std::ostringstream buf;
+       buf << n;
+       return(ConvertNumToSpokenDigits(buf.str()));
 }
 
 
 // Convert a 2 digit rwy number to a spoken-style string
 string ConvertRwyNumToSpokenString(int n) {
-       string nums[10] = {"zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"};
        // Basic error/sanity checking
        while(n < 0) {
                n += 36;
@@ -96,7 +97,7 @@ string ConvertRwyNumToSpokenString(int n) {
 // Assumes we get a two-digit string optionally appended with L, R or C
 // eg 01 07L 29R 36
 // Anything else is not guaranteed to be handled correctly!
-string ConvertRwyNumToSpokenString(string s) {
+string ConvertRwyNumToSpokenString(const string &s) {
        if(s.size() < 3) {
                return(ConvertRwyNumToSpokenString(atoi(s.c_str())));
        } else {
@@ -186,7 +187,7 @@ string GetCompassDirection(double h) {
 //================================================================================================================
 
 // Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters)
-double dclGetHorizontalSeparation(Point3D pos1, Point3D pos2) {
+double dclGetHorizontalSeparation(const Point3D pos1, const Point3D pos2) {
        double x;       //East-West separation
        double y;       //North-South separation
        double z;       //Horizontal separation - z = sqrt(x^2 + y^2)
@@ -225,7 +226,7 @@ double dclGetLinePointSeparation(double px, double py, double x1, double y1, dou
 // Given a position (lat/lon/elev), heading and vertical angle (degrees), and distance (meters), calculate the new position.
 // This function assumes the world is spherical.  If geodetic accuracy is required use the functions is sg_geodesy instead!
 // Assumes that the ground is not hit!!!  Expects heading and angle in degrees, distance in meters. 
-Point3D dclUpdatePosition(Point3D pos, double heading, double angle, double distance) {
+Point3D dclUpdatePosition(const Point3D pos, double heading, double angle, double distance) {
        //cout << setprecision(10) << pos.lon() << ' ' << pos.lat() << '\n';
        heading *= DCL_DEGREES_TO_RADIANS;
        angle *= DCL_DEGREES_TO_RADIANS;
@@ -258,7 +259,7 @@ Point3D dclUpdatePosition(Point3D pos, double heading, double angle, double dist
 // Get a heading in degrees from one lat/lon to another.
 // This function assumes the world is spherical.  If geodetic accuracy is required use the functions is sg_geodesy instead!
 // Warning - at the moment we are not checking for identical points - currently it returns 0 in this instance.
-double GetHeadingFromTo(Point3D A, Point3D B) {
+double GetHeadingFromTo(const Point3D A, const Point3D B) {
        double latA = A.lat() * DCL_DEGREES_TO_RADIANS;
        double lonA = A.lon() * DCL_DEGREES_TO_RADIANS;
        double latB = B.lat() * DCL_DEGREES_TO_RADIANS;
@@ -353,7 +354,7 @@ Point3D dclGetAirportPos( const string& id ) {
 
 // Runway stuff
 // Given a Point3D (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
-bool OnRunway(Point3D pt, const FGRunway& rwy) {
+bool OnRunway(const Point3D pt, const FGRunway& rwy) {
        FGATCAlignedProjection ortho;
        Point3D centre(rwy._lon, rwy._lat, 0.0);        // We don't need the elev
        ortho.Init(centre, rwy._heading);
index 448099a672680686c55920845eb10aba06209594..2047650862a32eddb070c15f2cbacf4b597675c0 100644 (file)
@@ -38,7 +38,7 @@ SG_USING_STD(string);
 ********************************/
 
 // Convert any number to spoken digits
-string ConvertNumToSpokenDigits(string n);
+string ConvertNumToSpokenDigits(const string &n);
 
 // Convert an integer to spoken digits
 string ConvertNumToSpokenDigits(int n);
@@ -48,10 +48,10 @@ string ConvertRwyNumToSpokenString(int n);
 
 // Convert rwy number string to a spoken-style string
 // eg "05L" to "zero five left"
-// Assumes we get a two-digit string optionally appended with R or L
+// Assumes we get a two-digit string optionally appended with R, L, or C
 // eg 01 07L 29R 36
 // Anything else is not guaranteed to be handled correctly!
-string ConvertRwyNumToSpokenString(string s);
+string ConvertRwyNumToSpokenString(const string &s);
 
 // Return the phonetic letter of a letter represented as an integer 1->26
 string GetPhoneticIdent(int i);
@@ -72,7 +72,7 @@ string GetCompassDirection(double h);
 ********************************/
 
 // Given two positions (lat & lon in degrees), get the HORIZONTAL separation (in meters)
-double dclGetHorizontalSeparation(Point3D pos1, Point3D pos2);
+double dclGetHorizontalSeparation(const Point3D pos1, const Point3D pos2);
 
 // Given a point and a line, get the HORIZONTAL shortest distance from the point to a point on the line.
 // Expects to be fed orthogonal co-ordinates, NOT lat & lon !
@@ -80,10 +80,10 @@ double dclGetLinePointSeparation(double px, double py, double x1, double y1, dou
 
 // Given a position (lat/lon/elev), heading, vertical angle, and distance, calculate the new position.
 // Assumes that the ground is not hit!!!  Expects heading and angle in degrees, distance in meters.
-Point3D dclUpdatePosition(Point3D pos, double heading, double angle, double distance);
+Point3D dclUpdatePosition(const Point3D pos, double heading, double angle, double distance);
 
 // Get a heading from one lat/lon to another (in degrees)
-double GetHeadingFromTo(Point3D A, Point3D B);
+double GetHeadingFromTo(const Point3D A, const Point3D B);
 
 // Given a heading (in degrees), bound it from 0 -> 360
 void dclBoundHeading(double &hdg);
@@ -118,5 +118,5 @@ Point3D dclGetAirportPos( const string& id );
 ****************/
 
 // Given a Point3D (lon/lat/elev) and an FGRunway struct, determine if the point lies on the runway
-bool OnRunway(Point3D pt, const FGRunway& rwy);
+bool OnRunway(const Point3D pt, const FGRunway& rwy);