Files
MeanField_SERiF/src/include/serif/discretization/domain/schema/validation/results.hpp

79 lines
3.8 KiB
C++

#pragma once
/**
* @file results.hpp
* @author Emily M. Boudreaux
*
* @brief File containing the data structures used for representing the results of validating a schema against a mesh.
*/
#include <cstddef>
#include <optional>
#include <string_view>
#include <vector>
#include <format>
#include <string>
#include "serif/discretization/domain/relation/validation/runtime.hpp"
// The aggregate result of validating a whole schema against a mesh
namespace serif::discretization::domain::schema::validation {
/**
* @struct SchemaRelationValidationResult
*
* @brief The result of validating a single relation against a mesh.
*/
struct SchemaRelationValidationResult {
std::size_t relationIndex{0}; ///< The index of the relation in the schema's relation list.
std::string_view relationName; ///< The name of the relation being validated.
relation::validation::RelationValidationResult result; ///< The result of validating the relation against the mesh.
[[nodiscard]] bool valid() const noexcept; ///< Check if the relation validation was successful.
[[nodiscard]] explicit operator bool() const noexcept; ///< Check if the relation validation was successful (explicit conversion to bool).
};
/**
* @struct SchemaValidationResult
*
* @brief The result of validating a schema against a mesh.
*/
struct SchemaValidationResult {
std::vector<SchemaRelationValidationResult> relationResults; ///< The results of validating each relation in the schema.
[[nodiscard]] bool valid() const noexcept; ///< Check if all relations in the schema validation were successful.
[[nodiscard]] explicit operator bool() const noexcept; ///< Check if all relations in the schema validation were successful (explicit conversion to bool).
[[nodiscard]] std::size_t relation_count() const noexcept; ///< Get the total number of relations in the schema.
[[nodiscard]] std::size_t failed_relation_count() const noexcept; ///< Get the number of relations that failed validation.
[[nodiscard]] std::size_t passed_relation_count() const noexcept; ///< Get the number of relations that passed validation.
[[nodiscard]] std::optional<std::size_t> first_failed_relation_index() const noexcept; ///< Get the index of the first failed relation, if any.
};
}
/**
* @brief Specialization of std::formatter for SchemaValidationResult to enable formatting with std::format.
*/
template <>
struct std::formatter<serif::discretization::domain::schema::validation::SchemaValidationResult> {
std::formatter<std::string> string_formatter;
constexpr auto parse(std::format_parse_context& ctx) {
return string_formatter.parse(ctx);
}
auto format(const serif::discretization::domain::schema::validation::SchemaValidationResult& result, std::format_context& ctx) const {
std::string output;
output += "SchemaValidationResult:\n";
output += std::format(" Valid: {}\n", result.valid());
output += std::format(" Relation count: {}\n", result.relation_count());
output += std::format(" Passed relation count: {}\n", result.passed_relation_count());
output += std::format(" Failed relation count: {}\n", result.failed_relation_count());
if (auto first_failed_index = result.first_failed_relation_index()) {
output += std::format(" First failed relation index: {}\n", *first_failed_index);
} else {
output += " No failed relations.\n";
}
return string_formatter.format(output, ctx);
}
};