From 50565575c5715c2a5637b193d11ebf16874d34d2 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Wed, 8 Apr 2015 18:11:45 +0200 Subject: [PATCH 1/2] libcriterion: Fix default state display for InclusiveCriterion InclusiveCriterion has a default state called "none", this state was displayed through default Criterion behavior which is: if no valid state is available, let's display "". This patch test explicitly the default value when formatting the state of an InclusiveCriterion. It also introduces the test getLiteralValue return when formatting a standard Criterion rather than testing the generated string emptiness. A difference can now be made between an inclusive criterion default value and an exclusive criterion with an unknown state. Signed-off-by: Jules Clero --- parameter/criterion/include/criterion/Criterion.h | 12 ------------ parameter/criterion/src/Criterion.cpp | 15 ++++----------- parameter/criterion/src/InclusiveCriterion.cpp | 10 ++++++++-- 3 files changed, 12 insertions(+), 25 deletions(-) diff --git a/parameter/criterion/include/criterion/Criterion.h b/parameter/criterion/include/criterion/Criterion.h index d435faf34..4296ffdc7 100644 --- a/parameter/criterion/include/criterion/Criterion.h +++ b/parameter/criterion/include/criterion/Criterion.h @@ -137,18 +137,6 @@ class Criterion : public IXmlSource, public CriterionInterface const ValuePairs& derivedValuePairs, const MatchMethods& derivedMatchMethods); - /** Set a "default formatted state" when no criterion state is set - * - * @param formattedState, the formatted state string to check - * @result the reference of the string passed in parameter filled with the default value - * if it was empty - * - * This method returns a reference on his referenced parameter in order to have the easy - * notation. - * return checkFormattedStateEmptyness(myFormattedStateToReturn); - */ - std::string& checkFormattedStateEmptyness(std::string& formattedState) const; - /** Contains pair association between literal and numerical value */ ValuePairs mValuePairs; diff --git a/parameter/criterion/src/Criterion.cpp b/parameter/criterion/src/Criterion.cpp index 3f75feb90..0d9b08946 100644 --- a/parameter/criterion/src/Criterion.cpp +++ b/parameter/criterion/src/Criterion.cpp @@ -221,9 +221,10 @@ bool Criterion::getLiteralValue(int numericalValue, std::string& literalValue) c std::string Criterion::getFormattedState() const { std::string formattedState; - getLiteralValue(mState, formattedState); - - return Criterion::checkFormattedStateEmptyness(formattedState); + if (!getLiteralValue(mState, formattedState)) { + formattedState = ""; + } + return formattedState; } std::string Criterion::listPossibleValues() const @@ -246,14 +247,6 @@ std::string Criterion::listPossibleValues() const return possibleValues; } -std::string& Criterion::checkFormattedStateEmptyness(std::string& formattedState) const -{ - if (formattedState.empty()) { - formattedState = ""; - } - return formattedState; -} - bool Criterion::match(const std::string& method, int32_t state) const { return mMatchMethods.at(method)(state); diff --git a/parameter/criterion/src/InclusiveCriterion.cpp b/parameter/criterion/src/InclusiveCriterion.cpp index 5943e8600..aabe4e7f1 100644 --- a/parameter/criterion/src/InclusiveCriterion.cpp +++ b/parameter/criterion/src/InclusiveCriterion.cpp @@ -31,6 +31,7 @@ #include "Tokenizer.h" #include +#include namespace core { @@ -92,6 +93,12 @@ bool InclusiveCriterion::getNumericalValue(const std::string& literalValue, std::string InclusiveCriterion::getFormattedState() const { std::string formattedState; + if (mState == 0) { + // Default inclusive criterion state is always present + getLiteralValue(0, formattedState); + return formattedState; + } + uint32_t bit; bool first = true; @@ -117,8 +124,7 @@ std::string InclusiveCriterion::getFormattedState() const formattedState += atomicState; } - - return Criterion::checkFormattedStateEmptyness(formattedState); + return formattedState; } } /** criterion namespace */ From db5bfd36273152e7355b3054349cfdec6bb994b2 Mon Sep 17 00:00:00 2001 From: Jules Clero Date: Thu, 9 Apr 2015 11:12:04 +0200 Subject: [PATCH 2/2] libcriterion: Update Criterion type display string for consistency Criterion type, which can be inclusive or exclusive is displayed sometimes with a capital letter and sometimes not. This patch corrects this behaviour to always have the first letter in capital. Signed-off-by: Jules Clero --- parameter/criterion/src/Criterion.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/parameter/criterion/src/Criterion.cpp b/parameter/criterion/src/Criterion.cpp index 0d9b08946..872926eeb 100644 --- a/parameter/criterion/src/Criterion.cpp +++ b/parameter/criterion/src/Criterion.cpp @@ -105,6 +105,7 @@ std::string Criterion::getCriterionName() const std::string Criterion::getFormattedDescription(bool bWithTypeInfo, bool bHumanReadable) const { std::string strFormattedDescription; + std::string typeName = isInclusive() ? "Inclusive" : "Exclusive"; if (bHumanReadable) { @@ -118,7 +119,7 @@ std::string Criterion::getFormattedDescription(bool bWithTypeInfo, bool bHumanRe // Type Kind strFormattedDescription += "("; - strFormattedDescription += isInclusive() ? "Inclusive" : "Exclusive"; + strFormattedDescription += typeName; strFormattedDescription += "): "; // States @@ -140,7 +141,7 @@ std::string Criterion::getFormattedDescription(bool bWithTypeInfo, bool bHumanRe if (bWithTypeInfo) { // Type Kind strFormattedDescription += ", type kind: "; - strFormattedDescription += isInclusive() ? "inclusive" : "exclusive"; + strFormattedDescription += typeName; } // Current State