diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-06-21 00:15:04 +0200 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-06-21 00:15:43 +0200 |
commit | c56840f03cf139d60c6d90b55cf16e70f6ae2bc2 (patch) | |
tree | c9f19ab065496ac704fbf855da031ef5643eefa3 /apps/sample-convert.cpp | |
parent | d91e500592790f1ef22ebfe921f273a61ff6252f (diff) | |
download | ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.gz ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.bz2 ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.tar.xz ble-toys-c56840f03cf139d60c6d90b55cf16e70f6ae2bc2.zip |
o Going all header file based and single-executable to launch all apps.
o Ading CMake magic to generate the launcher
Diffstat (limited to 'apps/sample-convert.cpp')
-rw-r--r-- | apps/sample-convert.cpp | 128 |
1 files changed, 0 insertions, 128 deletions
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp deleted file mode 100644 index 2dc34b3..0000000 --- a/apps/sample-convert.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include "trygvis/sensor.h" -#include "trygvis/sensor/io.h" -#include "json.hpp" -#include "apps.h" -#include <fstream> -#include <boost/tokenizer.hpp> - -namespace trygvis { -namespace apps { - -using namespace std; -using namespace trygvis::apps; -using namespace trygvis::sensor; -using namespace trygvis::sensor::io; -using boost::tokenizer; -namespace po = boost::program_options; - -class sample_convert : public app { -private: - string fields; - string timestamp_field; - bool add_timestamp; - string input_file, output_file; - sample_format_type output_format; - - string table_name; - -public: - sample_convert() : app("sample-convert") { - } - - ~sample_convert() = default; - - void add_options(po::options_description_easy_init &options) override { - options - ("help", "produce this help message") - ("input", po::value<string>(&input_file)->default_value("-")) -// ("input-format", po::value<string>(&input_format)->default_value("csv")) - ("output", po::value<string>(&output_file)->default_value("-")) - ("output-format", po::value<sample_format_type>(&output_format)->default_value(sample_format_type::KEY_VALUE)) - ("fields", po::value<string>(&fields)) - ("add-timestamp", po::value<bool>(&add_timestamp)->default_value(true)) - ("timestamp-field", po::value<string>(×tamp_field)->default_value("timestamp")); - } - - void add_extra_options(po::options_description &all_options) override { - po::options_description sql("SQL"); - sql.add_options() - ("table-name", po::value<string>(&table_name)); - - all_options.add(sql); - }; - - int main(app_execution &execution) override { - auto desc = execution.desc; - auto vm = execution.vm; - - KeyDictionary dict; - - istream *inputStream; - if (input_file == "-") { - inputStream = &cin; - } else { - inputStream = new ifstream(input_file); - if (inputStream->fail()) { - cerr << "Unable to open input file " << input_file << endl; - return EXIT_FAILURE; - } - } - - shared_ptr<ostream> outputStream; - if (output_file == "-") { - outputStream = shared_ptr<ostream>(&cout, noop_deleter); - } else { - outputStream = make_shared<ofstream>(output_file); - if (outputStream->fail()) { - cerr << "Unable to open output file " << output_file << endl; - return EXIT_FAILURE; - } - } - - sample_output_stream_options options; - trygvis::sensor::io::timestamp_field_option tf(timestamp_field); - - options.push_back(&tf); - - table_name_option tno(table_name); - if (table_name != "") { - options.push_back(&tno); - } - - tokenizer<> tok(fields); - output_fields_option fs; - std::copy(tok.begin(), tok.end(), std::back_inserter(fs.fields)); - if (!fs.fields.empty()) { - options.push_back(&fs); - } - - unique_ptr<SampleOutputStream> o = open_sample_output_stream(outputStream, dict, output_format, options); - - if (add_timestamp) { - o = make_unique<AddTimestampSampleOutputStream>(move(o), dict, timestamp_field); - } - - shared_ptr<SampleOutputStream> output(move(o)); - - auto input = make_shared<KeyValueSampleStreamParser>(output, dict); - - char data[100]; - while (!inputStream->eof()) { - inputStream->get(data[0]); - auto buf = boost::asio::buffer(data, 1); - input->process(buf); - } - - return EXIT_SUCCESS; - } -}; - -} -} - -using namespace trygvis::apps; - -int main(int argc, char *argv[]) { - sample_convert app; - return launch_app(argc, argv, app); -} |