From 5fb2ec097a22614c2869194cbcc83af59314ed93 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 Date: Tue, 25 Oct 2022 18:55:34 +0200 Subject: [PATCH] Add StringOr and StringAnd with 3 constraints --- src/configconstraints_base.h | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/configconstraints_base.h b/src/configconstraints_base.h index 30472f6..340f5f9 100644 --- a/src/configconstraints_base.h +++ b/src/configconstraints_base.h @@ -52,6 +52,21 @@ ConfigConstraintReturnType StringOr(const std::string &str) return tl::make_unexpected(fmt::format("None of the following 2 constraints succeded: {} | {}", result0.error(), result1.error())); } +template::ConstraintCallback callback0, ConfigWrapper::ConstraintCallback callback1, ConfigWrapper::ConstraintCallback callback2> +ConfigConstraintReturnType StringOr(const std::string &str) +{ + const auto result0 = callback0(str); + if (result0) + return {}; + const auto result1 = callback1(str); + if (result1) + return {}; + const auto result2 = callback2(str); + if (result2) + return {}; + return tl::make_unexpected(fmt::format("None of the following 3 constraints succeded: {} | {} | {}", result0.error(), result1.error(), result2.error())); +} + template::ConstraintCallback callback0, ConfigWrapper::ConstraintCallback callback1> ConfigConstraintReturnType StringAnd(const std::string &str) { @@ -62,6 +77,18 @@ ConfigConstraintReturnType StringAnd(const std::string &str) return {}; } +template::ConstraintCallback callback0, ConfigWrapper::ConstraintCallback callback1, ConfigWrapper::ConstraintCallback callback2> +ConfigConstraintReturnType StringAnd(const std::string &str) +{ + if (const auto result = callback0(str); !result) + return tl::make_unexpected(result.error()); + if (const auto result = callback1(str); !result) + return tl::make_unexpected(result.error()); + if (const auto result = callback2(str); !result) + return tl::make_unexpected(result.error()); + return {}; +} + template ConfigConstraintReturnType OneOf(typename ConfigWrapper::value_t val) {