diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-14 17:33:43 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2015-03-14 17:33:43 +0100 |
commit | efa1825dd6d16e7901e9620c31796b27b6c84ee9 (patch) | |
tree | 7ce8e6b4728dfaa853bb9d67f53c1a50eafb2231 /apps/sample-convert.cpp | |
parent | 46cd1838255712cc599a30a81098121aa26d80f5 (diff) | |
download | ble-toys-efa1825dd6d16e7901e9620c31796b27b6c84ee9.tar.gz ble-toys-efa1825dd6d16e7901e9620c31796b27b6c84ee9.tar.bz2 ble-toys-efa1825dd6d16e7901e9620c31796b27b6c84ee9.tar.xz ble-toys-efa1825dd6d16e7901e9620c31796b27b6c84ee9.zip |
o Creating a tool to calculate an absolute timestamp from a relative timestamp.
o Using git submodules instead of CMake's external project.
Diffstat (limited to 'apps/sample-convert.cpp')
-rw-r--r-- | apps/sample-convert.cpp | 20 |
1 files changed, 7 insertions, 13 deletions
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp index 7bc8d0b..249b737 100644 --- a/apps/sample-convert.cpp +++ b/apps/sample-convert.cpp @@ -14,10 +14,6 @@ namespace po = boost::program_options; class sample_convert : public app { public: - sample_convert() : table_name(""), input_file(""), input_format(""), - output_file(""), output_format("") { - } - void add_options(po::options_description_easy_init &options) override { options ("help", "produce this help message") @@ -52,11 +48,11 @@ public: } } - ostream *outputStream; + unique_ptr<ostream> outputStream; if (output_file == "-") { - outputStream = &cout; + outputStream = unique_ptr<ostream>(&cout); } else { - outputStream = new ofstream(output_file); + outputStream = make_unique<ofstream>(output_file); if (outputStream->fail()) { cerr << "Unable to open output file " << output_file << endl; return EXIT_FAILURE; @@ -64,22 +60,22 @@ public: } if (output_format == "plain") { - output = make_shared<CsvSampleOutputStream>(*outputStream); + output = make_shared<CsvSampleOutputStream>(move(outputStream)); } else if (output_format == "json") { - output = make_shared<JsonSampleOutputStream>(*outputStream); + output = make_shared<JsonSampleOutputStream>(move(outputStream)); } else if (output_format == "sql") { if (table_name.size() == 0) { cerr << "Missing option: table-name" << endl; return EXIT_FAILURE; } - output = make_shared<SqlSampleOutputStream>(*outputStream, table_name); + output = make_shared<SqlSampleOutputStream>(move(outputStream), table_name); } else { cerr << "Unsupported output format: " << output_format << endl; return EXIT_FAILURE; } - auto input = make_shared<CsvParser>(output); + auto input = make_shared<CsvSampleParser>(output); char data[100]; while (!inputStream->eof()) { @@ -87,8 +83,6 @@ public: input->process(boost::asio::buffer(data, 1)); } - delete outputStream; - return EXIT_SUCCESS; } |