From 5e4aba8140aa037e1f4289aeb9b303d24be82c85 Mon Sep 17 00:00:00 2001 From: BlackMark Date: Sun, 12 Jul 2020 19:38:35 +0200 Subject: [PATCH] Make sensor move constructible --- AdaptiveBrightness/sensor.cpp | 7 +++++++ AdaptiveBrightness/sensor.hpp | 4 +++- AdaptiveBrightness/sensor_driver.cpp | 2 +- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/AdaptiveBrightness/sensor.cpp b/AdaptiveBrightness/sensor.cpp index 91e1c07..904c40f 100644 --- a/AdaptiveBrightness/sensor.cpp +++ b/AdaptiveBrightness/sensor.cpp @@ -15,6 +15,13 @@ Sensor::~Sensor() qDebug(ltr("Destroying sensor on serial port %1").arg(m_serialPortName)); } +Sensor::Sensor(Sensor&& other) noexcept : m_serialPortName(other.m_serialPortName), m_errorOccurred(other.m_errorOccurred), m_range(other.m_range) +{ + other.m_serialPortName.clear(); + other.m_errorOccurred = false; + other.m_range.reset(); +} + std::vector Sensor::readValues() { qDebug(ltr("Reading values of sensor on port %1").arg(m_serialPortName)); diff --git a/AdaptiveBrightness/sensor.hpp b/AdaptiveBrightness/sensor.hpp index 03e2b51..5dd1c01 100644 --- a/AdaptiveBrightness/sensor.hpp +++ b/AdaptiveBrightness/sensor.hpp @@ -11,6 +11,8 @@ class Sensor { public: + Sensor(const Sensor&) = delete; + Sensor(Sensor&& other) noexcept; ~Sensor(); std::vector readValues(); @@ -26,7 +28,7 @@ class Sensor { static constexpr auto SUPPORTED_FIRMWARE = std::string_view{"AdaptiveBrightness v1.2"}; - const QString m_serialPortName; + QString m_serialPortName; bool m_errorOccurred = false; std::optional> m_range; diff --git a/AdaptiveBrightness/sensor_driver.cpp b/AdaptiveBrightness/sensor_driver.cpp index 95e349a..cbac94e 100644 --- a/AdaptiveBrightness/sensor_driver.cpp +++ b/AdaptiveBrightness/sensor_driver.cpp @@ -21,7 +21,7 @@ std::vector enumerateSensors() auto sensor = Sensor(portInfo.portName()); if(sensor.isValidSensor()) { qInfo(ltr("Successfully enumerated sensor on port %1").arg(portInfo.portName())); - sensors.push_back(sensor); + sensors.push_back(std::move(sensor)); } }