diff options
author | Alex Turbov <i.zaufi@gmail.com> | 2024-08-13 18:39:21 (GMT) |
---|---|---|
committer | Alex Turbov <i.zaufi@gmail.com> | 2024-08-15 18:01:34 (GMT) |
commit | 0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb (patch) | |
tree | 2211558444609e4f8d07cac3c5abb7cd99da7766 /Source/cmJSONHelpers.h | |
parent | 503a73b1832dde9685a44c2ee9cc904e39aeaee4 (diff) | |
download | CMake-0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb.zip CMake-0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb.tar.gz CMake-0b334e5bfb6bca7411b75cb0dd0715bc85bc68eb.tar.bz2 |
cmJSONHelpers.h: Add generic predicate checking helper
And use it in the `cmCMakePresetsGraphReadJSON.cxx` to check
presets schema version in the declarative way.
Co-authored-by: Martin Duffy <martin.duffy@kitware.com>
Diffstat (limited to 'Source/cmJSONHelpers.h')
-rw-r--r-- | Source/cmJSONHelpers.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Source/cmJSONHelpers.h b/Source/cmJSONHelpers.h index b35825d..ef94c14 100644 --- a/Source/cmJSONHelpers.h +++ b/Source/cmJSONHelpers.h @@ -390,4 +390,19 @@ struct cmJSONHelperBuilder return func(out, value, state); }; } + + template <typename T, typename F, typename P> + static cmJSONHelper<T> Checked(const JsonErrors::ErrorGenerator& error, + F func, P predicate) + { + return [error, func, predicate](T& out, const Json::Value* value, + cmJSONState* state) -> bool { + bool result = func(out, value, state); + if (result && !predicate(out)) { + error(value, state); + result = false; + } + return result; + }; + } }; |