aboutsummaryrefslogtreecommitdiff
path: root/sensor/include
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2016-04-12 20:06:47 +0200
committerTrygve Laugstøl <trygvis@inamo.no>2016-04-12 20:06:47 +0200
commit2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d (patch)
tree19f9ce796886e216a608fa5e938bd2bd4f0d0b55 /sensor/include
parentce07550c57172443c10a66957b50085e273d20b3 (diff)
downloadble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.tar.gz
ble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.tar.bz2
ble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.tar.xz
ble-toys-2ca532122d60cff4dbdc7f24fbc5783bcc5ad68d.zip
Soil Moisture: Adding support for controlling lights.
Bluetooth: refectorying, trying to be more c++ idiomatic and modern. SM/Diller: adding bluetooth to Diller bridge.
Diffstat (limited to 'sensor/include')
-rw-r--r--sensor/include/trygvis/sensor.h43
-rw-r--r--sensor/include/trygvis/sensor/io.h2
2 files changed, 23 insertions, 22 deletions
diff --git a/sensor/include/trygvis/sensor.h b/sensor/include/trygvis/sensor.h
index c109a2a..09372b9 100644
--- a/sensor/include/trygvis/sensor.h
+++ b/sensor/include/trygvis/sensor.h
@@ -5,15 +5,16 @@
#include <iostream>
#include <memory>
#include <vector>
-#include <boost/optional/optional.hpp>
+#include <algorithm>
+#include <experimental/optional>
namespace trygvis {
namespace sensor {
-using namespace std;
+//using namespace std;
-template<typename A>
-using o = boost::optional<A>;
+template<typename T>
+using o = std::experimental::optional<T>;
enum class sample_format_type {
AUTO,
@@ -24,7 +25,7 @@ enum class sample_format_type {
RRD,
};
-string to_string(const sample_format_type &arg);
+std::string to_string(const sample_format_type &arg);
std::ostream& operator<<(std::ostream& os, sample_format_type const& type);
@@ -39,9 +40,9 @@ std::ostream& operator<<(std::ostream& os, time_resolution const& type);
std::istream& operator>>(std::istream& is, time_resolution & type);
-class sample_exception : public runtime_error {
+class sample_exception : public std::runtime_error {
public:
- sample_exception(const string &what) : runtime_error(what) {
+ sample_exception(const std::string &what) : runtime_error(what) {
}
};
@@ -51,13 +52,13 @@ class SampleKey;
class KeyDictionary;
-using SampleKeyVector = vector<SampleKey *>;
+using SampleKeyVector = std::vector<SampleKey *>;
using SampleKeyIndex = SampleKeyVector::size_type;
struct SampleKey {
private:
SampleKey(const SampleKey& that) = delete;
- SampleKey(SampleKeyIndex index, const string &name) : index(index), name(name) {
+ SampleKey(SampleKeyIndex index, const std::string &name) : index(index), name(name) {
if (name.length() == 0) {
throw sample_exception("Bad sample key.");
}
@@ -72,7 +73,7 @@ public:
}
const SampleKeyIndex index;
- const string name;
+ const std::string name;
};
class KeyDictionary {
@@ -88,7 +89,7 @@ public:
KeyDictionary& operator=(const KeyDictionary&) = delete;
- SampleKey *indexOf(const string &key) {
+ const SampleKey *indexOf(const std::string &key) {
SampleKeyIndex i = 0;
for (auto ptr = keys.cbegin(); ptr != keys.cend(); ptr++, i++) {
if ((*ptr)->name == key) {
@@ -111,8 +112,8 @@ public:
return keys.at(i);
}
- vector<SampleKey *> findIndexes(SampleKeyVector &keys) {
- vector<SampleKey *> indexes;
+ std::vector<const SampleKey *> findIndexes(SampleKeyVector &keys) {
+ std::vector<const SampleKey *> indexes;
for (auto &key: keys) {
auto index = indexOf(key->name);
@@ -152,7 +153,7 @@ private:
class SampleRecord {
public:
- typedef vector<o<string>> vec;
+ typedef std::vector<o<std::string>> vec;
SampleRecord(KeyDictionary &dict) : dict(dict) {
}
@@ -179,19 +180,19 @@ public:
return values.empty();
}
- const o<string> at(const SampleKey *key) const {
+ const o<std::string> at(const SampleKey *key) const {
SampleKeyIndex index = key->index;
if (index >= values.size()) {
- return o<string>();
+ return o<std::string>();
}
return values.at(index);
}
SampleRecord& set(const SampleKey *key, const std::string &value) {
- values.resize(max(values.size(), key->index + 1));
+ values.resize(std::max(values.size(), key->index + 1));
- values.at(key->index).reset(value);
+ values.at(key->index) = value;
return *this;
}
@@ -199,9 +200,9 @@ public:
template<class A>
const o<A> lexical_at(const SampleKey *key) const;
- string to_string() const {
+ std::string to_string() const {
SampleKeyIndex i = 0;
- string s;
+ std::string s;
for (auto ptr = values.begin(); ptr != values.end(); ptr++, i++) {
auto o = *ptr;
@@ -209,7 +210,7 @@ public:
continue;
}
- auto value = o.get();
+ auto value = *o;
s += dict.at(i)->name + " = " + value + ", ";
}
diff --git a/sensor/include/trygvis/sensor/io.h b/sensor/include/trygvis/sensor/io.h
index 71b0b84..304091b 100644
--- a/sensor/include/trygvis/sensor/io.h
+++ b/sensor/include/trygvis/sensor/io.h
@@ -187,7 +187,7 @@ public:
void write(SampleRecord const &sample) override;
private:
- vector<SampleKey *> keys;
+ vector<const SampleKey *> keys;
shared_ptr<ostream> stream;
const SampleKey *timestamp_key;
};