feat(linear-static-3d-euler-beam): step 8 - core-diagnostics
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
#include "fesa/core/diagnostic.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <tuple>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
void sortDiagnostics(std::vector<Diagnostic>& diagnostics) {
|
||||
// stable_sort makes discovery order the final tie-breaker without storing it
|
||||
// in the externally visible Diagnostic record.
|
||||
std::stable_sort(
|
||||
diagnostics.begin(),
|
||||
diagnostics.end(),
|
||||
[](const Diagnostic& left, const Diagnostic& right) {
|
||||
return std::tie(
|
||||
left.location.file,
|
||||
left.location.line,
|
||||
left.keyword,
|
||||
left.entityIdentity,
|
||||
left.code) <
|
||||
std::tie(
|
||||
right.location.file,
|
||||
right.location.line,
|
||||
right.keyword,
|
||||
right.entityIdentity,
|
||||
right.code);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace fesa
|
||||
@@ -0,0 +1,42 @@
|
||||
#include "fesa/core/status.hpp"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
Status Status::ok() {
|
||||
return Status{true, std::nullopt, {}};
|
||||
}
|
||||
|
||||
Status Status::failure(std::vector<Diagnostic> diagnostics) {
|
||||
sortDiagnostics(diagnostics);
|
||||
return Status{false, std::nullopt, std::move(diagnostics)};
|
||||
}
|
||||
|
||||
Status Status::failure(
|
||||
FailureCategory category, std::vector<Diagnostic> diagnostics) {
|
||||
sortDiagnostics(diagnostics);
|
||||
return Status{false, category, std::move(diagnostics)};
|
||||
}
|
||||
|
||||
bool Status::isOk() const noexcept {
|
||||
return isOk_;
|
||||
}
|
||||
|
||||
std::optional<FailureCategory> Status::failureCategory() const noexcept {
|
||||
return category_;
|
||||
}
|
||||
|
||||
const std::vector<Diagnostic>& Status::diagnostics() const noexcept {
|
||||
return diagnostics_;
|
||||
}
|
||||
|
||||
Status::Status(
|
||||
bool isOk,
|
||||
std::optional<FailureCategory> category,
|
||||
std::vector<Diagnostic> diagnostics)
|
||||
: isOk_{isOk},
|
||||
category_{category},
|
||||
diagnostics_{std::move(diagnostics)} {}
|
||||
|
||||
} // namespace fesa
|
||||
Reference in New Issue
Block a user