From ef2e07b3891a3c2a2429d973d5db68208db7e526 Mon Sep 17 00:00:00 2001 From: "Robin.Mueller" Date: Mon, 30 Nov 2020 17:03:14 +0100 Subject: [PATCH] added explicit type conversion operator --- datapoollocal/LocalPoolVariable.h | 4 ++++ datapoollocal/LocalPoolVariable.tpp | 32 ++++++++++++++++------------- thermal/ThermalComponentCore.cpp | 6 +++--- 3 files changed, 25 insertions(+), 17 deletions(-) diff --git a/datapoollocal/LocalPoolVariable.h b/datapoollocal/LocalPoolVariable.h index bb36089d..c18d5443 100644 --- a/datapoollocal/LocalPoolVariable.h +++ b/datapoollocal/LocalPoolVariable.h @@ -121,6 +121,10 @@ public: LocalPoolVar &operator=(const T& newValue); LocalPoolVar &operator=(const LocalPoolVar& newPoolVariable); + //! Explicit type conversion operator. Allows casting the class to + //! its template type to perform operations on value. + explicit operator T() const; + bool operator==(const LocalPoolVar& other) const; bool operator==(const T& other) const; diff --git a/datapoollocal/LocalPoolVariable.tpp b/datapoollocal/LocalPoolVariable.tpp index a63e550d..b9f7b906 100644 --- a/datapoollocal/LocalPoolVariable.tpp +++ b/datapoollocal/LocalPoolVariable.tpp @@ -80,20 +80,6 @@ inline ReturnValue_t LocalPoolVar::commitWithoutLock() { return RETURN_OK; } -template -inline LocalPoolVar & LocalPoolVar::operator=(const T& newValue) { - value = newValue; - return *this; -} - -template -inline LocalPoolVar& LocalPoolVar::operator =( - const LocalPoolVar& newPoolVariable) { - value = newPoolVariable.value; - return *this; -} - - template inline ReturnValue_t LocalPoolVar::serialize(uint8_t** buffer, size_t* size, const size_t max_size, SerializeIF::Endianness streamEndianness) const { @@ -119,6 +105,24 @@ inline std::ostream& operator<< (std::ostream &out, return out; } +template +inline LocalPoolVar::operator T() const { + return value; +} + +template +inline LocalPoolVar & LocalPoolVar::operator=(const T& newValue) { + value = newValue; + return *this; +} + +template +inline LocalPoolVar& LocalPoolVar::operator =( + const LocalPoolVar& newPoolVariable) { + value = newPoolVariable.value; + return *this; +} + template inline bool LocalPoolVar::operator ==(const LocalPoolVar &other) const { return this->value == other.value; diff --git a/thermal/ThermalComponentCore.cpp b/thermal/ThermalComponentCore.cpp index 29f9e25d..7b594d0c 100644 --- a/thermal/ThermalComponentCore.cpp +++ b/thermal/ThermalComponentCore.cpp @@ -60,7 +60,7 @@ ThermalComponentIF::HeaterRequest ThermalComponentCore::performOperation( //SHOULDDO: Better pass db_float_t* to getTemperature and set it invalid if invalid. temperature = getTemperature(); updateMinMaxTemp(); - if ((temperature != INVALID_TEMPERATURE)) { + if (temperature != INVALID_TEMPERATURE) { temperature.setValid(PoolVariableIF::VALID); State state = getState(temperature.value, getParameters(), targetState.value); @@ -230,10 +230,10 @@ void ThermalComponentCore::updateMinMaxTemp() { return; } if (temperature < minTemp) { - minTemp = temperature.value; + minTemp = static_cast(temperature); } if (temperature > maxTemp) { - maxTemp = temperature.value; + maxTemp = static_cast(temperature); } }