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>
This commit is contained in:
Alex Turbov
2024-08-13 22:39:21 +04:00
parent 503a73b183
commit 0b334e5bfb
6 changed files with 35 additions and 8 deletions

View File

@@ -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;
};
}
};