Skip to content

Commit

Permalink
Enhance example fix arduino compile errors
Browse files Browse the repository at this point in the history
  • Loading branch information
jachappell committed Aug 17, 2018
1 parent 281b921 commit c754741
Show file tree
Hide file tree
Showing 9 changed files with 167 additions and 1 deletion.
2 changes: 1 addition & 1 deletion example/Makefile
Expand Up @@ -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)
Expand Down
115 changes: 115 additions & 0 deletions example/Phenom2String.cpp
@@ -0,0 +1,115 @@
#include "Phenom2String.h"

#include <map>

using namespace std;

namespace
{
using namespace Storage_B::Weather;

map<Phenom::phenom, string> 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;
}
15 changes: 15 additions & 0 deletions example/Phenom2String.h
@@ -0,0 +1,15 @@
#ifndef STORAGE_B_WEATHER_PHENOM2STRING_
#define STORAGE_B_WEATHER_PHENOM2STRING_

#include <string>

#include "Phenom.h"

namespace Storage_B
{
namespace Weather
{
std::string Phenom2String(const Phenom& phenom);
}
}
#endif
8 changes: 8 additions & 0 deletions example/main.cpp
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions include/Utils.h
Expand Up @@ -7,6 +7,8 @@
#ifndef STORAGE_B_WEATHER_UTILS_H_
#define STORAGE_B_WEATHER_UTILS_H_

#include "defines.h"

namespace Storage_B
{
namespace Weather
Expand Down
8 changes: 8 additions & 0 deletions src/Clouds.cpp
Expand Up @@ -6,9 +6,17 @@

#include "Clouds.h"

#ifndef NO_SHARED_PTR
#include <cstdlib>
#include <cstring>
#include <cstring>
#include <climits>
#else
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <limits.h>
#endif

using namespace std;
using namespace Storage_B::Weather;
Expand Down
9 changes: 9 additions & 0 deletions src/Metar.cpp
Expand Up @@ -6,12 +6,21 @@

#include "Metar.h"

#ifndef NO_SHARED_PTR
#include <cstring>
#include <cstdlib>
#include <cctype>

#include <climits>
#include <cfloat>
#else
#include <string.h>
#include <stdlib.h>
#include <ctype.h>

#include <limits.h>
#include <float.h>
#endif

using namespace std;
using namespace Storage_B::Weather;
Expand Down
5 changes: 5 additions & 0 deletions src/Phenom.cpp
Expand Up @@ -5,8 +5,13 @@
//
#include "Phenom.h"

#ifndef NO_SHARED_PTR
#include <cstring>
#include <cctype>
#else
#include <string.h>
#include <ctype.h>
#endif

using namespace std;
using namespace Storage_B::Weather;
Expand Down
4 changes: 4 additions & 0 deletions src/Utils.cpp
Expand Up @@ -5,7 +5,11 @@
//
#include "Utils.h"

#ifndef NO_SHARED_PTR
#include <cmath>
#else
#include <math.h>
#endif

#include <Convert.h>

Expand Down

0 comments on commit c754741

Please sign in to comment.