summaryrefslogtreecommitdiffstats
path: root/parameter
diff options
context:
space:
mode:
authorMattijs Korpershoek <mattijsx.korpershoek@intel.com>2014-05-14 11:58:21 +0200
committerMattijs Korpershoek <mattijsx.korpershoek@intel.com>2014-06-25 10:52:30 +0200
commita24e61fddaf09d2989fff25785e329454c842d7f (patch)
tree5ddac9799f7ee69b8e0e33b8e123bab579073334 /parameter
parentd9406eea67ae1d88b36e356d10d491f3bf0dfe1b (diff)
downloadexternal_parameter-framework-a24e61fddaf09d2989fff25785e329454c842d7f.zip
external_parameter-framework-a24e61fddaf09d2989fff25785e329454c842d7f.tar.gz
external_parameter-framework-a24e61fddaf09d2989fff25785e329454c842d7f.tar.bz2
FixedPointParameter: Rename conversion functions
BZ: 197723 Give a few functions more meaningful names. Add some cast fixes and doxygen to the renamed functions. Change-Id: I002a3fa9b397294153c23b9883c3ad3b1c136e54 Signed-off-by: Mattijs Korpershoek <mattijsx.korpershoek@intel.com>
Diffstat (limited to 'parameter')
-rw-r--r--parameter/FixedPointParameterType.cpp24
-rw-r--r--parameter/FixedPointParameterType.h28
2 files changed, 34 insertions, 18 deletions
diff --git a/parameter/FixedPointParameterType.cpp b/parameter/FixedPointParameterType.cpp
index d465ace..c9f736f 100644
--- a/parameter/FixedPointParameterType.cpp
+++ b/parameter/FixedPointParameterType.cpp
@@ -131,7 +131,7 @@ bool CFixedPointParameterType::toBlackboard(const string& strValue, uint32_t& ui
}
return convertFromDecimal(strValue, uiValue, parameterAccessContext);
}
- return convertFromQiQf(strValue, uiValue, parameterAccessContext);
+ return convertFromQnm(strValue, uiValue, parameterAccessContext);
}
void CFixedPointParameterType::setOutOfRangeError(const string& strValue, CParameterAccessContext& parameterAccessContext) const
@@ -208,7 +208,7 @@ bool CFixedPointParameterType::fromBlackboard(string& strValue, const uint32_t&
signExtend(iData);
// Conversion
- double dData = asDouble(iData);
+ double dData = binaryQnmToDouble(iData);
strStream << fixed << setprecision(_uiFractional) << dData;
}
@@ -231,7 +231,7 @@ bool CFixedPointParameterType::toBlackboard(double dUserValue, uint32_t& uiValue
}
// Do the conversion
- int32_t iData = asInteger(dUserValue);
+ int32_t iData = doubleToBinaryQnm(dUserValue);
// Check integrity
assert(isEncodable((uint32_t)iData, true));
@@ -253,7 +253,7 @@ bool CFixedPointParameterType::fromBlackboard(double& dUserValue, uint32_t uiVal
// Sign extend
signExtend(iData);
- dUserValue = asDouble(iData);
+ dUserValue = binaryQnmToDouble(iData);
return true;
}
@@ -308,7 +308,8 @@ bool CFixedPointParameterType::convertFromDecimal(const string& strValue, uint32
return true;
}
-bool CFixedPointParameterType::convertFromQiQf(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const
+bool CFixedPointParameterType::convertFromQnm(const string& strValue, uint32_t& uiValue,
+ CParameterAccessContext& parameterAccessContext) const
{
double dData;
@@ -317,7 +318,7 @@ bool CFixedPointParameterType::convertFromQiQf(const string& strValue, uint32_t&
setOutOfRangeError(strValue, parameterAccessContext);
return false;
}
- uiValue = static_cast<uint32_t>(asInteger(dData));
+ uiValue = static_cast<uint32_t>(doubleToBinaryQnm(dData));
// check that the data is encodable and has been safely written to the blackboard
assert(isEncodable(uiValue, true));
@@ -336,11 +337,10 @@ bool CFixedPointParameterType::checkValueAgainstRange(double dValue) const
}
// Data conversion
-int32_t CFixedPointParameterType::asInteger(double dValue) const
+int32_t CFixedPointParameterType::doubleToBinaryQnm(double dValue) const
{
- // Do the conversion
// For Qn.m number, multiply by 2^n and round to the nearest integer
- int32_t iData = (int32_t)(round(dValue * (1UL << _uiFractional)));
+ int32_t iData = static_cast<int32_t>(round(dValue * (1UL << _uiFractional)));
// Left justify
// For a Qn.m number, shift 32 - (n + m + 1) bits to the left (the rest of
// the bits aren't used)
@@ -349,12 +349,12 @@ int32_t CFixedPointParameterType::asInteger(double dValue) const
return iData;
}
-double CFixedPointParameterType::asDouble(int32_t iValue) const
+
+double CFixedPointParameterType::binaryQnmToDouble(int32_t iValue) const
{
// Unjustify
iValue >>= getSize() * 8 - getUtilSizeInBits();
- // Convert
- return (double)iValue / (1UL << _uiFractional);
+ return static_cast<double>(iValue) / (1UL << _uiFractional);
}
// From IXmlSource
diff --git a/parameter/FixedPointParameterType.h b/parameter/FixedPointParameterType.h
index acb638a..3ef53eb 100644
--- a/parameter/FixedPointParameterType.h
+++ b/parameter/FixedPointParameterType.h
@@ -104,18 +104,18 @@ private:
bool convertFromHexadecimal(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
/**
- * Convert a QI QF represented string into an unsigned long integer.
+ * Convert a Qn.m represented string into an unsigned long integer.
* In case of a failing conversion or encodability, this function set the error to
* illegal value provided and gives the range allowed for the parameter.
*
- * @param[in] strValue Parameter read from the XML file representated as a string in QIQF
+ * @param[in] strValue Parameter read from the XML file representated as a string in Qn.m
* representation.
* @param[out] uiValue Parameter representated as a long unsigned integer.
* @param[in:out] parameterAccessContext Parameter access context.
*
* @return true if the string was successfully converted, false otherwise.
*/
- bool convertFromQiQf(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
+ bool convertFromQnm(const string& strValue, uint32_t& uiValue, CParameterAccessContext& parameterAccessContext) const;
/**
* Set the out of range error.
@@ -129,9 +129,25 @@ private:
// Check if data is encodable
bool checkValueAgainstRange(double dValue) const;
- // Data conversion
- int32_t asInteger(double dValue) const;
- double asDouble(int32_t iValue) const;
+
+ /**
+ * Convert a double towards a Qn.m representation which is stored in binary format.
+ * This value is rounded if the double is not encodable in the corresponding Qn.m format.
+ *
+ * @param[in] dValue the double which should be converted.
+ *
+ * @return the integer which contains the converted Qn.m number.
+ */
+ int32_t doubleToBinaryQnm(double dValue) const;
+
+ /**
+ * Convert a Qn.m binary number towards its double representation.
+ *
+ * @param[in] iValue the integer which contains the Qn.m number which should be converted.
+ *
+ * @return the double which contains the double representation of iValue.
+ */
+ double binaryQnmToDouble(int32_t iValue) const;
// Integral part in Q notation
uint32_t _uiIntegral;