diff options
Diffstat (limited to 'sensor/main/sensor.cpp')
-rw-r--r-- | sensor/main/sensor.cpp | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/sensor/main/sensor.cpp b/sensor/main/sensor.cpp new file mode 100644 index 0000000..a773e0b --- /dev/null +++ b/sensor/main/sensor.cpp @@ -0,0 +1,79 @@ +#include "trygvis/sensor.h" + +#include "json.hpp" +#include <set> +#include <boost/regex.hpp> +#include <boost/lexical_cast.hpp> +#include <chrono> + +namespace trygvis { +namespace sensor { + +using namespace std; + +string to_string(const sample_format_type &arg) { + if (arg == sample_format_type::AUTO) + return "auto"; + else if (arg == sample_format_type::CSV) + return "csv"; + else if (arg == sample_format_type::JSON) + return "json"; + else if (arg == sample_format_type::KEY_VALUE) + return "key-value"; + else if (arg == sample_format_type::SQL) + return "sql"; + else if (arg == sample_format_type::RRD) + return "rrd"; + else + return "unknown"; +} + +std::ostream& operator<<(std::ostream& os, sample_format_type const& type) { + return os << to_string(type); +} + +std::istream& operator>>(std::istream& is, sample_format_type& type) { + string s; + is >> s; + + if (s == "auto") { + type = sample_format_type::AUTO; + } else if (s == "csv") { + type = sample_format_type::CSV; + } else if (s == "key-value") { + type = sample_format_type::KEY_VALUE; + } else if (s == "json") { + type = sample_format_type::JSON; + } else if (s == "sql") { + type = sample_format_type::SQL; + } else if (s == "rrd") { + type = sample_format_type::RRD; + } + + return is; +} + +template<> +const o<long> SampleRecord::lexical_at(const SampleKey *key) const { + auto value = at(key); + + if (!value) { + return o<long>(); + } + + return o<long>(boost::lexical_cast<long>(value.get())); +} +// +//template<class A> +//const o<A> SampleRecord::lexical_at(const SampleKey *key) const { +// auto value = at(key); +// +// if (!value) { +// return o<A>(); +// } +// +// return o<A>(boost::lexical_cast<A>(value.get())); +//} + +} +} |