diff options
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; } |