diff options
Diffstat (limited to 'parameter')
-rw-r--r-- | parameter/EnumParameterType.cpp | 2 | ||||
-rw-r--r-- | parameter/FixedPointParameterType.cpp | 4 | ||||
-rw-r--r-- | parameter/ParameterType.h | 10 |
3 files changed, 12 insertions, 4 deletions
diff --git a/parameter/EnumParameterType.cpp b/parameter/EnumParameterType.cpp index dcdbfaa..145e556 100644 --- a/parameter/EnumParameterType.cpp +++ b/parameter/EnumParameterType.cpp @@ -154,7 +154,7 @@ bool CEnumParameterType::toBlackboard(const string& strValue, uint32_t& uiValue, bool CEnumParameterType::checkValueAgainstRange(const string& strValue, int64_t value, CParameterAccessContext& parameterAccessContext, bool bHexaValue, bool bConversionSucceeded) const { // Enums are always signed, it means we have one less util bit - int64_t maxValue = (1 << (getSize() * 8 - 1)) - 1; + int64_t maxValue = getMaxValue<uint64_t>(); int64_t minValue = -maxValue - 1; if (!bConversionSucceeded || value < minValue || value > maxValue) { diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp index 3c9e20f..2b97f58 100644 --- a/parameter/FixedPointParameterType.cpp +++ b/parameter/FixedPointParameterType.cpp @@ -271,8 +271,6 @@ void CFixedPointParameterType::getRange(double& dMin, double& dMax) const // Out of range error string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool bRawValueSpace, bool bHexaValue) const { - - ostringstream strStream; strStream << "Value " << strValue << " standing out of admitted "; @@ -288,7 +286,7 @@ string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool } else { // Min/Max computation - int32_t iMax = (1L << (getSize() * 8 - 1)) - 1; + int32_t iMax = getMaxValue<uint32_t>(); int32_t iMin = -iMax - 1; strStream << "raw range ["; diff --git a/parameter/ParameterType.h b/parameter/ParameterType.h index d83dbce..ed30ac3 100644 --- a/parameter/ParameterType.h +++ b/parameter/ParameterType.h @@ -25,6 +25,7 @@ #pragma once #include <stdint.h> +#include <limits> #include "TypeElement.h" @@ -87,6 +88,15 @@ protected: // Remove all bits set outside available range uint32_t makeEncodable(uint32_t uiData) const; + /** Compute max value according to the parameter type */ + template <typename type> + type getMaxValue() const + { + return getSize() < sizeof(type) ? + (static_cast<type>(1) << (getSize() * numeric_limits<unsigned char>::digits - 1)) - 1 : + numeric_limits<type>::max(); + } + private: // Instantiation virtual CInstanceConfigurableElement* doInstantiate() const; |