feat(cpp-object-oriented-modular-refactoring): step 3 - foundation-google-style
This commit is contained in:
@@ -1,30 +1,21 @@
|
||||
#include "fesa/core/diagnostic.hpp"
|
||||
#include "fesa/core/diagnostic.h"
|
||||
|
||||
#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);
|
||||
});
|
||||
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.entity_identity, left.code) <
|
||||
std::tie(right.location.file, right.location.line, right.keyword,
|
||||
right.entity_identity, right.code);
|
||||
});
|
||||
}
|
||||
|
||||
} // namespace fesa
|
||||
} // namespace fesa
|
||||
|
||||
+20
-26
@@ -1,42 +1,36 @@
|
||||
#include "fesa/core/status.hpp"
|
||||
#include "fesa/core/status.h"
|
||||
|
||||
#include <utility>
|
||||
|
||||
namespace fesa {
|
||||
|
||||
Status Status::ok() {
|
||||
return Status{true, std::nullopt, {}};
|
||||
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(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)};
|
||||
}
|
||||
|
||||
Status Status::failure(
|
||||
FailureCategory category, std::vector<Diagnostic> diagnostics) {
|
||||
sortDiagnostics(diagnostics);
|
||||
return Status{false, category, std::move(diagnostics)};
|
||||
bool Status::IsOk() const noexcept { return is_ok_; }
|
||||
|
||||
std::optional<FailureCategory> Status::Category() const noexcept {
|
||||
return category_;
|
||||
}
|
||||
|
||||
bool Status::isOk() const noexcept {
|
||||
return isOk_;
|
||||
const std::vector<Diagnostic>& Status::Diagnostics() const noexcept {
|
||||
return diagnostics_;
|
||||
}
|
||||
|
||||
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},
|
||||
Status::Status(bool is_ok, std::optional<FailureCategory> category,
|
||||
std::vector<Diagnostic> diagnostics)
|
||||
: is_ok_{is_ok},
|
||||
category_{category},
|
||||
diagnostics_{std::move(diagnostics)} {}
|
||||
|
||||
} // namespace fesa
|
||||
} // namespace fesa
|
||||
|
||||
Reference in New Issue
Block a user