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 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 T& other) const;

View File

@ -80,20 +80,6 @@ inline ReturnValue_t LocalPoolVar<T>::commitWithoutLock() {
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>
inline ReturnValue_t LocalPoolVar<T>::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<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>
inline bool LocalPoolVar<T>::operator ==(const LocalPoolVar<T> &other) const {
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.
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<float>(temperature);
}
if (temperature > maxTemp) {
maxTemp = temperature.value;
maxTemp = static_cast<float>(temperature);
}
}