diff options
author | David Wagner <david.wagner@intel.com> | 2014-02-27 15:52:49 +0100 |
---|---|---|
committer | Mattijs Korpershoek <mattijsx.korpershoek@intel.com> | 2014-06-25 10:52:25 +0200 |
commit | 8ef87a1fe5d2f05557856efa6faf070bb9b03337 (patch) | |
tree | 66b1ee719721e3bd44238d6123faf8a8ba89ba5b /parameter | |
parent | 397cfb624defe0b4fcb22351536478379fdc711a (diff) | |
download | external_parameter-framework-8ef87a1fe5d2f05557856efa6faf070bb9b03337.zip external_parameter-framework-8ef87a1fe5d2f05557856efa6faf070bb9b03337.tar.gz external_parameter-framework-8ef87a1fe5d2f05557856efa6faf070bb9b03337.tar.bz2 |
FixedPointParameterType: fix potential compilation issue
BZ: 176178
The isEncodable() method has several prototypes and some compilers are not able
to decide which version to use and produce a compilation error.
Remove unnecessary casts and make the code simpler by using a template-based
conversion library from string to various numeric types instead of using
strtoll and strtod.
Change-Id: I53d0b4ebd12f2cbb315bb52d98365a35876b5aef
Signed-off-by: David Wagner <david.wagner@intel.com>
Signed-off-by: Mattijs Korpershoek <mattijsx.korpershoek@intel.com>
Diffstat (limited to 'parameter')
-rw-r--r-- | parameter/FixedPointParameterType.cpp | 31 |
1 files changed, 9 insertions, 22 deletions
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp index 88d3aa1..6a873b3 100644 --- a/parameter/FixedPointParameterType.cpp +++ b/parameter/FixedPointParameterType.cpp @@ -37,6 +37,7 @@ #include "ParameterAccessContext.h" #include "ConfigurationAccessContext.h" #include <errno.h> +#include <convert.hpp> #define base CParameterType @@ -122,19 +123,11 @@ bool CFixedPointParameterType::toBlackboard(const string& strValue, uint32_t& ui return false; } - int64_t iData; + uint32_t uiData; if (parameterAccessContext.valueSpaceIsRaw()) { - errno = 0; - char *pcStrEnd; - // Get data in integer form - iData = strtoll(strValue.c_str(), &pcStrEnd, 0); - - // Conversion error when the input string does not contain any digit or the number is out of range - bool bConversionSucceeded = !errno && (strValue.c_str() != pcStrEnd); - - if (!bConversionSucceeded || !isEncodable((uint64_t)iData, !bValueProvidedAsHexa)) { + if (!convertTo(strValue, uiData) || !isEncodable(uiData, !bValueProvidedAsHexa)) { // Illegal value provided parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), bValueProvidedAsHexa)); @@ -144,20 +137,14 @@ bool CFixedPointParameterType::toBlackboard(const string& strValue, uint32_t& ui if (bValueProvidedAsHexa) { // Sign extend - signExtend(iData); + signExtend((int32_t&)uiData); } } else { - errno = 0; - char *pcStrEnd; - - double dData = strtod(strValue.c_str(), &pcStrEnd); - - // Conversion error when the input string does not contain any digit or the number is out of range (int32_t type) - bool bConversionSucceeded = !errno && (strValue.c_str() != pcStrEnd); + double dData; // Check encodability - if (!bConversionSucceeded || !checkValueAgainstRange(dData)) { + if (!convertTo(strValue, dData) || !checkValueAgainstRange(dData)) { // Illegal value provided parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), bValueProvidedAsHexa)); @@ -166,13 +153,13 @@ bool CFixedPointParameterType::toBlackboard(const string& strValue, uint32_t& ui } // Do the conversion - iData = asInteger(dData); + uiData = (uint32_t)asInteger(dData); } // check that the data is encodable and can be safely written to the blackboard - assert(isEncodable((unsigned long int)iData, true)); + assert(isEncodable(uiData, true)); - uiValue = (uint32_t)iData; + uiValue = uiData; return true; } |