载入中...
搜索中...
未找到
Diagnostic.cpp
浏览该文件的文档.
1#include "common/Diagnostic.h"
2
3#include <ostream>
4
5namespace eve {
6
7std::ostream& operator<<(std::ostream& stream, Severity severity) { return stream << severityName(severity); }
8
9std::ostream& operator<<(std::ostream& stream, DiagnosticCode code) { return stream << diagnosticCodeName(code); }
10
11Diagnostic::Diagnostic() noexcept = default;
12Diagnostic::~Diagnostic() noexcept = default;
13Diagnostic::Diagnostic(const Diagnostic& other) = default;
14Diagnostic::Diagnostic(Diagnostic&& other) noexcept = default;
15Diagnostic& Diagnostic::operator=(const Diagnostic& other) = default;
16Diagnostic& Diagnostic::operator=(Diagnostic&& other) noexcept = default;
17
19 : Diagnostic(code, severity, std::move(message), std::move(path), {}, {}) {}
20
22 return Diagnostic(code, Severity::Error, std::move(message), std::move(path));
23}
25 return Diagnostic(code, Severity::Warning, std::move(message), std::move(path));
26}
27
28Diagnostic::Diagnostic(DiagnosticCode code, Severity severity, std::string message, std::string path,
29 DiagnosticDetails details, std::string source)
30 : code_(code),
31 severity_(severity),
32 message_(std::move(message)),
33 path_(std::move(path)),
34 details_(std::move(details)),
35 source_(std::move(source)) {}
36
38 std::string source) {
39 return Diagnostic(code, Severity::Error, std::move(message), std::move(path), std::move(details),
40 std::move(source));
41}
43 std::string source) {
44 return Diagnostic(code, Severity::Warning, std::move(message), std::move(path), std::move(details),
45 std::move(source));
46}
47void Diagnostic::addDetail(std::string key, std::string value) {
48 details_.emplace_back(std::move(key), std::move(value));
49}
50} // namespace eve
51
52
53#if defined(_WIN32) && defined(EVENGINE_MODULE_DLL)
54template class __declspec(dllexport) std::vector<eve::Diagnostic>;
55#endif
Stable, structured diagnostics shared by engine modules.
SQObjectPtr key
Definition ECS.cpp:155
std::string message
DiagnosticCode code
std::string path
Definition PlayHost.cpp:111
Object::Ptr value
std::string_view source
A structured explanation of a failed, degraded, or noteworthy result.
Definition Diagnostic.h:94
DiagnosticCode code() const noexcept
Stable machine-readable code.
Definition Diagnostic.h:143
const std::string & path() const noexcept
Optional field, property, URI, or logical path.
Definition Diagnostic.h:149
static Diagnostic error(DiagnosticCode code, std::string message, std::string path={})
Construct an error diagnostic with the standard error severity.
void addDetail(std::string key, std::string value)
Add structured context without changing the stable code.
static Diagnostic warning(DiagnosticCode code, std::string message, std::string path={})
Construct a warning diagnostic.
Diagnostic() noexcept
Construct an empty informational diagnostic.
const std::string & message() const noexcept
Human-readable explanation.
Definition Diagnostic.h:147
const DiagnosticDetails & details() const noexcept
Structured context in insertion order.
Definition Diagnostic.h:151
const std::string & source() const noexcept
Optional producer or subsystem that emitted the diagnostic.
Definition Diagnostic.h:153
Build metadata (engine git commit, build time, third-party version).
Definition Build.cpp:16
std::vector< DiagnosticDetail > DiagnosticDetails
Owning collection of diagnostic details with stable insertion order.
Definition Diagnostic.h:88
DiagnosticCode
Stable machine-readable diagnostic codes.
Definition Diagnostic.h:47
std::ostream & operator<<(std::ostream &stream, Severity severity)
Writes a severity for diagnostics and test output.
Definition Diagnostic.cpp:7
constexpr std::string_view severityName(Severity severity) noexcept
Returns the stable lowercase severity spelling.
Definition Diagnostic.h:28
Severity
Stable severity of a diagnostic, independent of its display text.
Definition Diagnostic.h:20
constexpr std::string_view diagnosticCodeName(DiagnosticCode code) noexcept
Return a stable, compact spelling useful for logs and diagnostics.
Definition Diagnostic.h:176