#pragma once #include #include #include #include #include #include "util/macros.h" #include "util/numtypes.h" class Weather { public: using degrees = rfl::Validator, rfl::Maximum<360>>; using percentage = rfl::Validator, rfl::Maximum<100>>; struct Condition { std::string description; std::string icon; std::string main; usize id; }; struct Main { f64 feels_like; f64 temp; f64 temp_max; f64 temp_min; isize pressure; percentage humidity; std::optional grnd_level; std::optional sea_level; }; struct Wind { degrees deg; f64 speed; std::optional gust; }; struct Precipitation { rfl::Rename<"1h", f64> one_hour; rfl::Rename<"3h", f64> three_hours; }; struct Sys { std::string country; usize id; usize sunrise; usize sunset; usize type; }; struct Clouds { percentage all; }; struct Coords { double lat; double lon; }; struct WeatherOutput { Clouds clouds; isize timezone; isize visibility; Main main; rfl::Rename<"coord", Coords> coords; std::optional rain; std::optional snow; std::string base; std::string name; std::vector weather; Sys sys; usize cod; usize dt; usize id; Wind wind; }; using Location = std::variant; private: Location m_Location; std::string m_ApiKey; std::string m_Units; public: Weather(Location location, std::string api_key, std::string units); [[nodiscard]] fn getWeatherInfo() const -> WeatherOutput; [[nodiscard]] fn getLocation() const -> const Location; [[nodiscard]] fn getApiKey() const -> const std::string; [[nodiscard]] fn getUnits() const -> const std::string; }; struct WeatherImpl { Weather::Location location; std::string api_key; std::string units; static fn from_class(const Weather& weather) noexcept -> WeatherImpl; [[nodiscard]] fn to_class() const -> Weather; }; namespace rfl::parsing { template struct Parser : public CustomParser< ReaderType, WriterType, ProcessorsType, Weather, WeatherImpl> {}; }