aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--parameter/SelectionCriterion.cpp4
-rw-r--r--parameter/SelectionCriterionType.cpp32
-rw-r--r--parameter/SelectionCriterionType.h23
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. */
};