From 1cb8f9237cb7fa47eb8e4a89f135ac17656315a5 Mon Sep 17 00:00:00 2001 From: Torsten Dreyer Date: Sat, 27 Nov 2010 21:04:04 +0100 Subject: [PATCH] Expose weather phenomena to the SGMetar interface --- simgear/environment/metar.cxx | 22 +++++++++++++--------- simgear/environment/metar.hxx | 4 ++++ 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/simgear/environment/metar.cxx b/simgear/environment/metar.cxx index 8a06a4cf..182a3995 100644 --- a/simgear/environment/metar.cxx +++ b/simgear/environment/metar.cxx @@ -85,7 +85,8 @@ SGMetar::SGMetar(const string& m, const string& proxy, const string& port, _rain(false), _hail(false), _snow(false), - _cavok(false) + _cavok(false), + _intensity(0) { if (m.length() == 4 && isalnum(m[0]) && isalnum(m[1]) && isalnum(m[2]) && isalnum(m[3])) { for (int i = 0; i < 4; i++) @@ -680,32 +681,35 @@ bool SGMetar::scanWeather() } string pre, post; - int intensity = 0; if (*m == '-') - m++, pre = "light ", intensity = 1; + m++, pre = "light ", _intensity = 1; else if (*m == '+') - m++, pre = "heavy ", intensity = 3; + m++, pre = "heavy ", _intensity = 3; else if (!strncmp(m, "VC", 2)) m += 2, post = "in the vicinity "; else - pre = "moderate ", intensity = 2; + pre = "moderate ", _intensity = 2; + vector descriptions; int i; for (i = 0; i < 3; i++) { if (!(a = scanToken(&m, description))) break; + descriptions.push_back(a->id); weather += string(a->text) + " "; } + for (i = 0; i < 3; i++) { if (!(a = scanToken(&m, phenomenon))) break; + _phenomena[a->id] = descriptions; weather += string(a->text) + " "; if (!strcmp(a->id, "RA")) - _rain = intensity; + _rain = _intensity; else if (!strcmp(a->id, "HA")) - _hail = intensity; + _hail = _intensity; else if (!strcmp(a->id, "SN")) - _snow = intensity; + _snow = _intensity; } if (!weather.length()) return false; @@ -743,7 +747,7 @@ static const struct Token cloud_types[] = { { 0, 0 } }; - +#include // (FEW|SCT|BKN|OVC|SKC|CLR|CAVOK|VV)([0-9]{3}|///)?[:cloud_type:]? bool SGMetar::scanSkyCondition() { diff --git a/simgear/environment/metar.hxx b/simgear/environment/metar.hxx index b6439a27..870456d5 100644 --- a/simgear/environment/metar.hxx +++ b/simgear/environment/metar.hxx @@ -208,6 +208,8 @@ public: inline const vector& getClouds() const { return _clouds; } inline const map& getRunways() const { return _runways; } inline const vector& getWeather() const { return _weather; } + inline const map >& getPhenomena() const { return _phenomena; } + inline int getIntensity() const { return _intensity; } protected: string _url; @@ -242,6 +244,8 @@ protected: vector _clouds; map _runways; vector _weather; + map > _phenomena; + int _intensity; bool scanPreambleDate(); bool scanPreambleTime(); -- 2.39.5