From 6ba361d96bc2581667b3400f87ff89fae6449e1f Mon Sep 17 00:00:00 2001 From: Patrick Benavoli Date: Wed, 31 Aug 2011 11:23:24 +0200 Subject: parameter-framework: improvements and corrections BZ: 6721 - Bug correction concerning selection criteria display (inclusive type) - Adapted XML format to allow for only on parameter to be associated to a domain - Removed unused files in parameter project Change-Id: I9f42d08ff8cb60354714fe3d6b0f0b321ad0a7bf Orig-Change-Id: I837e553070f5acf2d275082c986ba29433493e31 Signed-off-by: Patrick Benavoli Reviewed-on: http://android.intel.com:8080/16878 Reviewed-by: Mahe, Erwan Tested-by: Barthes, FabienX Reviewed-by: buildbot Tested-by: buildbot --- parameter/SelectionCriterionType.cpp | 91 ++++++++++++++++++++++++++++++++++-- 1 file changed, 86 insertions(+), 5 deletions(-) (limited to 'parameter/SelectionCriterionType.cpp') diff --git a/parameter/SelectionCriterionType.cpp b/parameter/SelectionCriterionType.cpp index 2e562da..478fb43 100644 --- a/parameter/SelectionCriterionType.cpp +++ b/parameter/SelectionCriterionType.cpp @@ -42,15 +42,21 @@ string CSelectionCriterionType::getKind() const } // From ISelectionCriterionTypeInterface -std::string CSelectionCriterionType::getCriterionTypeName() -{ - return getName(); -} - bool CSelectionCriterionType::addValuePair(int iValue, const string& strValue) { + // Check 1 bit set only for inclusive types + if (_bInclusive && (!iValue || (iValue & (iValue - 1)))) { + + log("Rejecting value pair association: 0x%X - %s for Selection Criterion Type %s", iValue, strValue.c_str(), getName().c_str()); + + return false; + } + + // Check already inserted if (_numToLitMap.find(strValue) != _numToLitMap.end()) { + log("Rejecting value pair association (literal already present): 0x%X - %s for Selection Criterion Type %s", iValue, strValue.c_str(), getName().c_str()); + return false; } _numToLitMap[strValue] = iValue; @@ -91,3 +97,78 @@ bool CSelectionCriterionType::isTypeInclusive() const { return _bInclusive; } + +// Value list +string CSelectionCriterionType::listPossibleValues() const +{ + string strValueList = "{"; + + // Get comma seprated list of values + NumToLitMapConstIt it; + bool bFirst = true; + + for (it = _numToLitMap.begin(); it != _numToLitMap.end(); ++it) { + + if (bFirst) { + + bFirst = false; + } else { + strValueList += ", "; + } + strValueList += it->first; + } + + strValueList += "}"; + + return strValueList; +} + +// Formatted state +string CSelectionCriterionType::getFormattedState(int iValue) const +{ + string strFormattedState; + + if (_bInclusive) { + + // Need to go through all set bit + uint32_t uiBit; + bool bFirst = true; + + for (uiBit = 0; uiBit < sizeof(iValue) << 3; uiBit++) { + + int iSingleBitValue = iValue & (1 << uiBit); + + // Check if current bit is set + if (!iSingleBitValue) { + + continue; + } + + // Simple translation + string strSingleValue; + + getLiteralValue(iSingleBitValue, strSingleValue); + + if (bFirst) { + + bFirst = false; + } else { + strFormattedState += "|"; + } + + strFormattedState += strSingleValue; + } + + } else { + // Simple translation + getLiteralValue(iValue, strFormattedState); + } + + // Sometimes nothing is set + if (strFormattedState.empty()) { + + strFormattedState = ""; + } + + return strFormattedState; +} -- cgit v1.1