Skip to content

Commit

Permalink
Errata: Better support for notes with only code and/or severity.
Browse files Browse the repository at this point in the history
  • Loading branch information
SolidWallOfCode committed Dec 13, 2023
1 parent 563597c commit 5cb7e29
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 19 deletions.
35 changes: 31 additions & 4 deletions code/include/swoc/Errata.h
Original file line number Diff line number Diff line change
Expand Up @@ -337,26 +337,38 @@ class Errata {
* @param text Text of the message.
* @return *this
*
* The error code is set to the default.
* @a text is localized to @a this and does not need to be persistent.
* The severity is updated to @a severity if the latter is more severe.
*/
self_type &note(Severity severity, std::string_view text);

/** Add an @c Annotation to the top with @a text and local @a severity.
* @param severity The local severity.
* @return *this
*
* The annotation uses the format @c AUTOTEXT_SEVERITY with the argument @a severity.
* @see AUTOTEXT_SEVERITY
*/
self_type &note(Severity severity);

/** Add an @c Annotation to the top based on error code @a code.
* @param code Error code.
* @return *this
*
* The annotation text is constructed as the short, long, and numeric value of @a code.
* The annotation uses the format @c AUTOTEXT_CODE with the argument @a ec.
* @see AUTOTEXT_CODE
*
* @note @a ec is used only for formatting, the @c Errata error code is unchanged.
*/
self_type &note(code_type const &code);
self_type &note(code_type const &ec);

/** Append an @c Annotation to the top based on error code @a code with @a severity.
* @param severity Local severity.
* @param code Error code.
* @return *this
*
* The annotation text is constructed as the short, long, and numeric value of @a code.
* The annotation uses the format @c AUTOTEXT_SEVERITY_CODE with the argument @a severity.
* @see AUTOTEXT_SEVERITY_CODE
*/
self_type &note(code_type const &code, Severity severity);

Expand Down Expand Up @@ -1173,6 +1185,21 @@ Errata::note(Severity severity, std::string_view text) {
return this->note_s(severity, text);
}

inline Errata &
Errata::note(Severity severity) {
return this->note(severity, AUTOTEXT_SEVERITY, severity);
}

inline Errata &
Errata::note(code_type const &code) {
return this->note(AUTOTEXT_CODE, code);
}

inline Errata &
Errata::note(code_type const &ec, Severity severity) {
return this->note(severity, AUTOTEXT_SEVERITY_CODE, severity, ec);
}

template <typename... Args>
Errata &
Errata::note_sv(std::optional<Severity> severity, std::string_view fmt, std::tuple<Args...> const &args) {
Expand Down
20 changes: 5 additions & 15 deletions code/src/Errata.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,6 @@ Errata::sink() {
return *this;
}

Errata &
Errata::note(code_type const &code) {
return this->note("{}"_sv, code);
}

Errata &
Errata::note(code_type const &code, Severity severity) {
return this->note(severity, "{}"_sv, code);
}

Errata::Data *
Errata::data() {
if (!_data) {
Expand All @@ -80,6 +70,11 @@ Errata::data() {
return _data;
}

MemSpan<char>
Errata::alloc(size_t n) {
return this->data()->_arena.alloc(n).rebind<char>();
}

Errata &
Errata::note_s(std::optional<Severity> severity, std::string_view text) {
if (severity.has_value()) {
Expand All @@ -101,11 +96,6 @@ Errata::note_localized(std::string_view const &text, std::optional<Severity> sev
return *this;
}

MemSpan<char>
Errata::alloc(size_t n) {
return this->data()->_arena.alloc(n).rebind<char>();
}

Errata &
Errata::note(const self_type &that) {
if (that._data) {
Expand Down

0 comments on commit 5cb7e29

Please sign in to comment.