Expose weather phenomena to the SGMetar interface

This commit is contained in:
Torsten Dreyer
2010-11-27 21:04:04 +01:00
parent 4cac366468
commit 1cb8f9237c
2 changed files with 17 additions and 9 deletions
+13 -9
View File
@@ -85,7 +85,8 @@ SGMetar::SGMetar(const string& m, const string& proxy, const string& port,
_rain(false), _rain(false),
_hail(false), _hail(false),
_snow(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])) { if (m.length() == 4 && isalnum(m[0]) && isalnum(m[1]) && isalnum(m[2]) && isalnum(m[3])) {
for (int i = 0; i < 4; i++) for (int i = 0; i < 4; i++)
@@ -680,32 +681,35 @@ bool SGMetar::scanWeather()
} }
string pre, post; string pre, post;
int intensity = 0;
if (*m == '-') if (*m == '-')
m++, pre = "light ", intensity = 1; m++, pre = "light ", _intensity = 1;
else if (*m == '+') else if (*m == '+')
m++, pre = "heavy ", intensity = 3; m++, pre = "heavy ", _intensity = 3;
else if (!strncmp(m, "VC", 2)) else if (!strncmp(m, "VC", 2))
m += 2, post = "in the vicinity "; m += 2, post = "in the vicinity ";
else else
pre = "moderate ", intensity = 2; pre = "moderate ", _intensity = 2;
vector<string> descriptions;
int i; int i;
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (!(a = scanToken(&m, description))) if (!(a = scanToken(&m, description)))
break; break;
descriptions.push_back(a->id);
weather += string(a->text) + " "; weather += string(a->text) + " ";
} }
for (i = 0; i < 3; i++) { for (i = 0; i < 3; i++) {
if (!(a = scanToken(&m, phenomenon))) if (!(a = scanToken(&m, phenomenon)))
break; break;
_phenomena[a->id] = descriptions;
weather += string(a->text) + " "; weather += string(a->text) + " ";
if (!strcmp(a->id, "RA")) if (!strcmp(a->id, "RA"))
_rain = intensity; _rain = _intensity;
else if (!strcmp(a->id, "HA")) else if (!strcmp(a->id, "HA"))
_hail = intensity; _hail = _intensity;
else if (!strcmp(a->id, "SN")) else if (!strcmp(a->id, "SN"))
_snow = intensity; _snow = _intensity;
} }
if (!weather.length()) if (!weather.length())
return false; return false;
@@ -743,7 +747,7 @@ static const struct Token cloud_types[] = {
{ 0, 0 } { 0, 0 }
}; };
#include <iostream>
// (FEW|SCT|BKN|OVC|SKC|CLR|CAVOK|VV)([0-9]{3}|///)?[:cloud_type:]? // (FEW|SCT|BKN|OVC|SKC|CLR|CAVOK|VV)([0-9]{3}|///)?[:cloud_type:]?
bool SGMetar::scanSkyCondition() bool SGMetar::scanSkyCondition()
{ {
+4
View File
@@ -208,6 +208,8 @@ public:
inline const vector<SGMetarCloud>& getClouds() const { return _clouds; } inline const vector<SGMetarCloud>& getClouds() const { return _clouds; }
inline const map<string, SGMetarRunway>& getRunways() const { return _runways; } inline const map<string, SGMetarRunway>& getRunways() const { return _runways; }
inline const vector<string>& getWeather() const { return _weather; } inline const vector<string>& getWeather() const { return _weather; }
inline const map<string,vector<string> >& getPhenomena() const { return _phenomena; }
inline int getIntensity() const { return _intensity; }
protected: protected:
string _url; string _url;
@@ -242,6 +244,8 @@ protected:
vector<SGMetarCloud> _clouds; vector<SGMetarCloud> _clouds;
map<string, SGMetarRunway> _runways; map<string, SGMetarRunway> _runways;
vector<string> _weather; vector<string> _weather;
map<string,vector<string> > _phenomena;
int _intensity;
bool scanPreambleDate(); bool scanPreambleDate();
bool scanPreambleTime(); bool scanPreambleTime();