diff options
author | Francois Gaffie <francois.gaffie@intel.com> | 2013-10-15 11:01:23 +0200 |
---|---|---|
committer | David Wagner <david.wagner@intel.com> | 2014-02-12 17:04:14 +0100 |
commit | a0c3b8a42e473fa96ec469c2e691a919f31df26d (patch) | |
tree | a962dce8a7fad4e753b81cb5d5a378a541ae86fa | |
parent | ff574884b80ca5e96960565ada430d8207951b31 (diff) | |
download | external_parameter-framework-a0c3b8a42e473fa96ec469c2e691a919f31df26d.zip external_parameter-framework-a0c3b8a42e473fa96ec469c2e691a919f31df26d.tar.gz external_parameter-framework-a0c3b8a42e473fa96ec469c2e691a919f31df26d.tar.bz2 |
Adds default value pair for inclusive criterion
BZ: 99956
Inclusive criterion type does not allow to check if the bitfield
is empty, i.e., if zero is not available.
This patch adds the default value pair "none, 0" to allow
check either if the criterion "Is" 0, and establishes consistency
with inclusion rule. It also allows to convert a concatenated
chain of string value, where "|" is considered as AND rule into
the corresponding numerical value.
Change-Id: I4ee7c0f69228a727964ab80050ac12c6babd4f58
Signed-off-by: Francois Gaffie <francois.gaffie@intel.com>
Signed-off-by: Jorge Quintero <jorge.quintero@intel.com>
Reviewed-on: http://android.intel.com:8080/138518
Reviewed-by: Centelles, Sylvain <sylvain.centelles@intel.com>
Tested-by: Barthes, FabienX <fabienx.barthes@intel.com>
-rw-r--r-- | parameter/SelectionCriterion.cpp | 4 | ||||
-rw-r--r-- | parameter/SelectionCriterionType.cpp | 32 | ||||
-rw-r--r-- | parameter/SelectionCriterionType.h | 23 |
3 files changed, 57 insertions, 2 deletions
diff --git a/parameter/SelectionCriterion.cpp b/parameter/SelectionCriterion.cpp index 908aaf6..9b23cb4 100644 --- a/parameter/SelectionCriterion.cpp +++ b/parameter/SelectionCriterion.cpp @@ -99,7 +99,9 @@ bool CSelectionCriterion::isNot(int iState) const bool CSelectionCriterion::includes(int iState) const { - return (_iState & iState) != 0; + // For inclusive criterion, Includes checks if ALL the bit sets in iState are set in the + // current _iState. + return (_iState & iState) == iState; } bool CSelectionCriterion::excludes(int iState) const diff --git a/parameter/SelectionCriterionType.cpp b/parameter/SelectionCriterionType.cpp index 6e5a8cc..2f07ade 100644 --- a/parameter/SelectionCriterionType.cpp +++ b/parameter/SelectionCriterionType.cpp @@ -23,11 +23,19 @@ * UPDATED: 2011-07-27 */ #include "SelectionCriterionType.h" +#include "Tokenizer.h" #define base CElement +const string CSelectionCriterionType::_strDelimiter = "|"; + CSelectionCriterionType::CSelectionCriterionType(bool bIsInclusive) : _bInclusive(bIsInclusive) { + // For inclusive criterion type, appends the pair none,0 by default. + if (_bInclusive) { + + _numToLitMap["none"] = 0; + } } string CSelectionCriterionType::getKind() const @@ -60,6 +68,30 @@ bool CSelectionCriterionType::addValuePair(int iValue, const string& strValue) bool CSelectionCriterionType::getNumericalValue(const string& strValue, int& iValue) const { + if (_bInclusive) { + + Tokenizer tok(strValue, _strDelimiter); + vector<string> astrValues = tok.split(); + uint32_t uiNbValues = astrValues.size(); + int iResult = 0; + uint32_t uiValueIndex; + + // Looping on each string delimited by "|" token and adding the associated value + for (uiValueIndex = 0; uiValueIndex < uiNbValues; uiValueIndex++) { + + if (!getAtomicNumericalValue(astrValues[uiValueIndex], iResult)) { + + return false; + } + iValue |= iResult; + } + return true; + } + return getAtomicNumericalValue(strValue, iValue); +} + +bool CSelectionCriterionType::getAtomicNumericalValue(const string& strValue, int& iValue) const +{ NumToLitMapConstIt it = _numToLitMap.find(strValue); if (it != _numToLitMap.end()) { diff --git a/parameter/SelectionCriterionType.h b/parameter/SelectionCriterionType.h index bff11c5..bc96750 100644 --- a/parameter/SelectionCriterionType.h +++ b/parameter/SelectionCriterionType.h @@ -38,6 +38,16 @@ public: // From ISelectionCriterionTypeInterface virtual bool addValuePair(int iValue, const string& strValue); + /** + * Retrieve the numerical value from the string representation of the criterion type. + * + * @param[in] strValue: criterion type value represented as a stream. If the criterion is + * inclusive, it supports more than one criterion type value delimited + * by the "|" symbol. + * @param[out] iValue: criterion type value represented as an integer. + * + * @return true if integer value retrieved from the string one, false otherwise. + */ virtual bool getNumericalValue(const string& strValue, int& iValue) const; virtual bool getLiteralValue(int iValue, string& strValue) const; virtual bool isTypeInclusive() const; @@ -51,8 +61,19 @@ public: // From CElement virtual string getKind() const; private: - + /** + * Retrieve the numerical value from the string representation of the criterion type. + * + * @param[in] strValue: criterion type value represented as a stream. If the criterion is + * inclusive, it expects only one criterion type value. + * @param[out] iValue: criterion type value represented as an integer. + * + * @return true if integer value retrieved from the string one, false otherwise. + */ + bool getAtomicNumericalValue(const string& strValue, int& iValue) const; bool _bInclusive; map<string, int> _numToLitMap; + + static const std::string _strDelimiter; /**< Inclusive criterion type delimiter. */ }; |