53namespace swoc {
inline namespace SWOC_VERSION_NS {
113 unsigned short level()
const;
139 using Linkage = swoc::IntrusiveLinkage<self_type, &self_type::_next, &self_type::_prev>;
155 unsigned short level = 0);
184 std::string_view
localize(std::string_view src);
195 TextView _indent_text = DEFAULT_INDENT_TEXT;
206 static constexpr struct AutoText {
303 explicit Errata(std::string_view
const &text);
317 template <
typename... Args>
Errata(
code_type const &type, std::string_view fmt, Args &&...args);
319 template <
typename... Args>
explicit Errata(std::string_view fmt, Args &&...args);
390 template <
typename... Args>
self_type &
note(std::string_view fmt, Args &&...args);
400 template <
typename... Args>
self_type &
note_v(std::string_view fmt, std::tuple<Args...>
const &args);
435 template <
typename... Args>
475 friend std::ostream &operator<<(std::ostream &,
self_type const &);
482 static inline TextView DEFAULT_INDENT_TEXT =
" ";
493 explicit operator bool()
const;
552 using iterator = Container::iterator;
553 using const_iterator = Container::const_iterator;
558 const_iterator
begin()
const;
562 const_iterator
end()
const;
631 using self_type =
Sink;
634 using Handle = std::shared_ptr<self_type>;
643 static void register_sink(Sink::Handle
const &s);
654 void operator()(
Errata const &e)
const override;
672 std::ostream &write(std::ostream &out)
const;
703extern std::ostream &operator<<(std::ostream &os,
Errata const &stat);
711template <
typename R>
class Rv {
817 template <
typename... Args>
self_type &
note(std::string_view fmt, Args &&...args);
827 template <
typename... Args>
self_type &
note(Severity severity, std::string_view fmt, Args &&...args);
970inline Errata::Annotation::Annotation() =
default;
977 _text = std::string_view{};
997 return _severity.value_or(default_severity);
1009 _arena = std::move(arena);
1014 return _arena.remnant().rebind<
char>();
1019 return _arena.alloc(n).rebind<
char>();
1031 std::swap(
_data, that._data);
1043 auto d = this->
data();
1050 this->
note(AUTOTEXT_CODE, ec);
1070template <
typename... Args>
1072 this->
note_v(fmt, std::forward_as_tuple(args...));
1075template <
typename... Args>
1076Errata::Errata(code_type
const &code, std::string_view fmt, Args &&...args)
1077 :
Errata(code, DEFAULT_SEVERITY, fmt,
std::forward<Args>(args)...) {}
1078template <
typename... Args>
1079Errata::Errata(Severity severity, std::string_view fmt, Args &&...args)
1080 : Errata(DEFAULT_CODE, severity, fmt,
std::forward<Args>(args)...) {}
1081template <
typename... Args>
1082Errata::Errata(std::string_view fmt, Args &&...args) :
Errata(DEFAULT_CODE, DEFAULT_SEVERITY, fmt, std::forward<Args>(args)...) {}
1095 if (
this != &that) {
1097 std::swap(
_data, that._data);
1102inline Errata::operator bool()
const {
1103 return this->
is_ok();
1108 return !this->
is_ok();
1113 return _data ==
nullptr ||
_data->_notes.count() == 0;
1118 return this->
empty() ? DEFAULT_CODE :
_data->_code;
1129 return _data &&
_data->_severity.has_value();
1149 return nullptr ==
_data || this->
severity() < FAILURE_SEVERITY;
1154 return *(
_data->_notes.head());
1159 return *(
_data->_notes.tail());
1171 return this->
note_s({}, text);
1176 return this->
note_s(severity, text);
1186 return this->
note(AUTOTEXT_CODE,
code);
1194template <
typename... Args>
1196Errata::note_sv(std::optional<Severity> severity, std::string_view fmt, std::tuple<Args...>
const &args) {
1204 FixedBufferWriter bw{span};
1205 if (!bw.print_v(fmt, args).error()) {
1206 span = span.prefix(bw.extent());
1207 data->alloc(bw.extent());
1210 span = this->
alloc(bw.extent());
1211 FixedBufferWriter{span}.print_v(fmt, args);
1218template <
typename... Args>
1220Errata::note_v(std::string_view fmt, std::tuple<Args...>
const &args) {
1221 return this->
note_sv({}, fmt, args);
1224template <
typename... Args>
1226Errata::note_v(Severity severity, std::string_view fmt, std::tuple<Args...>
const &args) {
1230template <
typename... Args>
1233 return this->
note_sv({}, fmt, std::forward_as_tuple(args...));
1236template <
typename... Args>
1238Errata::note(Severity severity, std::string_view fmt, Args &&...args) {
1242inline Errata::iterator
1244 return _data ?
_data->_notes.begin() : iterator();
1247inline Errata::const_iterator
1249 return _data ?
_data->_notes.begin() : const_iterator();
1252inline Errata::iterator
1254 return _data ?
_data->_notes.end() : iterator();
1257inline Errata::const_iterator
1259 return _data ?
_data->_notes.end() : const_iterator();
1269 this->data()->_annotation_glue_text = this->data()->localize(text);
1270 this->data()->_glue_final_p = final_glue_p;
1281 this->data()->_annotation_severity_glue_text = this->data()->localize(text);
1292 this->data()->_severity_glue_text = this->data()->localize(text);
1298 return _data ?
_data->_indent_text : DEFAULT_INDENT_TEXT;
1303 this->data()->_indent_text = this->data()->localize(text);
1314template <
typename R>
1321template <
typename R>
1328template <
typename R>
1335template <
typename R>
1342template <
typename R>
1343template <
typename... Args>
1346 _errata.note(fmt, std::forward<Args>(args)...);
1350template <
typename R>
1351template <
typename... Args>
1354 _errata.note(
severity, fmt, std::forward<Args>(args)...);
1358template <
typename R>
1364template <
typename R>
1387template <
typename R>
1393template <
typename R>
1399template <
typename R>
1405template <
typename R>
1415template <
typename R>
1422template <
typename R>
1429template <
typename R>
1436template <
typename R>
1443template <
typename R>
1446 this->
_errata.note(std::move(that));
1451template <
typename R>
1458template <
typename R>
1476template <
size_t IDX,
typename R>
class tuple_element<IDX, swoc::Rv<R>> {
1477 static_assert(
"swoc:Rv tuple index out of range");
1480template <
typename R>
class tuple_element<0, swoc::Rv<R>> {
1485template <
typename R>
class tuple_element<1, swoc::Rv<R>> {
1487 using type = swoc::Errata;
1490template <
typename R>
class tuple_size<swoc::Rv<R>> :
public std::integral_constant<size_t, 2> {};
1494namespace swoc {
inline namespace SWOC_VERSION_NS {
1502template <
size_t IDX,
typename R>
1503typename std::tuple_element<IDX, swoc::Rv<R>>::type &
1504get(swoc::Rv<R> &&rv) {
1505 if constexpr (IDX == 0) {
1507 }
else if constexpr (IDX == 1) {
1512template <
size_t IDX,
typename R>
1513typename std::tuple_element<IDX, swoc::Rv<R>>::type &
1514get(swoc::Rv<R> &rv) {
1515 static_assert(0 <= IDX && IDX <= 1,
"Errata tuple index out of range (0..1)");
1516 if constexpr (IDX == 0) {
1518 }
else if constexpr (IDX == 1) {
1522 throw std::domain_error(
"Errata index value out of bounds");
1525template <
size_t IDX,
typename R>
1526typename std::tuple_element<IDX, swoc::Rv<R>>::type
const &
1527get(swoc::Rv<R>
const &rv) {
1528 static_assert(0 <= IDX && IDX <= 1,
"Errata tuple index out of range (0..1)");
1529 if constexpr (IDX == 0) {
1531 }
else if constexpr (IDX == 1) {
1535 throw std::domain_error(
"Errata index value out of bounds");
Severity severity(Severity default_severity=DEFAULT_SEVERITY) const
std::string_view _text
Annotation text.
swoc::TextView text() const
Get the text of the message.
std::optional< Severity > _severity
Severity.
bool has_severity() const
Check if this has a Severity.
self_type & clear()
Reset to the message to default state.
unsigned short _level
Nesting level for display purposes.
unsigned short level() const
Get the nesting level.
swoc::IntrusiveLinkage< self_type, &self_type::_next, &self_type::_prev > Linkage
self_type & assign(Severity severity)
Set the severity of this.
virtual void operator()(Errata const &) const =0
Handle an abandoned errata.
std::shared_ptr< self_type > Handle
Handle type.
virtual ~Sink()
Force virtual destructor.
static Severity FAILURE_SEVERITY
Severity level at which the instance is a failure of some sort.
TextView severity_glue_text() const
const Annotation & back() const
self_type & assign_indent_text(TextView text)
static TextView DEFAULT_ANNOTATION_GLUE_TEXT
Default glue value (a newline) for text rendering.
self_type & note(std::string_view text)
size_t length() const
Number of messages in the errata.
self_type & note(Severity severity, std::string_view fmt, Args &&...args)
TextView annotation_glue_text() const
self_type & assign_annotation_glue_text(TextView text, bool final_glue_p=false)
static TextView AUTOTEXT_SEVERITY_CODE
Format for auto generate annotation with error code and severity.
TextView annotation_severity_glue_text() const
static void register_sink(SinkHandler &&f)
Register a sink function for abandonded erratum.
self_type & note_localized(std::string_view const &text, std::optional< Severity > severity=std::optional< Severity >{})
Add Annotation with already localized text.
self_type & note_v(Severity severity, std::string_view fmt, std::tuple< Args... > const &args)
self_type & note_sv(std::optional< Severity > severity, std::string_view fmt, std::tuple< Args... > const &args)
self_type & assign_annotation_severity_glue_text(TextView text)
iterator end()
Reference one past bottom item on the stack.
self_type & note(std::string_view fmt, Args &&...args)
self_type & assign_severity_glue_text(TextView text)
TextView indent_text() const
code_type const & code() const
The code for the top message.
static void register_sink(Sink::Handle const &s)
Register a sink for discarded erratum.
IntrusiveDList< Annotation::Linkage > Container
bool has_severity() const
static Annotation const NIL_NOTE
Used for returns when no data is present.
self_type & assign(Severity severity)
std::error_code code_type
Type for message code.
static TextView AUTOTEXT_SEVERITY
Format for auto generated annotation with severity.
Errata(self_type const &that)=delete
No copy construction.
static Severity DEFAULT_SEVERITY
Severity reported if severity not set.
static const code_type DEFAULT_CODE
Code used if not specified.
iterator begin()
Reference to top item on the stack.
static TextView AUTOTEXT_CODE
Format for auto generated annotation with error code.
static MemSpan< TextView const > SEVERITY_NAMES
self_type & note_v(std::string_view fmt, std::tuple< Args... > const &args)
self_type & note_s(std::optional< Severity > severity, std::string_view text)
static Severity FILTER_SEVERITY
self_type & update(Severity severity)
std::function< void(Errata const &)> SinkHandler
Register a function as a sink.
static void register_sink(SinkHandler const &f)
Register a sink function for abandonded erratum.
MemSpan< char > alloc(size_t n)
const Annotation & front() const
Errata()=default
Default constructor - empty errata, very fast.
uint8_t severity_type
Underlying type for Severity.
static TextView DEFAULT_SEVERITY_GLUE_TEXT
Default glue text for use after the severity name.
Severity severity() const
self_type & assign(result_type const &result)
result_type & operator=(result_type const &r)
self_type & note(std::string_view fmt, Args &&...args)
self_type & clear()
Clear the errata.
Rv self_type
Standard self reference type.
self_type & note(std::string_view text)
self_type & note(Severity severity, std::string_view fmt, Args &&...args)
R result_type
Type of result value.
result_type _r
The result.
Errata _errata
The errata.
For template deduction guides.
BufferWriter & bwformat(BufferWriter &w, bwf::Spec const &spec, std::string_view sv)
Rv< typename std::remove_reference< R >::type > MakeRv(R &&r, Errata &&erratum)
code_type _code
Message code / ID.
bool empty() const
Check if there are any notes.
std::optional< Severity > _severity
Severity.
swoc::MemSpan< char > alloc(size_t n)
Allocate from the arena.
swoc::MemArena _arena
Annotation text storage.
Data(swoc::MemArena &&arena)
bool _glue_final_p
Add glue after the last annotation?
swoc::MemSpan< char > remnant()
Get the remnant of the current block in the arena.
Data self_type
Self reference type.
Container _notes
The message stack.
std::string_view localize(std::string_view src)
constexpr Severity(severity_type n)
No implicit conversion from numeric.
severity_type _raw
Severity numeric value.
Convenience wrapper class to enable using functions directly for sinks.
SinkWrapper(SinkHandler const &f)
Constructor.
void operator()(Errata const &e) const override
Operator to invoke the function.
SinkHandler _f
Client supplied handler.