From 2ad164e80f742a3da1989759a8d383ed79883d1b Mon Sep 17 00:00:00 2001 From: Florent Rougon Date: Tue, 18 Apr 2017 00:50:20 +0200 Subject: [PATCH] Improve handling of the pushBackRoute attribute in groundnet's Parking nodes - Don't ignore pushbackRoute="0". - Stricter parsing with precise log messages when the input is incorrect. - Add missing includes in src/Airports/dynamicloader.cxx. See for the discussion about this change. --- src/Airports/dynamicloader.cxx | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/src/Airports/dynamicloader.cxx b/src/Airports/dynamicloader.cxx index 6b5902533..03e27e069 100644 --- a/src/Airports/dynamicloader.cxx +++ b/src/Airports/dynamicloader.cxx @@ -17,6 +17,7 @@ # include #endif +#include #include #include // for strcmp @@ -26,6 +27,9 @@ #include #include #include +#include +#include +#include using std::string; @@ -92,10 +96,12 @@ void FGGroundNetXMLLoader::startParking(const XMLAttributes &atts) double heading = 0.0; double radius = 1.0; string airlineCodes; - int pushBackRoute = 0; + int pushBackRoute = -1; // signals unseen attribute + + savePosition(); // allows to retrieve the line number for (int i = 0; i < atts.size(); i++) - { + { string attname(atts.getName(i)); if (attname == "index") { index = std::atoi(atts.getValue(i)); @@ -120,9 +126,17 @@ void FGGroundNetXMLLoader::startParking(const XMLAttributes &atts) else if (attname == "airlineCodes") airlineCodes = atts.getValue(i); else if (attname == "pushBackRoute") { - pushBackRoute = std::atoi(atts.getValue(i)); + const string attrVal = atts.getValue(i); + try { + pushBackRoute = simgear::strutils::readNonNegativeInt(attrVal); + } catch (const sg_exception& e) { + SG_LOG(SG_NAVAID, SG_DEV_WARN, + getPath() << ":" << getLine() << ": " << + "invalid value for 'pushBackRoute': " << e.what()); + pushBackRoute = -2; + } } - } + } SGGeod pos(SGGeod::fromDeg(processPosition(lon), processPosition(lat))); @@ -130,7 +144,7 @@ void FGGroundNetXMLLoader::startParking(const XMLAttributes &atts) pos, heading, radius, gateName + gateNumber, type, airlineCodes)); - if (pushBackRoute > 0) { + if (pushBackRoute >= 0) { _parkingPushbacks[parking] = pushBackRoute; }