From a83e6f5960a549d54991495336bd12d549127d91 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Fri, 6 Mar 2015 21:07:34 +0100 Subject: o Starting on a tool to convert between sample formats. --- apps/sample-convert.cpp | 98 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 98 insertions(+) create mode 100644 apps/sample-convert.cpp (limited to 'apps/sample-convert.cpp') diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp new file mode 100644 index 0000000..2e448ca --- /dev/null +++ b/apps/sample-convert.cpp @@ -0,0 +1,98 @@ +#include "SoilMoistureIo.h" +#include "json.hpp" +#include "apps.h" + +enum class Format { + PLAIN, + JSON, + SQL +}; + +void validate(boost::any &v, const std::vector &values, Format *, int) { + using namespace boost::program_options; + + const std::string &s = validators::get_single_string(values); + + if (s == "plain") { + v = boost::any(Format::PLAIN); + } else if (s == "json") { + v = boost::any(Format::JSON); + } else if (s == "sql") { + v = boost::any(Format::SQL); + } else { + throw validation_error(validation_error::invalid_option_value); + } +} + +namespace boost { + +template<> +std::string lexical_cast(const Format &arg) { + if (arg == Format::PLAIN) + return "plain"; + else if (arg == Format::JSON) + return "json"; + else if (arg == Format::SQL) + return "sql"; + else + throw std::runtime_error("Unknown format value: " + lexical_cast(arg)); +} + +} + +namespace trygvis { +namespace apps { + +using namespace std; +using namespace trygvis::apps; +using namespace trygvis::soil_moisture; +namespace po = boost::program_options; + +Format inputFormat, outputFormat; + +class sample_convert : public app { + +public: +// void add_options(po::options_description_easy_init &options) override { +// options +// ("help", "produce help message") +// ("input-format", po::value(&inputFormat)->default_value(Format::PLAIN)) +// ("output-format", po::value(&outputFormat)->default_value(Format::PLAIN)) +// } + + int main(app_execution &execution) override { + auto desc = execution.desc; + auto vm = execution.vm; + + shared_ptr sampleStream; + + auto field_names = vector({ + "hostname", + "device_type", + "device", + "timestamp", + "sensor", + "value" + }); + + sampleStream = make_shared(cout, field_names); + + map values; + values["hostname"] = "my-hostname"; + values["extra"] = "wat"; + + sampleStream->write(values); + + return EXIT_SUCCESS; + } + +}; + +} +} + +using namespace trygvis::apps; +int main(int argc, char *argv[]) { + sample_convert app; + return launch_app(argc, argv, app); +} -- cgit v1.2.3