X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=simgear%2Fenvironment%2Fmetar.hxx;h=2f2e5d0218c08fb1a3a915ebb0c8c9e08fca154d;hb=a62f11c5509f8d7b2a4c3b587c0e7af8d4f5a39b;hp=c1e29f212c3ec58b30fe0a23c0c7928a2f784c78;hpb=99bf2c6f9ec1c646fba8c17ef4caf75834ec682c;p=simgear.git diff --git a/simgear/environment/metar.hxx b/simgear/environment/metar.hxx index c1e29f21..2f2e5d02 100644 --- a/simgear/environment/metar.hxx +++ b/simgear/environment/metar.hxx @@ -16,7 +16,7 @@ // // You should have received a copy of the GNU General Public License // along with this program; if not, write to the Free Software -// Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ @@ -29,18 +29,12 @@ #include -SG_USING_STD(vector); -SG_USING_STD(map); -SG_USING_STD(string); - -const double SGMetarNaN = -1E20; -#define NaN SGMetarNaN - struct Token { - char *id; - char *text; + const char *id; + const char *text; }; +const double SGMetarNaN = -1E20; class SGMetar; @@ -48,7 +42,7 @@ class SGMetarVisibility { friend class SGMetar; public: SGMetarVisibility() : - _distance(NaN), + _distance(SGMetarNaN), _direction(-1), _modifier(EQUALS), _tendency(NONE) {} @@ -67,9 +61,11 @@ public: DECREASING }; + void set(double dist, int dir = -1, int mod = -1, int tend = -1); + inline double getVisibility_m() const { return _distance; } - inline double getVisibility_ft() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_FEET; } - inline double getVisibility_sm() const { return _distance == NaN ? NaN : _distance * SG_METER_TO_SM; } + inline double getVisibility_ft() const { return _distance == SGMetarNaN ? SGMetarNaN : _distance * SG_METER_TO_FEET; } + inline double getVisibility_sm() const { return _distance == SGMetarNaN ? SGMetarNaN : _distance * SG_METER_TO_SM; } inline int getDirection() const { return _direction; } inline int getModifier() const { return _modifier; } inline int getTendency() const { return _tendency; } @@ -87,30 +83,33 @@ class SGMetarRunway { friend class SGMetar; public: SGMetarRunway() : - _deposit(0), + _deposit(-1), + _deposit_string(0), _extent(-1), _extent_string(0), - _depth(NaN), - _friction(NaN), + _depth(SGMetarNaN), + _friction(SGMetarNaN), _friction_string(0), _comment(0), _wind_shear(false) {} - inline const char *getDeposit() const { return _deposit; } + inline int getDeposit() const { return _deposit; } + inline const char *getDepositString() const { return _deposit_string; } inline double getExtent() const { return _extent; } inline const char *getExtentString() const { return _extent_string; } inline double getDepth() const { return _depth; } inline double getFriction() const { return _friction; } inline const char *getFrictionString() const { return _friction_string; } inline const char *getComment() const { return _comment; } - inline const bool getWindShear() const { return _wind_shear; } - inline SGMetarVisibility getMinVisibility() const { return _min_visibility; } - inline SGMetarVisibility getMaxVisibility() const { return _max_visibility; } + inline bool getWindShear() const { return _wind_shear; } + inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; } + inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; } protected: SGMetarVisibility _min_visibility; SGMetarVisibility _max_visibility; - const char *_deposit; + int _deposit; + const char *_deposit_string; int _extent; const char *_extent_string; double _depth; @@ -125,35 +124,44 @@ protected: class SGMetarCloud { friend class SGMetar; public: - SGMetarCloud() : - _coverage(-1), - _altitude(NaN), - _type(0), - _type_long(0) {} - - inline int getCoverage() const { return _coverage; } - inline double getAltitude_m() const { return _altitude; } - inline double getAltitude_ft() const { return _altitude == NaN ? NaN : _altitude * SG_METER_TO_FEET; } - inline char *getTypeString() const { return _type; } - inline char *getTypeLongString() const { return _type_long; } + enum Coverage { + COVERAGE_NIL = -1, + COVERAGE_CLEAR = 0, + COVERAGE_FEW = 1, + COVERAGE_SCATTERED = 2, + COVERAGE_BROKEN = 3, + COVERAGE_OVERCAST = 4 + }; + + static const char * COVERAGE_NIL_STRING; + static const char * COVERAGE_CLEAR_STRING; + static const char * COVERAGE_FEW_STRING; + static const char * COVERAGE_SCATTERED_STRING; + static const char * COVERAGE_BROKEN_STRING; + static const char * COVERAGE_OVERCAST_STRING; + + SGMetarCloud() : _coverage(COVERAGE_NIL), _altitude(SGMetarNaN), _type(0), _type_long(0) {} + + void set(double alt, Coverage cov = COVERAGE_NIL ); + + inline Coverage getCoverage() const { return _coverage; } + static Coverage getCoverage( const std::string & coverage ); + inline double getAltitude_m() const { return _altitude; } + inline double getAltitude_ft() const { return _altitude == SGMetarNaN ? SGMetarNaN : _altitude * SG_METER_TO_FEET; } + inline const char *getTypeString() const { return _type; } + inline const char *getTypeLongString() const { return _type_long; } protected: - int _coverage; // quarters: 0 -> clear ... 4 -> overcast - double _altitude; // 1000 m - char *_type; // CU - char *_type_long; // cumulus + Coverage _coverage; // quarters: 0 -> clear ... 4 -> overcast + double _altitude; // 1000 m + const char *_type; // CU + const char *_type_long; // cumulus }; class SGMetar { public: - SGMetar(const char *m); - - // The following contructor is tempting, but it is not - // correct, it creates an anonymous instance of SGMetar and - // then immediately throws it away. - // SGMetar(const string m) { SGMetar(m.c_str()); } - + SGMetar(const std::string& m); ~SGMetar(); enum ReportType { @@ -163,8 +171,24 @@ public: RTD }; + enum Intensity { + NIL = 0, + LIGHT = 1, + MODERATE = 2, + HEAVY = 3 + }; + + struct Weather { + Weather() { intensity = NIL; vincinity = false; } + Intensity intensity; + bool vincinity; + std::vector descriptions; + std::vector phenomena; + }; + inline const char *getData() const { return _data; } inline const char *getUnusedData() const { return _m; } + inline bool getProxy() const { return _x_proxy; } inline const char *getId() const { return _icao; } inline int getYear() const { return _year; } inline int getMonth() const { return _month; } @@ -175,38 +199,46 @@ public: inline int getWindDir() const { return _wind_dir; } inline double getWindSpeed_mps() const { return _wind_speed; } - inline double getWindSpeed_kmh() const { return _wind_speed == NaN ? NaN : _wind_speed * 3.6; } - inline double getWindSpeed_kt() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_KT; } - inline double getWindSpeed_mph() const { return _wind_speed == NaN ? NaN : _wind_speed * SG_MPS_TO_MPH; } + inline double getWindSpeed_kmh() const { return _wind_speed == SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_KMH; } + inline double getWindSpeed_kt() const { return _wind_speed == SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_KT; } + inline double getWindSpeed_mph() const { return _wind_speed == SGMetarNaN ? SGMetarNaN : _wind_speed * SG_MPS_TO_MPH; } inline double getGustSpeed_mps() const { return _gust_speed; } - inline double getGustSpeed_kmh() const { return _gust_speed == NaN ? NaN : _gust_speed * 3.6; } - inline double getGustSpeed_kt() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_KT; } - inline double getGustSpeed_mph() const { return _gust_speed == NaN ? NaN : _gust_speed * SG_MPS_TO_MPH; } + inline double getGustSpeed_kmh() const { return _gust_speed == SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_KMH; } + inline double getGustSpeed_kt() const { return _gust_speed == SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_KT; } + inline double getGustSpeed_mph() const { return _gust_speed == SGMetarNaN ? SGMetarNaN : _gust_speed * SG_MPS_TO_MPH; } inline int getWindRangeFrom() const { return _wind_range_from; } inline int getWindRangeTo() const { return _wind_range_to; } - inline SGMetarVisibility& getMinVisibility() { return _min_visibility; } - inline SGMetarVisibility& getMaxVisibility() { return _max_visibility; } - inline SGMetarVisibility& getVertVisibility() { return _vert_visibility; } - inline SGMetarVisibility *getDirVisibility() { return _dir_visibility; } + inline const SGMetarVisibility& getMinVisibility() const { return _min_visibility; } + inline const SGMetarVisibility& getMaxVisibility() const { return _max_visibility; } + inline const SGMetarVisibility& getVertVisibility() const { return _vert_visibility; } + inline const SGMetarVisibility *getDirVisibility() const { return _dir_visibility; } inline double getTemperature_C() const { return _temp; } - inline double getTemperature_F() const { return _temp == NaN ? NaN : 1.8 * _temp + 32; } + inline double getTemperature_F() const { return _temp == SGMetarNaN ? SGMetarNaN : 1.8 * _temp + 32; } inline double getDewpoint_C() const { return _dewp; } - inline double getDewpoint_F() const { return _dewp == NaN ? NaN : 1.8 * _dewp + 32; } - inline double getPressure_hPa() const { return _pressure == NaN ? NaN : _pressure / 100; } - inline double getPressure_inHg() const { return _pressure == NaN ? NaN : _pressure * SG_PA_TO_INHG; } + inline double getDewpoint_F() const { return _dewp == SGMetarNaN ? SGMetarNaN : 1.8 * _dewp + 32; } + inline double getPressure_hPa() const { return _pressure == SGMetarNaN ? SGMetarNaN : _pressure / 100; } + inline double getPressure_inHg() const { return _pressure == SGMetarNaN ? SGMetarNaN : _pressure * SG_PA_TO_INHG; } + + inline int getRain() const { return _rain; } + inline int getHail() const { return _hail; } + inline int getSnow() const { return _snow; } + inline bool getCAVOK() const { return _cavok; } double getRelHumidity() const; - inline vector& getClouds() { return _clouds; } - inline map& getRunways() { return _runways; } - inline vector& getWeather() { return _weather; } + inline const std::vector& getClouds() const { return _clouds; } + inline const std::map& getRunways() const { return _runways; } + inline const std::vector& getWeather() const { return _weather; } + inline const std::vector getWeather2() const { return _weather2; } protected: + std::string _url; int _grpcount; + bool _x_proxy; char *_data; char *_m; char _icao[5]; @@ -224,17 +256,23 @@ protected: double _temp; double _dewp; double _pressure; + int _rain; + int _hail; + int _snow; + bool _cavok; + std::vector _weather2; SGMetarVisibility _min_visibility; SGMetarVisibility _max_visibility; SGMetarVisibility _vert_visibility; SGMetarVisibility _dir_visibility[8]; - vector _clouds; - map _runways; - vector _weather; + std::vector _clouds; + std::map _runways; + std::vector _weather; bool scanPreambleDate(); bool scanPreambleTime(); + void useCurrentDate(); bool scanType(); bool scanId(); @@ -258,9 +296,7 @@ protected: int scanNumber(char **str, int *num, int min, int max = 0); bool scanBoundary(char **str); const struct Token *scanToken(char **str, const struct Token *list); - char *loadData(const char *id); void normalizeData(); }; -#undef NaN #endif // _METAR_HXX