diff options
Diffstat (limited to 'apps/sample-add-timestamp.cpp')
-rw-r--r-- | apps/sample-add-timestamp.cpp | 29 |
1 files changed, 16 insertions, 13 deletions
diff --git a/apps/sample-add-timestamp.cpp b/apps/sample-add-timestamp.cpp index ec3c43a..5493524 100644 --- a/apps/sample-add-timestamp.cpp +++ b/apps/sample-add-timestamp.cpp @@ -13,9 +13,10 @@ namespace po = boost::program_options; class TimestampAddingSampleOutputStream : public SampleConsumer { public: - TimestampAddingSampleOutputStream(shared_ptr<SampleConsumer> output, KeyDictionary &dict, string timestamp_name) - : output_(output), timestamp_key(dict.indexOf(timestamp_name)) { - if (input_time_resolution_ == time_resolution::MILLISECONDS) { + TimestampAddingSampleOutputStream(shared_ptr<SampleConsumer> output, KeyDictionary &dict, + time_resolution resolution, string timestamp_name) : + output_(output), resolution_(resolution), timestamp_key(dict.indexOf(timestamp_name)) { + if (resolution_ == time_resolution::MILLISECONDS) { factor = 1000; } else { factor = 1; @@ -34,7 +35,7 @@ public: private: const SampleKey *timestamp_key; - const time_resolution input_time_resolution_ = time_resolution::MILLISECONDS; + const time_resolution resolution_; int factor; shared_ptr<SampleConsumer> output_; }; @@ -60,22 +61,24 @@ public: const int buffer_size = 1024; int main(app_execution &execution) override { - auto stdin = shared_ptr<istream>(&cin, noop_deleter); - auto stdout = shared_ptr<ostream>(&cout, noop_deleter); - KeyDictionary dict; + auto out = shared_ptr<ostream>(&cout, noop_deleter); + KeyDictionary dict; sample_output_stream_options options = {}; - auto writer = open_sample_writer(stdout, dict, output_format, options); - auto p = make_shared<TimestampAddingSampleOutputStream>(std::move(writer), dict, timestamp_name); + auto writer = open_sample_writer(out, dict, output_format, options); + auto p = make_shared<TimestampAddingSampleOutputStream>(std::move(writer), dict, resolution, timestamp_name); auto parser = open_sample_stream_parser(p, dict); int recordCount = 0; - while (!stdin->eof()) { + auto in = shared_ptr<istream>(&cin, noop_deleter); +// in->rdbuf(nullptr); + + while (!in->eof()) { char buffer[buffer_size]; - stdin->read(buffer, buffer_size); - auto gcount = static_cast<size_t>(stdin->gcount()); + in->read(buffer, buffer_size); + auto gcount = static_cast<size_t>(in->gcount()); recordCount++; @@ -83,7 +86,7 @@ public: parser->process(b); } - stdout->flush(); + out->flush(); return EXIT_SUCCESS; }; |