Make sensor move constructible

This commit is contained in:
BlackMark 2020-07-12 19:38:35 +02:00
parent 7b791a071b
commit 5e4aba8140
3 changed files with 11 additions and 2 deletions

View File

@ -15,6 +15,13 @@ Sensor::~Sensor()
qDebug(ltr("Destroying sensor on serial port %1").arg(m_serialPortName)); 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<float> Sensor::readValues() std::vector<float> Sensor::readValues()
{ {
qDebug(ltr("Reading values of sensor on port %1").arg(m_serialPortName)); qDebug(ltr("Reading values of sensor on port %1").arg(m_serialPortName));

View File

@ -11,6 +11,8 @@
class Sensor { class Sensor {
public: public:
Sensor(const Sensor&) = delete;
Sensor(Sensor&& other) noexcept;
~Sensor(); ~Sensor();
std::vector<float> readValues(); std::vector<float> readValues();
@ -26,7 +28,7 @@ class Sensor {
static constexpr auto SUPPORTED_FIRMWARE = std::string_view{"AdaptiveBrightness v1.2"}; static constexpr auto SUPPORTED_FIRMWARE = std::string_view{"AdaptiveBrightness v1.2"};
const QString m_serialPortName; QString m_serialPortName;
bool m_errorOccurred = false; bool m_errorOccurred = false;
std::optional<std::pair<int, int>> m_range; std::optional<std::pair<int, int>> m_range;

View File

@ -21,7 +21,7 @@ std::vector<Sensor> enumerateSensors()
auto sensor = Sensor(portInfo.portName()); auto sensor = Sensor(portInfo.portName());
if(sensor.isValidSensor()) { if(sensor.isValidSensor()) {
qInfo(ltr("Successfully enumerated sensor on port %1").arg(portInfo.portName())); qInfo(ltr("Successfully enumerated sensor on port %1").arg(portInfo.portName()));
sensors.push_back(sensor); sensors.push_back(std::move(sensor));
} }
} }