diff options
-rw-r--r-- | apps/sample-convert.cpp | 4 | ||||
-rw-r--r-- | sensor/include/trygvis/sensor/io.h | 58 | ||||
-rw-r--r-- | sensor/main/io.cpp | 11 |
3 files changed, 36 insertions, 37 deletions
diff --git a/apps/sample-convert.cpp b/apps/sample-convert.cpp index 0c3aa9a..c7173a1 100644 --- a/apps/sample-convert.cpp +++ b/apps/sample-convert.cpp @@ -68,14 +68,14 @@ public: } std::vector<sample_output_stream_option *> options; - trygvis::sensor::io::timestamp_field tf(timestamp_field); + trygvis::sensor::io::timestamp_field_option tf(timestamp_field); if (!timestamp_field.empty()) { options.push_back(&tf); } tokenizer<> tok(fields); - output_fields fs; + output_fields_option fs; std::copy(tok.begin(), tok.end(), std::back_inserter(fs.fields)); if (!fs.fields.empty()) { options.push_back(&fs); diff --git a/sensor/include/trygvis/sensor/io.h b/sensor/include/trygvis/sensor/io.h index 2cace70..bbeb80e 100644 --- a/sensor/include/trygvis/sensor/io.h +++ b/sensor/include/trygvis/sensor/io.h @@ -12,9 +12,30 @@ namespace io { using namespace std; using namespace boost::asio; -class output_fields; +class sample_output_stream_option { +public: + virtual ~sample_output_stream_option() { + }; +}; + +class output_fields_option : public sample_output_stream_option { +public: + ~output_fields_option() { + } + + vector<string> fields; +}; + +class timestamp_field_option : public sample_output_stream_option { +public: + timestamp_field_option(string name) : name(name) { + } + + ~timestamp_field_option() { + } -class timestamp_field; + string name; +}; class SampleOutputStream { public: @@ -86,7 +107,7 @@ private: class RrdSampleOutputStream : public SampleOutputStream { public: - RrdSampleOutputStream(shared_ptr<ostream> stream, KeyDictionary &dict, const SampleKey *timestamp_key, o<output_fields *> output_fields); + RrdSampleOutputStream(shared_ptr<ostream> stream, KeyDictionary &dict, const SampleKey *timestamp_key, o<output_fields_option *> output_fields); void write(SampleRecord const &sample) override; @@ -154,31 +175,6 @@ public: virtual void process(mutable_buffers_1 buffer); }; -class sample_output_stream_option { -public: - virtual ~sample_output_stream_option() { - }; -}; - -class output_fields : public sample_output_stream_option { -public: - ~output_fields() { - } - - vector<string> fields; -}; - -class timestamp_field : public sample_output_stream_option { -public: - timestamp_field(string name) : name(name) { - } - - ~timestamp_field() { - } - - string name; -}; - unique_ptr<SampleStreamParser> open_sample_stream_parser( shared_ptr<SampleOutputStream> output, KeyDictionary &dict, @@ -188,14 +184,15 @@ unique_ptr<SampleOutputStream> open_sample_output_stream( shared_ptr<ostream> output, KeyDictionary &dict, sample_format_type type, -vector<sample_output_stream_option *> options); + vector<sample_output_stream_option *> options); static inline unique_ptr<SampleOutputStream> open_sample_output_stream( shared_ptr<ostream> output, KeyDictionary &dict, sample_format_type type) { -return open_sample_output_stream(output, dict, type); + vector<sample_output_stream_option *> options; + return open_sample_output_stream(output, dict, type, options); } static inline @@ -203,7 +200,6 @@ unique_ptr<ThreadSafeSampleOutputStream> thread_safe_sample_output_stream(unique return make_unique<ThreadSafeSampleOutputStream>(move(underlying)); }; - } } } diff --git a/sensor/main/io.cpp b/sensor/main/io.cpp index 4837414..57c0b18 100644 --- a/sensor/main/io.cpp +++ b/sensor/main/io.cpp @@ -186,9 +186,12 @@ void KeyValueSampleOutputStream::write(SampleRecord const &sample) { *stream.get() << endl; } -RrdSampleOutputStream::RrdSampleOutputStream(shared_ptr<ostream> stream, KeyDictionary &dict, const SampleKey *timestamp_key, o<output_fields *> output_fields) - : +RrdSampleOutputStream::RrdSampleOutputStream(shared_ptr<ostream> stream, + KeyDictionary &dict, + const SampleKey *timestamp_key, + o<output_fields_option *> output_fields) : stream(move(stream)), timestamp_key(timestamp_key) { + if (output_fields) { for (auto field : output_fields.get()->fields) { keys.emplace_back(dict.indexOf(field)); @@ -399,9 +402,9 @@ unique_ptr<SampleOutputStream> open_sample_output_stream( } else if (type == sample_format_type::JSON) { return make_unique<JsonSampleOutputStream>(output, dict); } else if (type == sample_format_type::RRD) { - o<output_fields *> of = find_option<output_fields>(options); + o<output_fields_option *> of = find_option<output_fields_option>(options); - o<timestamp_field *> tsf = find_option<timestamp_field>(options); + o<timestamp_field_option *> tsf = find_option<timestamp_field_option>(options); auto timestamp_key = dict.indexOf(tsf ? tsf.get()->name : "timestamp"); |