diff --git a/example/Makefile b/example/Makefile index 5120caf..9fcd937 100644 --- a/example/Makefile +++ b/example/Makefile @@ -7,7 +7,7 @@ LDFLAGS = `pkg-config libcurl --libs` -L../lib -lMetar $(shell mkdir -p $(OBJDIR)) -OBJS = $(OBJDIR)/main.o $(OBJDIR)/Fetch.o +OBJS = $(OBJDIR)/main.o $(OBJDIR)/Phenom2String.o $(OBJDIR)/Fetch.o $(PROG) : $(OBJS) $(CC) $(OBJS) $(LDFLAGS) -o $(PROG) diff --git a/example/Phenom2String.cpp b/example/Phenom2String.cpp new file mode 100644 index 0000000..02df3f4 --- /dev/null +++ b/example/Phenom2String.cpp @@ -0,0 +1,115 @@ +#include "Phenom2String.h" + +#include + +using namespace std; + +namespace +{ + using namespace Storage_B::Weather; + + map phenom2String = + { + {Phenom::phenom::NONE, ""}, + {Phenom::phenom::MIST, "mist"}, + {Phenom::phenom::DUST_STORM, "dust storm"}, + {Phenom::phenom::DUST, "dist"}, + {Phenom::phenom::DRIZZLE, "drizzle"}, + {Phenom::phenom::FUNNEL_CLOUD, "funnel cloud"}, + {Phenom::phenom::FOG, "fog"}, + {Phenom::phenom::SMOKE, "smoke"}, + {Phenom::phenom::HAIL, "hail"}, + {Phenom::phenom::SMALL_HAIL, "small hail"}, + {Phenom::phenom::HAZE, "haze"}, + {Phenom::phenom::ICE_CRYSTALS, "ice crystals"}, + {Phenom::phenom::ICE_PELLETS, "ice pellets"}, + {Phenom::phenom::DUST_SAND_WHORLS, "dust sand whorls"}, + {Phenom::phenom::SPRAY, "spray"}, + {Phenom::phenom::RAIN, "rain"}, + {Phenom::phenom::SAND, "sand"}, + {Phenom::phenom::SNOW_GRAINS, "snow grains"}, + {Phenom::phenom::SHOWER, "showers"}, + {Phenom::phenom::SNOW, "snow"}, + {Phenom::phenom::SQUALLS, "squalls"}, + {Phenom::phenom::SAND_STORM, "sand storm"}, + {Phenom::phenom::UNKNOWN_PRECIP, "unknown precipitation"}, + {Phenom::phenom::VOLCANIC_ASH, "volcanic ash"} + }; + + string intensity2string(Phenom::intensity intensity) + { + string result; + + switch(intensity) + { + case Phenom::intensity::LIGHT: + result = "light "; + break; + case Phenom::intensity::HEAVY: + result = "heavy "; + break; + + case Phenom::intensity::NORMAL: + default: + break; + } + + return result; + } +} + +string Storage_B::Weather::Phenom2String(const Phenom& phenom) +{ + string result; + + for (unsigned int i = 0 ; i < phenom.NumPhenom() ; i++) + { + result += phenom2String[phenom[i]] + " "; + } + + if (phenom.Blowing()) + { + result = "blowing " + result; + } + + if (phenom.Freezing()) + { + result = "freezing " + result; + } + + if (phenom.Drifting()) + { + result = "drifting " + result; + } + + if (phenom.Partial()) + { + result = "partial " + result; + } + + if (phenom.Shallow()) + { + result = "shallow " + result; + } + + if (phenom.Patches()) + { + result = "patchy " + result; + } + + if (phenom.ThunderStorm()) + { + result += "thunder storm "; + } + + if (phenom.Vicinity()) + { + result += " in the vicinity"; + } + + result = intensity2string(phenom.Intensity()) + result; + + result[0] = toupper(result[0]); + + return result; +} diff --git a/example/Phenom2String.h b/example/Phenom2String.h new file mode 100644 index 0000000..ba67e11 --- /dev/null +++ b/example/Phenom2String.h @@ -0,0 +1,15 @@ +#ifndef STORAGE_B_WEATHER_PHENOM2STRING_ +#define STORAGE_B_WEATHER_PHENOM2STRING_ + +#include + +#include "Phenom.h" + +namespace Storage_B +{ + namespace Weather + { + std::string Phenom2String(const Phenom& phenom); + } +} +#endif diff --git a/example/main.cpp b/example/main.cpp index 216986d..cf3ff7f 100644 --- a/example/main.cpp +++ b/example/main.cpp @@ -20,6 +20,8 @@ #include "Convert.h" #include "Utils.h" +#include "Phenom2String.h" + using namespace std; using namespace Storage_B::Weather; using namespace Storage_B::Curlpp; @@ -258,6 +260,12 @@ int main(int argc, char **argv) } } + for (unsigned int i = 0 ; i < metar->NumPhenomena() ; i++) + { + const auto& p = metar->Phenomenon(i); + cout << Phenom2String(p) << endl; + } + #ifdef NO_SHARED_PTR delete metar; #endif diff --git a/include/Utils.h b/include/Utils.h index 7722a6d..959ddc3 100644 --- a/include/Utils.h +++ b/include/Utils.h @@ -7,6 +7,8 @@ #ifndef STORAGE_B_WEATHER_UTILS_H_ #define STORAGE_B_WEATHER_UTILS_H_ +#include "defines.h" + namespace Storage_B { namespace Weather diff --git a/src/Clouds.cpp b/src/Clouds.cpp index c65e47f..b6ff588 100644 --- a/src/Clouds.cpp +++ b/src/Clouds.cpp @@ -6,9 +6,17 @@ #include "Clouds.h" +#ifndef NO_SHARED_PTR #include #include +#include #include +#else +#include +#include +#include +#include +#endif using namespace std; using namespace Storage_B::Weather; diff --git a/src/Metar.cpp b/src/Metar.cpp index 3b58cb6..dfed0d4 100644 --- a/src/Metar.cpp +++ b/src/Metar.cpp @@ -6,12 +6,21 @@ #include "Metar.h" +#ifndef NO_SHARED_PTR #include #include #include #include #include +#else +#include +#include +#include + +#include +#include +#endif using namespace std; using namespace Storage_B::Weather; diff --git a/src/Phenom.cpp b/src/Phenom.cpp index b4a41d2..0e3c49b 100644 --- a/src/Phenom.cpp +++ b/src/Phenom.cpp @@ -5,8 +5,13 @@ // #include "Phenom.h" +#ifndef NO_SHARED_PTR #include #include +#else +#include +#include +#endif using namespace std; using namespace Storage_B::Weather; diff --git a/src/Utils.cpp b/src/Utils.cpp index e646ce7..17232b4 100644 --- a/src/Utils.cpp +++ b/src/Utils.cpp @@ -5,7 +5,11 @@ // #include "Utils.h" +#ifndef NO_SHARED_PTR #include +#else +#include +#endif #include