mirror of
https://github.com/Kitware/CMake.git
synced 2026-02-28 19:58:34 -06:00
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:
@@ -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;
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user