added explicit type conversion operator

This commit is contained in:
Robin Müller 2020-11-30 17:03:14 +01:00
parent d1beb96c60
commit ef2e07b389
3 changed files with 25 additions and 17 deletions

View File

@ -121,6 +121,10 @@ public:
LocalPoolVar<T> &operator=(const T& newValue); LocalPoolVar<T> &operator=(const T& newValue);
LocalPoolVar<T> &operator=(const LocalPoolVar<T>& newPoolVariable); LocalPoolVar<T> &operator=(const LocalPoolVar<T>& 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<T>& other) const; bool operator==(const LocalPoolVar<T>& other) const;
bool operator==(const T& other) const; bool operator==(const T& other) const;

View File

@ -80,20 +80,6 @@ inline ReturnValue_t LocalPoolVar<T>::commitWithoutLock() {
return RETURN_OK; return RETURN_OK;
} }
template<typename T>
inline LocalPoolVar<T> & LocalPoolVar<T>::operator=(const T& newValue) {
value = newValue;
return *this;
}
template<typename T>
inline LocalPoolVar<T>& LocalPoolVar<T>::operator =(
const LocalPoolVar<T>& newPoolVariable) {
value = newPoolVariable.value;
return *this;
}
template<typename T> template<typename T>
inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size, inline ReturnValue_t LocalPoolVar<T>::serialize(uint8_t** buffer, size_t* size,
const size_t max_size, SerializeIF::Endianness streamEndianness) const { const size_t max_size, SerializeIF::Endianness streamEndianness) const {
@ -119,6 +105,24 @@ inline std::ostream& operator<< (std::ostream &out,
return out; return out;
} }
template<typename T>
inline LocalPoolVar<T>::operator T() const {
return value;
}
template<typename T>
inline LocalPoolVar<T> & LocalPoolVar<T>::operator=(const T& newValue) {
value = newValue;
return *this;
}
template<typename T>
inline LocalPoolVar<T>& LocalPoolVar<T>::operator =(
const LocalPoolVar<T>& newPoolVariable) {
value = newPoolVariable.value;
return *this;
}
template<typename T> template<typename T>
inline bool LocalPoolVar<T>::operator ==(const LocalPoolVar<T> &other) const { inline bool LocalPoolVar<T>::operator ==(const LocalPoolVar<T> &other) const {
return this->value == other.value; return this->value == other.value;

View File

@ -60,7 +60,7 @@ ThermalComponentIF::HeaterRequest ThermalComponentCore::performOperation(
//SHOULDDO: Better pass db_float_t* to getTemperature and set it invalid if invalid. //SHOULDDO: Better pass db_float_t* to getTemperature and set it invalid if invalid.
temperature = getTemperature(); temperature = getTemperature();
updateMinMaxTemp(); updateMinMaxTemp();
if ((temperature != INVALID_TEMPERATURE)) { if (temperature != INVALID_TEMPERATURE) {
temperature.setValid(PoolVariableIF::VALID); temperature.setValid(PoolVariableIF::VALID);
State state = getState(temperature.value, getParameters(), State state = getState(temperature.value, getParameters(),
targetState.value); targetState.value);
@ -230,10 +230,10 @@ void ThermalComponentCore::updateMinMaxTemp() {
return; return;
} }
if (temperature < minTemp) { if (temperature < minTemp) {
minTemp = temperature.value; minTemp = static_cast<float>(temperature);
} }
if (temperature > maxTemp) { if (temperature > maxTemp) {
maxTemp = temperature.value; maxTemp = static_cast<float>(temperature);
} }
} }