From 76f31e2c4e9cda441a0edcdb85cd2a564d8c8573 Mon Sep 17 00:00:00 2001 From: Mathias Baumann Date: Tue, 12 Oct 2021 15:24:55 +0200 Subject: [PATCH] Whiskers: Support conditional value parameters for lists --- libsolutil/Whiskers.cpp | 12 +++++++----- libsolutil/Whiskers.h | 7 ++++--- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/libsolutil/Whiskers.cpp b/libsolutil/Whiskers.cpp index e236104c7af2..340527bdd1a3 100644 --- a/libsolutil/Whiskers.cpp +++ b/libsolutil/Whiskers.cpp @@ -189,11 +189,13 @@ string Whiskers::replace( if (conditionName[0] == '+') { string tag = conditionName.substr(1); - assertThrow( - _parameters.count(tag), - WhiskersError, "Tag " + tag + " used as condition but was not set." - ); - conditionValue = !_parameters.at(tag).empty(); + + if (_parameters.count(tag)) + conditionValue = !_parameters.at(tag).empty(); + else if (_listParameters.count(tag)) + conditionValue = !_listParameters.at(tag).empty(); + else + assertThrow(false, WhiskersError, "Tag " + tag + " used as condition but was not set."); } else { diff --git a/libsolutil/Whiskers.h b/libsolutil/Whiskers.h index 113fbe6ed1aa..7bbf74f09649 100644 --- a/libsolutil/Whiskers.h +++ b/libsolutil/Whiskers.h @@ -60,12 +60,13 @@ DEV_SIMPLE_EXCEPTION(WhiskersError); * - Condition parameter: ......, where "" is optional * replaced (and recursively expanded) by the first part if the condition is true * and by the second (or empty string if missing) if the condition is false - * - Conditional string parameter: ...... - * Works similar to a conditional parameter where the checked condition is - * that the regular (string) parameter called "name" is non-empty. * - List parameter: <#list>... * The part between the tags is repeated as often as values are provided * in the mapping. Each list element can have its own parameter -> value mapping. + * - Conditional value parameter: ...... + * Works similar to a conditional parameter where the checked condition is + * that the string or list parameter called "name" is non-empty or contains + * no elements respectively. */ class Whiskers {