diff options
Diffstat (limited to 'apps/sample-timestamp.cpp')
-rw-r--r-- | apps/sample-timestamp.cpp | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/apps/sample-timestamp.cpp b/apps/sample-timestamp.cpp index 6ac2f86..dd9ab3c 100644 --- a/apps/sample-timestamp.cpp +++ b/apps/sample-timestamp.cpp @@ -14,12 +14,12 @@ namespace po = boost::program_options; class TimestampFixingSampleOutputStream : public SampleOutputStream { public: - TimestampFixingSampleOutputStream(KeyDictionary dict, string timestamp_name, string now_name, time_t start_time, shared_ptr<SampleOutputStream> output) : - timestamp_index(dict.indexOf(timestamp_name)), now_index(dict.indexOf(now_name)), start_time_(start_time), output_(output) { + TimestampFixingSampleOutputStream(shared_ptr<SampleOutputStream> output, KeyDictionary &dict, string timestamp_name, string now_name, time_t start_time) : + timestamp_key(dict.indexOf(timestamp_name)), now_key(dict.indexOf(now_name)), start_time_(start_time), output_(output) { } virtual void write(SampleRecord sample) override { - o<long> relative_time_o = sample.lexical_at<long>(now_index); + o<long> relative_time_o = sample.lexical_at<long>(now_key); if (!relative_time_o) { return; @@ -28,13 +28,13 @@ public: long relative_time = relative_time_o.get(); string new_value = std::to_string(start_time_ + relative_time); - sample.set(timestamp_index, new_value); + sample.set(timestamp_key, new_value); output_->write(sample); }; private: - KeyDictionary::index_t now_index, timestamp_index; + const SampleKey* now_key, *timestamp_key; time_t start_time_; shared_ptr<SampleOutputStream> output_; }; @@ -43,7 +43,7 @@ class sample_timestamp : public app { private: string input_file, timestamp_name, now_name; - KeyDictionary::index_t now_index; + SampleKey* now_key; public: sample_timestamp() : input_file("") { @@ -78,7 +78,7 @@ public: KeyDictionary dict; - now_index = dict.indexOf(now_name); + now_key = dict.indexOf(now_name); auto sample_buffer = make_shared<VectorSampleOutputStream>(); unique_ptr<SampleStreamParser> parser = open_sample_input_stream(dict, sample_buffer); @@ -101,7 +101,7 @@ public: SampleRecord sample = *--sample_buffer->samples.end(); - o<string> s = sample.at(now_index); + o<string> s = sample.at(now_key); if (!s) { cerr << "Missing key '" + now_name + "'." << endl; cerr << "keys: " << sample.to_string() << endl; @@ -129,8 +129,8 @@ public: return EXIT_FAILURE; } - auto output_stream = open_sample_output_stream(dict, parser->type(), unique_ptr<ostream>(&cout)); - auto p = make_shared<TimestampFixingSampleOutputStream>(dict, "timestamp", now_name, start_time, move(output_stream)); + auto output_stream = open_sample_output_stream(unique_ptr<ostream>(&cout), dict, parser->type()); + auto p = make_shared<TimestampFixingSampleOutputStream>(move(output_stream), dict, "timestamp", now_name, start_time); parser = open_sample_input_stream(dict, p, parser->type()); int recordCount = 0; |