mirror of
https://github.com/WarmUpTill/SceneSwitcher.git
synced 2026-08-12 20:28:11 -05:00
Add option for short circuit evaluation of conditions
This commit is contained in:
@@ -19,6 +19,15 @@ const std::map<Logic::Type, const char *> Logic::localeMap = {
|
||||
|
||||
bool Logic::ApplyConditionLogic(Type type, bool currentMatchResult,
|
||||
bool conditionMatched, const char *context)
|
||||
{
|
||||
return ApplyConditionLogic(
|
||||
type, currentMatchResult,
|
||||
[conditionMatched]() { return conditionMatched; }, context);
|
||||
}
|
||||
|
||||
bool Logic::ApplyConditionLogic(Type type, bool currentMatchResult,
|
||||
const std::function<bool()> &evaluateCondition,
|
||||
const char *context)
|
||||
{
|
||||
if (!context) {
|
||||
context = "";
|
||||
@@ -26,22 +35,22 @@ bool Logic::ApplyConditionLogic(Type type, bool currentMatchResult,
|
||||
|
||||
switch (type) {
|
||||
case Type::ROOT_NONE:
|
||||
return conditionMatched;
|
||||
return evaluateCondition();
|
||||
case Type::ROOT_NOT:
|
||||
return !conditionMatched;
|
||||
return !evaluateCondition();
|
||||
case Type::ROOT_LAST:
|
||||
break;
|
||||
case Type::NONE:
|
||||
vblog(LOG_INFO, "skipping condition check for '%s'", context);
|
||||
return currentMatchResult;
|
||||
case Type::AND:
|
||||
return currentMatchResult && conditionMatched;
|
||||
return currentMatchResult && evaluateCondition();
|
||||
case Type::OR:
|
||||
return currentMatchResult || conditionMatched;
|
||||
return currentMatchResult || evaluateCondition();
|
||||
case Type::AND_NOT:
|
||||
return currentMatchResult && !conditionMatched;
|
||||
return currentMatchResult && !evaluateCondition();
|
||||
case Type::OR_NOT:
|
||||
return currentMatchResult || !conditionMatched;
|
||||
return currentMatchResult || !evaluateCondition();
|
||||
case Type::LAST:
|
||||
default:
|
||||
blog(LOG_WARNING, "ignoring invalid logic check (%s)", context);
|
||||
|
||||
Reference in New Issue
Block a user