Browse Source

sns: be more explicit about the copy vs. move

mcspr-patch-1
Maxim Prokhorov 4 years ago
parent
commit
1b66460638
1 changed files with 13 additions and 3 deletions
  1. +13
    -3
      code/espurna/sensor.cpp

+ 13
- 3
code/espurna/sensor.cpp View File

@ -220,6 +220,13 @@ struct sensor_magnitude_t {
constexpr static double _unset = std::numeric_limits<double>::quiet_NaN(); constexpr static double _unset = std::numeric_limits<double>::quiet_NaN();
static unsigned char _counts[MAGNITUDE_MAX]; static unsigned char _counts[MAGNITUDE_MAX];
sensor_magnitude_t& operator=(const sensor_magnitude_t&) = default;
void move(sensor_magnitude_t&& other) noexcept {
*this = other;
other.filter = nullptr;
}
public: public:
static unsigned char counts(unsigned char type) { static unsigned char counts(unsigned char type) {
@ -227,15 +234,18 @@ struct sensor_magnitude_t {
} }
sensor_magnitude_t() = delete; sensor_magnitude_t() = delete;
sensor_magnitude_t& operator=(const sensor_magnitude_t&) = default;
sensor_magnitude_t(const sensor_magnitude_t&) = delete; sensor_magnitude_t(const sensor_magnitude_t&) = delete;
sensor_magnitude_t(sensor_magnitude_t&& other) noexcept { sensor_magnitude_t(sensor_magnitude_t&& other) noexcept {
*this = other; *this = other;
other.filter = nullptr; other.filter = nullptr;
} }
~sensor_magnitude_t() {
sensor_magnitude_t& operator=(sensor_magnitude_t&& other) noexcept {
move(std::move(other));
return *this;
}
~sensor_magnitude_t() noexcept {
delete filter; delete filter;
} }


Loading…
Cancel
Save