]> git.mxchange.org Git - flightgear.git/blobdiff - src/Airports/runwayprefs.cxx
commradio: improvements for atis speech
[flightgear.git] / src / Airports / runwayprefs.cxx
index 2a2fceb0f743251d07e162c952b6720caf8d679d..e6f1eb68a304af390eb76f5df8ece7dd2715e61d 100644 (file)
 #include <cstdlib>
 #include <cstring>
 
-#include <simgear/compiler.h>
+#include <boost/foreach.hpp>
 
+#include <simgear/compiler.h>
 #include <simgear/debug/logstream.hxx>
+#include <simgear/misc/strutils.hxx>
+#include <simgear/structure/exception.hxx>
+
 #include <Main/globals.hxx>
 #include <Airports/runways.hxx>
 
 #include "runwayprefs.hxx"
 #include "airport.hxx"
 
+using namespace simgear;
+
 /******************************************************************************
  * ScheduleTime
  ***************e*************************************************************/
@@ -90,12 +96,12 @@ ScheduleTime & ScheduleTime::operator=(const ScheduleTime & other)
     return *this;
 }
 
-string ScheduleTime::getName(time_t dayStart)
+std::string ScheduleTime::getName(time_t dayStart)
 {
     if ((start.size() != end.size())
         || (start.size() != scheduleNames.size())) {
         SG_LOG(SG_GENERAL, SG_INFO, "Unable to parse schedule times");
-        exit(1);
+        throw sg_exception("Unable to parse schedule times");
     } else {
         int nrItems = start.size();
         //cerr << "Nr of items to process: " << nrItems << endl;
@@ -109,7 +115,7 @@ string ScheduleTime::getName(time_t dayStart)
         //couldn't find one so return 0;
         //cerr << "Returning 0 " << endl;
     }
-    return string("");
+    return std::string("");
 }
 
 /******************************************************************************
@@ -136,25 +142,26 @@ RunwayList & RunwayList::operator=(const RunwayList & other)
     return *this;
 }
 
-void RunwayList::set(const string & tp, const string & lst)
+void RunwayList::set(const std::string & tp, const std::string & lst)
 {
     //weekday          = atoi(timeCopy.substr(0,1).c_str());
     //    timeOffsetInDays = weekday - currTimeDate->getGmt()->tm_wday;
     //    timeCopy = timeCopy.substr(2,timeCopy.length());
     type = tp;
-    string rwys = lst;
-    string rwy;
-    while (rwys.find(",") != string::npos) {
-        rwy = rwys.substr(0, rwys.find(",", 0));
-        //cerr << "adding runway [" << rwy << "] to the list " << endl;
-        preferredRunways.push_back(rwy);
-        rwys.erase(0, rwys.find(",", 0) + 1);   // erase until after the first whitspace
-        while (rwys[0] == ' ')
-            rwys.erase(0, 1);   // Erase any leading whitespaces.
-        //cerr << "Remaining runway list " << rwys;
+    
+    
+    
+    BOOST_FOREACH(std::string s, strutils::split(lst, ",")) {
+        std::string ident = strutils::strip(s);
+        
+        // http://code.google.com/p/flightgear-bugs/issues/detail?id=1137
+        if ((ident.size() < 2) || !isdigit(ident[1])) {
+            SG_LOG(SG_GENERAL, SG_INFO, "RunwayList::set: padding runway ident '" << ident << "'");
+            ident = "0" + ident;
+        }
+        
+        preferredRunways.push_back(ident);
     }
-    preferredRunways.push_back(rwys);
-    //exit(1);
 }
 
 void RunwayList::clear()
@@ -206,7 +213,7 @@ void RunwayGroup::setActive(const FGAirport * airport,
     double hdgDiff;
     double crossWind;
     double tailWind;
-    string name;
+    std::string name;
     //stringVec names;
     int bestMatch = 0, bestChoice = 0;
 
@@ -229,7 +236,7 @@ void RunwayGroup::setActive(const FGAirport * airport,
             validSelection = true;
             
             for (int j = 0; j < activeRwys; j++) {
-                string ident(rwyList[j].getRwyList(i));
+                std::string ident(rwyList[j].getRwyList(i));
                 if (!airport->hasRunwayWithIdent(ident)) {
                     SG_LOG(SG_GENERAL, SG_WARN,
                            "no such runway:" << ident << " at " <<
@@ -290,9 +297,9 @@ void RunwayGroup::setActive(const FGAirport * airport,
         choice[0] = 0;
         choice[1] = 0;
         for (int i = activeRwys - 1; i; i--) {
-            if (rwyList[i].getType() == string("landing"))
+            if (rwyList[i].getType() == std::string("landing"))
                 choice[0] = i;
-            if (rwyList[i].getType() == string("takeoff"))
+            if (rwyList[i].getType() == std::string("takeoff"))
                 choice[1] = i;
         }
         //cerr << "Choosing " << choice[0] << " for landing and " << choice[1] << "for takeoff" << endl;
@@ -327,7 +334,7 @@ void RunwayGroup::setActive(const FGAirport * airport,
     nrActive = 0;
 }
 
-void RunwayGroup::getActive(int i, string & name, string & type)
+void RunwayGroup::getActive(int i, std::string & name, std::string & type)
 {
     if (i == -1) {
         return;
@@ -394,7 +401,7 @@ ScheduleTime *FGRunwayPreference::getSchedule(const char *trafficType)
     return 0;
 }
 
-RunwayGroup *FGRunwayPreference::getGroup(const string & groupName)
+RunwayGroup *FGRunwayPreference::getGroup(const std::string & groupName)
 {
     PreferenceListIterator i = preferences.begin();
     if (preferences.begin() == preferences.end())
@@ -407,7 +414,7 @@ RunwayGroup *FGRunwayPreference::getGroup(const string & groupName)
         return 0;
 }
 
-string FGRunwayPreference::getId()
+std::string FGRunwayPreference::getId()
 {
     return _ap->getId();
 };