summaryrefslogtreecommitdiffstats
path: root/parameter/FixedPointParameterType.cpp
diff options
context:
space:
mode:
authorPatrick Benavoli <patrickx.benavoli@intel.com>2011-10-04 15:32:57 +0200
committerDavid Wagner <david.wagner@intel.com>2014-02-10 17:14:56 +0100
commit11e6498a4fa3b27ca34d2fcb76bd6365da9d5c1b (patch)
tree51a757715ce03dac4cadb51cf742991c650c09a6 /parameter/FixedPointParameterType.cpp
parent930075cd752694f173605fccde1bac1f2bc1e8e7 (diff)
downloadexternal_parameter-framework-11e6498a4fa3b27ca34d2fcb76bd6365da9d5c1b.zip
external_parameter-framework-11e6498a4fa3b27ca34d2fcb76bd6365da9d5c1b.tar.gz
external_parameter-framework-11e6498a4fa3b27ca34d2fcb76bd6365da9d5c1b.tar.bz2
parameter-framework: import/export XML
BZ: 10948 - Max value handling on integers corrected - Left-justified Qn.m numbers - Corrections after code review: removed fixed numbers from the code and unified byte to bit conversions Change-Id: Iaf54e413201eae61013735580e046c5ab1874700 Signed-off-by: Patrick Benavoli <patrickx.benavoli@intel.com> Reviewed-on: http://android.intel.com:8080/22316 Reviewed-by: Centelles, Sylvain <sylvain.centelles@intel.com> Tested-by: Barthes, FabienX <fabienx.barthes@intel.com> Reviewed-by: buildbot <buildbot@intel.com> Tested-by: buildbot <buildbot@intel.com> Reviewed-on: http://android.intel.com:8080/26777 Reviewed-by: Barthes, FabienX <fabienx.barthes@intel.com>
Diffstat (limited to 'parameter/FixedPointParameterType.cpp')
-rw-r--r--parameter/FixedPointParameterType.cpp46
1 files changed, 21 insertions, 25 deletions
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp
index 5b90f13..0c1cc07 100644
--- a/parameter/FixedPointParameterType.cpp
+++ b/parameter/FixedPointParameterType.cpp
@@ -128,19 +128,10 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal
// Get data in integer form
iData = strtol(strValue.c_str(), NULL, 0);
- if (bValueProvidedAsHexa) {
+ if (bValueProvidedAsHexa && isEncodable(iData)) {
- if (!isEncodable(iData, getUtilSizeInBits())) {
-
- // Illegal value provided
- parameterAccessContext.setError(getOutOfRangeError(strValue, parameterAccessContext.valueSpaceIsRaw(), true));
-
- return false;
- } else {
-
- // Sign extend
- signExtend(iData);
- }
+ // Sign extend
+ signExtend(iData);
}
} else {
@@ -148,6 +139,8 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal
// Do the conversion
iData = (int32_t)(dData * (1UL << _uiFractional) + 0.5F - (double)(dData < 0));
+ // Left justify
+ iData <<= getSize() * 8 - getUtilSizeInBits();
}
// Check integrity
@@ -159,7 +152,7 @@ bool CFixedPointParameterType::asInteger(const string& strValue, uint32_t& uiVal
return false;
}
- uiValue = (uint32_t)iData;
+ uiValue = iData;
return true;
}
@@ -169,7 +162,7 @@ void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValu
int32_t iData = uiValue;
// Check consistency
- assert(isEncodable(iData, getUtilSizeInBits()));
+ assert(isEncodable(iData));
// Sign extend
signExtend(iData);
@@ -183,13 +176,16 @@ void CFixedPointParameterType::asString(const uint32_t& uiValue, string& strValu
// Hexa formatting?
if (parameterAccessContext.outputRawFormatIsHex()) {
- strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << uiValue;
+ strStream << "0x" << hex << uppercase << setw(getSize()*2) << setfill('0') << (uint32_t)iData;
} else {
strStream << iData;
}
} else {
+ // Unjustify
+ iData >>= getSize() * 8 - getUtilSizeInBits();
+
double dData = (double)iData / (1UL << _uiFractional);
strStream << dData;
@@ -208,7 +204,7 @@ uint32_t CFixedPointParameterType::getUtilSizeInBits() const
string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool bRawValueSpace, bool bHexaValue) const
{
// Min/Max computation
- int32_t iMax = (1L << (getUtilSizeInBits() - 1)) - 1;
+ int32_t iMax = (1L << (getSize() * 8 - 1)) - 1;
int32_t iMin = -iMax - 1;
ostringstream strStream;
@@ -244,17 +240,17 @@ string CFixedPointParameterType::getOutOfRangeError(const string& strValue, bool
// Check data is consistent with available range, with respect to its sign
bool CFixedPointParameterType::isConsistent(uint32_t uiData) const
{
- uint32_t uiShift = 32 - getUtilSizeInBits();
+ uint32_t uiShift = getSize() * 8;
- if (uiShift) {
-
- // Negative value?
- bool bIsValueExpectedNegative = (uiData & (1 << (uiShift - 1))) != 0;
-
- // Check high bits are clean
- return bIsValueExpectedNegative ? !(~uiData >> uiShift) : !(uiData >> uiShift);
+ if (uiShift == 8 * sizeof(uiData)) {
+ // Prevent inappropriate shifts
+ return true;
}
- return true;
+ // Negative value?
+ bool bIsValueExpectedNegative = (uiData & (1 << (uiShift - 1))) != 0;
+
+ // Check high bits are clean
+ return bIsValueExpectedNegative ? !(~uiData >> uiShift) : !(uiData >> uiShift);
}