Class ValidationContext
Defined in File ValidationContext.h
Class Documentation
-
class ValidationContext
Provides a context to push validation errors.
Public Functions
-
inline ValidationContext()
Construct a new validation context.
-
inline ValidationContext(const ValidationContext &other)
Copy constructor for ValidationContext.
-
inline auto is_empty() const noexcept -> bool
Check if empty.
-
template<typename T>
void add_validation_error(const std::string &field_name, T value, const std::string &message) Add validation error based on a value.
- Parameters
field_name – the name of the field/key that failed validation
value – the value of the field that was invalid
message – the message that describes the error, this could be decribing that the field is required, numeric, needs to meet a specific regular expression.
-
inline void add_missing_field_error(const std::string &field_name)
Add required field validation error.
This is a convenience method used when there is a required field missing.
- Parameters
field_name – the name the field/key that failed validation
-
inline void add_value_regex_error(const std::string &field_name, const std::string &value, const std::string &pattern)
Add validation error based on a regular expression failing.
- Parameters
field_name – the name the field/key that failed validation
value – the value of the field that was invalid
pattern – the regular expression the field value should have matched to
-
template<typename T>
void add_value_list_error(const std::string &field_name, const T &value, const std::vector<T> &list) Add validation error based on value not present in a list.
- Parameters
field_name – the name the field/key that failed validation
value – the value of the field that was invalid
list – the vector of values that should have contained the field value
-
inline void copy_errors(const ValidationContext &other)
copy validation errors from a different context.
This allows the use of a sub-validation context where the application can create another context, add validation to it, check if that is empty or not before proceeding.
- Parameters
other – the other validation context to copy errors from.
-
void throw_error_if_not_empty()
throw a validation error if not empty.
If the context is empty this will do nothing. However, if there is at least one validation error then this will throw a
See also
- Throws
ska::pst::common::pst_validation_error – if there are valid error records
-
inline ValidationContext()