aboutsummaryrefslogtreecommitdiff
path: root/apps
diff options
context:
space:
mode:
Diffstat (limited to 'apps')
-rw-r--r--apps/sample-convert.cpp21
-rw-r--r--apps/sample-timestamp.cpp2
2 files changed, 15 insertions, 8 deletions
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp
index c7173a1..1cedf42 100644
--- a/apps/sample-convert.cpp
+++ b/apps/sample-convert.cpp
@@ -18,6 +18,7 @@ namespace po = boost::program_options;
class sample_convert : public app {
string fields;
string timestamp_field;
+ bool add_timestamp;
public:
void add_options(po::options_description_easy_init &options) override {
@@ -28,7 +29,8 @@ public:
("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))
- ("timestamp-field", po::value<string>(&timestamp_field));
+ ("add-timestamp", po::value<bool>(&add_timestamp)->default_value(true))
+ ("timestamp-field", po::value<string>(&timestamp_field)->default_value("timestamp"));
}
void add_extra_options(po::options_description &all_options) override {
@@ -67,12 +69,10 @@ public:
}
}
- std::vector<sample_output_stream_option *> options;
+ sample_output_stream_options options;
trygvis::sensor::io::timestamp_field_option tf(timestamp_field);
- if (!timestamp_field.empty()) {
- options.push_back(&tf);
- }
+ options.push_back(&tf);
tokenizer<> tok(fields);
output_fields_option fs;
@@ -81,14 +81,21 @@ public:
options.push_back(&fs);
}
- shared_ptr<SampleOutputStream> output = open_sample_output_stream(outputStream, dict, output_format, options);
+ 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]);
- input->process(boost::asio::buffer(data, 1));
+ auto buf = boost::asio::buffer(data, 1);
+ input->process(buf);
}
return EXIT_SUCCESS;
diff --git a/apps/sample-timestamp.cpp b/apps/sample-timestamp.cpp
index 85431ae..cf0b7fe 100644
--- a/apps/sample-timestamp.cpp
+++ b/apps/sample-timestamp.cpp
@@ -178,7 +178,7 @@ public:
return EXIT_FAILURE;
}
- vector<sample_output_stream_option*> options = {};
+ sample_output_stream_options options;
unique_ptr<SampleOutputStream> unique_output_stream = open_sample_output_stream(shared_ptr<ostream>(&cout, noop_deleter), dict, parser->type(), options);
shared_ptr<SampleOutputStream> output_stream{std::move(unique_output_stream)};
shared_ptr<SampleOutputStream> p = make_shared<TimestampFixingSampleOutputStream>(output_stream, dict, timestamp_name, relative_name, relative_resolution, start_time);