LibSWOC++ 1.5.14
Solid Wall of C++
Loading...
Searching...
No Matches
Errata.h
Go to the documentation of this file.
1// SPDX-License-Identifier: Apache-2.0
2// Copyright Network Geographics 2014
37
38#pragma once
39
40#include <vector>
41#include <string_view>
42#include <functional>
43#include <atomic>
44#include <optional>
45
46#include "swoc/swoc_version.h"
47#include "swoc/MemSpan.h"
48#include "swoc/MemArena.h"
49#include "swoc/bwf_base.h"
50#include "swoc/bwf_std.h"
51#include "swoc/IntrusiveDList.h"
52
53namespace swoc { inline namespace SWOC_VERSION_NS {
54
59class Errata {
60public:
61 using code_type = std::error_code;
62 using severity_type = uint8_t;
63
67 struct Severity {
69
70 explicit constexpr Severity(severity_type n) : _raw(n) {}
71
72 Severity(Severity const &that) = default;
73 Severity &operator=(Severity const &that) = default;
74
75 operator severity_type() const { return _raw; }
76 };
77
79 static inline const code_type DEFAULT_CODE;
88
89 static inline TextView AUTOTEXT_SEVERITY = "{}";
90 static inline TextView AUTOTEXT_CODE = "{}";
91 static inline TextView AUTOTEXT_SEVERITY_CODE = "{}: {}";
92
97
103 using self_type = Annotation;
104
105 public:
107 self_type &clear();
108
110 swoc::TextView text() const;
111
113 unsigned short level() const;
114
116 bool has_severity() const;
117
120 Severity severity(Severity default_severity = DEFAULT_SEVERITY) const;
121
123 self_type &assign(Severity severity);
124
125 protected:
126 std::string_view _text;
127 unsigned short _level{0};
128 std::optional<Severity> _severity;
129
132 self_type *_next{nullptr};
133 self_type *_prev{nullptr};
139 using Linkage = swoc::IntrusiveLinkage<self_type, &self_type::_next, &self_type::_prev>;
140
144
154 explicit Annotation(std::string_view text, std::optional<Severity> severity = std::optional<Severity>{},
155 unsigned short level = 0);
156
157 friend class Errata;
158 friend class swoc::MemArena; // needed for @c MemArena::make
159 };
160
161protected:
165 using Container = IntrusiveDList<Annotation::Linkage>;
166
168 struct Data {
169 using self_type = Data;
170
174 Data(swoc::MemArena &&arena);
175
177 bool empty() const;
178
184 std::string_view localize(std::string_view src);
185
188
190 swoc::MemSpan<char> alloc(size_t n);
191
192 TextView _annotation_glue_text = DEFAULT_ANNOTATION_GLUE_TEXT;
193 TextView _annotation_severity_glue_text = DEFAULT_SEVERITY_GLUE_TEXT;
194 TextView _severity_glue_text = DEFAULT_SEVERITY_GLUE_TEXT;
195 TextView _indent_text = DEFAULT_INDENT_TEXT;
196 bool _glue_final_p = true;
197
198 std::optional<Severity> _severity;
202 };
203
204public:
206 static constexpr struct AutoText {
207 } AUTO{};
208
210 Errata() = default;
211 Errata(self_type const &that) = delete;
212 Errata(self_type &&that) noexcept;
213 self_type &operator=(self_type const &that) = delete; // no copy assignment.
214 self_type &operator=(self_type &&that);
215 ~Errata();
216
223 explicit Errata(code_type const &ec);
224
232 explicit Errata(code_type const &ec, AutoText);
233
240 explicit Errata(Severity severity);
241
249 explicit Errata(Severity severity, AutoText);
250
258 Errata(code_type const &ec, Severity severity);
259
269 explicit Errata(code_type const &ec, Severity severity, AutoText auto_text);
270
279 Errata(code_type const &code, Severity severity, std::string_view const &text);
280
288 Errata(Severity severity, std::string_view const &text);
289
297 Errata(code_type const &code, std::string_view const &text);
298
303 explicit Errata(std::string_view const &text);
304
315 template <typename... Args> Errata(code_type const &code, Severity severity, std::string_view fmt, Args &&...args);
316
317 template <typename... Args> Errata(code_type const &type, std::string_view fmt, Args &&...args);
318 template <typename... Args> Errata(Severity severity, std::string_view fmt, Args &&...args);
319 template <typename... Args> explicit Errata(std::string_view fmt, Args &&...args);
320
328 self_type &note(std::string_view text);
329
338 self_type &note(Severity severity, std::string_view text);
339
348
358 self_type &note(code_type const &ec);
359
369
382 self_type &note_s(std::optional<Severity> severity, std::string_view text);
383
390 template <typename... Args> self_type &note(std::string_view fmt, Args &&...args);
391
400 template <typename... Args> self_type &note_v(std::string_view fmt, std::tuple<Args...> const &args);
401
410 template <typename... Args> self_type &note(Severity severity, std::string_view fmt, Args &&...args);
411
423 template <typename... Args> self_type &note_v(Severity severity, std::string_view fmt, std::tuple<Args...> const &args);
424
435 template <typename... Args>
436 self_type &note_sv(std::optional<Severity> severity, std::string_view fmt, std::tuple<Args...> const &args);
437
445 self_type &note(self_type const &that);
446
454 self_type &note(self_type &&that);
455
462 self_type &clear();
463
473 self_type &sink();
474
475 friend std::ostream &operator<<(std::ostream &, self_type const &);
476
481 // Text used for each level of indent.
482 static inline TextView DEFAULT_INDENT_TEXT = " ";
483
492
493 explicit operator bool() const;
494
502 bool operator!() const;
503
511 bool is_ok() const;
512
514 bool has_severity() const;
515
517 Severity severity() const;
518
527
538
540 code_type const &code() const;
541
544
546 size_t length() const;
547
550 bool empty() const;
551
552 using iterator = Container::iterator;
553 using const_iterator = Container::const_iterator;
554
556 iterator begin();
558 const_iterator begin() const;
560 iterator end();
562 const_iterator end() const;
563
570 const Annotation &front() const;
571
578 const Annotation &back() const;
579
580 // Logging support.
581
584
591 self_type &assign_annotation_glue_text(TextView text, bool final_glue_p = false);
592
595
602
605
612
614 TextView indent_text() const;
615
622
630 class Sink {
631 using self_type = Sink;
632
633 public:
634 using Handle = std::shared_ptr<self_type>;
635
637 virtual void operator()(Errata const &) const = 0;
639 virtual ~Sink() {}
640 };
641
643 static void register_sink(Sink::Handle const &s);
644
646 using SinkHandler = std::function<void(Errata const &)>;
647
649 struct SinkWrapper : public Sink {
651 SinkWrapper(SinkHandler const &f) : _f(f) {}
652 SinkWrapper(SinkHandler &&f) : _f(std::move(f)) {}
654 void operator()(Errata const &e) const override;
656 };
657
659 static void
663
665 static void
667 register_sink(Sink::Handle(new SinkWrapper(std::move(f))));
668 }
669
672 std::ostream &write(std::ostream &out) const;
673
674protected:
679 Data *_data = nullptr;
680
683 Data *data();
684
690 MemSpan<char> alloc(size_t n);
691
693 self_type &note_localized(std::string_view const &text, std::optional<Severity> severity = std::optional<Severity>{});
694
696 static Annotation const NIL_NOTE;
697
698 friend struct Data;
699 friend class Item;
700 friend BufferWriter &bwformat(BufferWriter &bw, bwf::Spec const &, Errata const &errata);
701};
702
703extern std::ostream &operator<<(std::ostream &os, Errata const &stat);
704
711template <typename R> class Rv {
712public:
713 using result_type = R;
714 using code_type = Errata::code_type;
715 using Severity = Errata::Severity;
716
717protected:
718 using self_type = Rv;
719
722
723public:
728 Rv();
729
734 Rv(result_type const &result);
735
741 Rv(result_type const &result, Errata &&errata);
742
748
755
774 Rv(Errata &&errata);
775
781 self_type &note(std::string_view text);
782
789 self_type &note(Severity severity, std::string_view text);
790
798 self_type &note(code_type const &code);
799
808 self_type &note(code_type const &code, Severity severity);
809
817 template <typename... Args> self_type &note(std::string_view fmt, Args &&...args);
818
827 template <typename... Args> self_type &note(Severity severity, std::string_view fmt, Args &&...args);
828
836 self_type &note(Errata const &that);
837
845 self_type &note(Errata &&that);
846
852 operator result_type const &() const;
853
875
882
903
910
915
919 result_type const &result() const;
920
924 Errata &errata();
925
929 Errata const &errata() const;
930
935 operator Errata &();
936
944 self_type &operator=(Errata &&status);
945
950 bool is_ok() const;
951
953 self_type &clear();
954};
955
960template <typename R>
962MakeRv(R &&r,
963 Errata &&erratum
964) {
965 return Rv<typename std::remove_reference<R>::type>(std::forward<R>(r), std::move(erratum));
966}
967/* ----------------------------------------------------------------------- */
968// Inline methods for Annotation
969
970inline Errata::Annotation::Annotation() = default;
971
972inline Errata::Annotation::Annotation(std::string_view text, std::optional<Severity> severity, unsigned short level)
974
975inline Errata::Annotation &
977 _text = std::string_view{};
978 return *this;
979}
980
981inline swoc::TextView
983 return _text;
984}
985
986inline unsigned short
988 return _level;
989}
990
991inline bool
993 return _severity.has_value();
994}
995inline auto
997 return _severity.value_or(default_severity);
998}
999inline auto
1002 return *this;
1003}
1004
1005/* ----------------------------------------------------------------------- */
1006// Inline methods for Errata::Data
1007
1009 _arena = std::move(arena);
1010}
1011
1014 return _arena.remnant().rebind<char>();
1015}
1016
1019 return _arena.alloc(n).rebind<char>();
1020}
1021
1022inline bool
1024 return _notes.empty();
1025}
1026
1027/* ----------------------------------------------------------------------- */
1028// Inline methods for Errata
1029
1030inline Errata::Errata(self_type &&that) noexcept {
1031 std::swap(_data, that._data);
1032}
1033
1034inline Errata::Errata(code_type const &ec) {
1035 this->data()->_code = ec;
1036}
1037
1039 this->data()->_severity = severity;
1040}
1041
1043 auto d = this->data();
1044 d->_severity = severity;
1045 d->_code = ec;
1046}
1047
1048inline Errata::Errata(code_type const &ec, AutoText) {
1049 this->data()->_code = ec;
1050 this->note(AUTOTEXT_CODE, ec);
1051}
1052
1054 this->data()->_severity = severity;
1055 this->note(AUTOTEXT_SEVERITY, severity);
1056}
1057
1058inline Errata::Errata(const code_type &ec, Severity severity, AutoText) : Errata(ec, severity) {
1059 this->note(AUTOTEXT_SEVERITY_CODE, severity, ec);
1060}
1061
1062inline Errata::Errata(const code_type &code, Severity severity, const std::string_view &text) : Errata(code, severity) {
1063 this->note(text);
1064}
1065
1066inline Errata::Errata(const std::string_view &text) : Errata(DEFAULT_CODE, DEFAULT_SEVERITY, text) {}
1067inline Errata::Errata(code_type const &code, const std::string_view &text) : Errata(code, DEFAULT_SEVERITY, text) {}
1068inline Errata::Errata(Severity severity, const std::string_view &text) : Errata(DEFAULT_CODE, severity, text) {}
1069
1070template <typename... Args>
1071Errata::Errata(code_type const &code, Severity severity, std::string_view fmt, Args &&...args) : Errata(code, severity) {
1072 this->note_v(fmt, std::forward_as_tuple(args...));
1073}
1074
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)...) {}
1083
1084inline Errata &
1086 if (_data) {
1087 _data->~Data(); // destructs the @c MemArena in @a _data which releases memory.
1088 _data = nullptr;
1089 }
1090 return *this;
1091}
1092
1093inline auto
1094Errata::operator=(self_type &&that) -> self_type & {
1095 if (this != &that) {
1096 this->clear();
1097 std::swap(_data, that._data);
1098 }
1099 return *this;
1100}
1101
1102inline Errata::operator bool() const {
1103 return this->is_ok();
1104}
1105
1106inline bool
1108 return !this->is_ok();
1109}
1110
1111inline bool
1113 return _data == nullptr || _data->_notes.count() == 0;
1114}
1115
1116inline auto
1117Errata::code() const -> code_type const & {
1118 return this->empty() ? DEFAULT_CODE : _data->_code;
1119}
1120
1121inline auto
1123 this->data()->_code = code;
1124 return *this;
1125}
1126
1127inline bool
1129 return _data && _data->_severity.has_value();
1130}
1131inline auto
1133 return this->has_severity() ? _data->_severity.value() : DEFAULT_SEVERITY;
1134}
1135
1136inline auto
1138 this->data()->_severity = severity;
1139 return *this;
1140}
1141
1142inline size_t
1144 return _data ? _data->_notes.count() : 0;
1145}
1146
1147inline bool
1149 return nullptr == _data || this->severity() < FAILURE_SEVERITY;
1150}
1151
1152inline const Errata::Annotation &
1154 return *(_data->_notes.head());
1155}
1156
1157inline const Errata::Annotation &
1159 return *(_data->_notes.tail());
1160}
1161
1162inline Errata &
1164 this->note(that); // no longer an rvalue reference, so no recursion.
1165 that.clear();
1166 return *this;
1167}
1168
1169inline Errata &
1170Errata::note(std::string_view text) {
1171 return this->note_s({}, text);
1172}
1173
1174inline Errata &
1175Errata::note(Severity severity, std::string_view text) {
1176 return this->note_s(severity, text);
1177}
1178
1179inline Errata &
1181 return this->note(severity, AUTOTEXT_SEVERITY, severity);
1182}
1183
1184inline Errata &
1186 return this->note(AUTOTEXT_CODE, code);
1187}
1188
1189inline Errata &
1191 return this->note(severity, AUTOTEXT_SEVERITY_CODE, severity, ec);
1192}
1193
1194template <typename... Args>
1195Errata &
1196Errata::note_sv(std::optional<Severity> severity, std::string_view fmt, std::tuple<Args...> const &args) {
1197 if (severity.has_value()) {
1198 this->update(*severity);
1199 }
1200
1201 if (!severity.has_value() || *severity >= FILTER_SEVERITY) {
1202 Data *data = this->data();
1203 auto span = data->remnant();
1204 FixedBufferWriter bw{span};
1205 if (!bw.print_v(fmt, args).error()) {
1206 span = span.prefix(bw.extent());
1207 data->alloc(bw.extent()); // require the part of the remnant actually used.
1208 } else {
1209 // Not enough space, get a big enough chunk and do it again.
1210 span = this->alloc(bw.extent());
1211 FixedBufferWriter{span}.print_v(fmt, args);
1212 }
1213 this->note_localized(TextView(span), severity);
1214 }
1215 return *this;
1216}
1217
1218template <typename... Args>
1219Errata &
1220Errata::note_v(std::string_view fmt, std::tuple<Args...> const &args) {
1221 return this->note_sv({}, fmt, args);
1222}
1223
1224template <typename... Args>
1225Errata &
1226Errata::note_v(Severity severity, std::string_view fmt, std::tuple<Args...> const &args) {
1227 return this->note_sv(severity, fmt, args);
1228}
1229
1230template <typename... Args>
1231Errata &
1232Errata::note(std::string_view fmt, Args &&...args) {
1233 return this->note_sv({}, fmt, std::forward_as_tuple(args...));
1234}
1235
1236template <typename... Args>
1237Errata &
1238Errata::note(Severity severity, std::string_view fmt, Args &&...args) {
1239 return this->note_sv(severity, fmt, std::forward_as_tuple(args...));
1240}
1241
1242inline Errata::iterator
1244 return _data ? _data->_notes.begin() : iterator();
1245}
1246
1247inline Errata::const_iterator
1249 return _data ? _data->_notes.begin() : const_iterator();
1250}
1251
1252inline Errata::iterator
1254 return _data ? _data->_notes.end() : iterator();
1255}
1256
1257inline Errata::const_iterator
1259 return _data ? _data->_notes.end() : const_iterator();
1260}
1261
1262inline TextView
1264 return _data ? _data->_annotation_glue_text : DEFAULT_ANNOTATION_GLUE_TEXT;
1265}
1266
1267inline auto
1269 this->data()->_annotation_glue_text = this->data()->localize(text);
1270 this->data()->_glue_final_p = final_glue_p;
1271 return *this;
1272}
1273
1274inline TextView
1276 return _data ? _data->_annotation_severity_glue_text : DEFAULT_SEVERITY_GLUE_TEXT;
1277}
1278
1279inline auto
1281 this->data()->_annotation_severity_glue_text = this->data()->localize(text);
1282 return *this;
1283}
1284
1285inline TextView
1287 return _data ? _data->_severity_glue_text : DEFAULT_SEVERITY_GLUE_TEXT;
1288}
1289
1290inline auto
1292 this->data()->_severity_glue_text = this->data()->localize(text);
1293 return *this;
1294}
1295
1296inline TextView
1298 return _data ? _data->_indent_text : DEFAULT_INDENT_TEXT;
1299}
1300
1301inline auto
1303 this->data()->_indent_text = this->data()->localize(text);
1304 return *this;
1305}
1306
1307inline void
1309 _f(e);
1310}
1311/* ----------------------------------------------------------------------- */
1312// Inline methods for Rv
1313
1314template <typename R>
1315inline auto
1316Rv<R>::note(std::string_view text) -> self_type & {
1317 _errata.note(text);
1318 return *this;
1319}
1320
1321template <typename R>
1322inline auto
1323Rv<R>::note(Severity severity, std::string_view text) -> self_type & {
1324 _errata.note(severity, text);
1325 return *this;
1326}
1327
1328template <typename R>
1329auto
1330Rv<R>::note(const code_type &code) -> self_type & {
1331 _errata.note(code);
1332 return *this;
1333}
1334
1335template <typename R>
1336auto
1337Rv<R>::note(const code_type &code, Severity severity) -> self_type & {
1338 _errata.note(code, severity);
1339 return *this;
1340}
1341
1342template <typename R>
1343template <typename... Args>
1344auto
1345Rv<R>::note(std::string_view fmt, Args &&...args) -> self_type & {
1346 _errata.note(fmt, std::forward<Args>(args)...);
1347 return *this;
1348}
1349
1350template <typename R>
1351template <typename... Args>
1352auto
1353Rv<R>::note(Severity severity, std::string_view fmt, Args &&...args) -> self_type & {
1354 _errata.note(severity, fmt, std::forward<Args>(args)...);
1355 return *this;
1356}
1357
1358template <typename R>
1359bool
1361 return _errata.is_ok();
1362}
1363
1364template <typename R>
1365auto
1367 errata().clear();
1368 return *this;
1369}
1370
1371template <typename T> Rv<T>::Rv() {}
1372
1373template <typename T> Rv<T>::Rv(result_type const &r) : _r(r) {}
1374
1375template <typename T> Rv<T>::Rv(result_type const &r, Errata &&errata) : _r(r), _errata(std::move(errata)) {}
1376
1377template <typename R> Rv<R>::Rv(R &&r) : _r(std::move(r)) {}
1378
1379template <typename R> Rv<R>::Rv(R &&r, Errata &&errata) : _r(std::move(r)), _errata(std::move(errata)) {}
1380
1381template <typename R> Rv<R>::Rv(Errata &&errata) : _errata{std::move(errata)} {}
1382
1383template <typename T> Rv<T>::operator result_type const &() const {
1384 return _r;
1385}
1386
1387template <typename R>
1388R const &
1390 return _r;
1391}
1392
1393template <typename R>
1394R &
1396 return _r;
1397}
1398
1399template <typename R>
1400Errata const &
1402 return _errata;
1403}
1404
1405template <typename R>
1406Errata &
1408 return _errata;
1409}
1410
1411template <typename R> Rv<R>::operator Errata &() {
1412 return _errata;
1413}
1414
1415template <typename R>
1416Rv<R> &
1418 _r = r;
1419 return *this;
1420}
1421
1422template <typename R>
1423Rv<R> &
1425 _r = std::move(r);
1426 return *this;
1427}
1428
1429template <typename R>
1430auto
1432 _errata = std::move(errata);
1433 return *this;
1434}
1435
1436template <typename R>
1437inline Rv<R> &
1438Rv<R>::note(Errata const &that) {
1439 this->_errata.note(that);
1440 return *this;
1441}
1442
1443template <typename R>
1444inline Rv<R> &
1446 this->_errata.note(std::move(that));
1447 that.clear();
1448 return *this;
1449}
1450
1451template <typename R>
1452auto
1454 _r = r;
1455 return _r;
1456}
1457
1458template <typename R>
1459auto
1461 _r = std::move(r);
1462 return _r;
1463}
1464
1466
1468
1469BufferWriter &bwformat(BufferWriter &w, bwf::Spec const &spec, Errata const &);
1470
1471}} // namespace swoc::SWOC_VERSION_NS
1472
1473// Tuple / structured binding support.
1474namespace std {
1476template <size_t IDX, typename R> class tuple_element<IDX, swoc::Rv<R>> {
1477 static_assert("swoc:Rv tuple index out of range");
1478};
1479
1480template <typename R> class tuple_element<0, swoc::Rv<R>> {
1481public:
1482 using type = typename swoc::Rv<R>::result_type;
1483};
1484
1485template <typename R> class tuple_element<1, swoc::Rv<R>> {
1486public:
1487 using type = swoc::Errata;
1488};
1489
1490template <typename R> class tuple_size<swoc::Rv<R>> : public std::integral_constant<size_t, 2> {};
1492} // namespace std
1493
1494namespace swoc { inline namespace SWOC_VERSION_NS {
1495// Not sure how much of this is needed, but experimentally all of these were needed in one
1496// use case or another of structured binding. I wasn't able to make this work if this was
1497// defined in namespace @c std. Also, because functions can't be partially specialized, it is
1498// necessary to use @c constexpr @c if to handle the cases. This should roll up nicely when
1499// compiled.
1500
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) {
1506 return rv.result();
1507 } else if constexpr (IDX == 1) {
1508 return rv.errata();
1509 }
1510}
1511
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) {
1517 return rv.result();
1518 } else if constexpr (IDX == 1) {
1519 return rv.errata();
1520 }
1521 // Shouldn't need this due to the @c static_assert but the Intel compiler requires it.
1522 throw std::domain_error("Errata index value out of bounds");
1523}
1524
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) {
1530 return rv.result();
1531 } else if constexpr (IDX == 1) {
1532 return rv.errata();
1533 }
1534 // Shouldn't need this due to the @c static_assert but the Intel compiler requires it.
1535 throw std::domain_error("Errata index value out of bounds");
1536}
1538
1539}} // namespace swoc::SWOC_VERSION_NS
Severity severity(Severity default_severity=DEFAULT_SEVERITY) const
Definition Errata.h:996
std::string_view _text
Annotation text.
Definition Errata.h:126
swoc::TextView text() const
Get the text of the message.
Definition Errata.h:982
std::optional< Severity > _severity
Severity.
Definition Errata.h:128
bool has_severity() const
Check if this has a Severity.
Definition Errata.h:992
self_type & clear()
Reset to the message to default state.
Definition Errata.h:976
unsigned short _level
Nesting level for display purposes.
Definition Errata.h:127
unsigned short level() const
Get the nesting level.
Definition Errata.h:987
swoc::IntrusiveLinkage< self_type, &self_type::_next, &self_type::_prev > Linkage
Definition Errata.h:139
self_type & assign(Severity severity)
Set the severity of this.
Definition Errata.h:1000
virtual void operator()(Errata const &) const =0
Handle an abandoned errata.
std::shared_ptr< self_type > Handle
Handle type.
Definition Errata.h:634
virtual ~Sink()
Force virtual destructor.
Definition Errata.h:639
bool operator!() const
Definition Errata.h:1107
static Severity FAILURE_SEVERITY
Severity level at which the instance is a failure of some sort.
Definition Errata.h:83
TextView severity_glue_text() const
Definition Errata.h:1286
const Annotation & back() const
Definition Errata.h:1158
self_type & assign_indent_text(TextView text)
Definition Errata.h:1302
static TextView DEFAULT_ANNOTATION_GLUE_TEXT
Default glue value (a newline) for text rendering.
Definition Errata.h:478
self_type & sink()
Definition Errata.cc:54
bool empty() const
Definition Errata.h:1112
self_type & note(std::string_view text)
Definition Errata.h:1170
self_type & clear()
Definition Errata.h:1085
size_t length() const
Number of messages in the errata.
Definition Errata.h:1143
self_type & note(Severity severity, std::string_view fmt, Args &&...args)
TextView annotation_glue_text() const
Definition Errata.h:1263
self_type & assign_annotation_glue_text(TextView text, bool final_glue_p=false)
Definition Errata.h:1268
static TextView AUTOTEXT_SEVERITY_CODE
Format for auto generate annotation with error code and severity.
Definition Errata.h:91
TextView annotation_severity_glue_text() const
Definition Errata.h:1275
static void register_sink(SinkHandler &&f)
Register a sink function for abandonded erratum.
Definition Errata.h:666
self_type & note_localized(std::string_view const &text, std::optional< Severity > severity=std::optional< Severity >{})
Add Annotation with already localized text.
Definition Errata.cc:92
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)
Definition Errata.h:1280
iterator end()
Reference one past bottom item on the stack.
Definition Errata.h:1253
self_type & note(std::string_view fmt, Args &&...args)
self_type & assign_severity_glue_text(TextView text)
Definition Errata.h:1291
TextView indent_text() const
Definition Errata.h:1297
bool is_ok() const
Definition Errata.h:1148
code_type const & code() const
The code for the top message.
Definition Errata.h:1117
static void register_sink(Sink::Handle const &s)
Register a sink for discarded erratum.
Definition Errata.cc:122
IntrusiveDList< Annotation::Linkage > Container
Definition Errata.h:165
bool has_severity() const
Definition Errata.h:1128
static Annotation const NIL_NOTE
Used for returns when no data is present.
Definition Errata.h:696
self_type & assign(Severity severity)
Definition Errata.h:1137
Data * _data
Definition Errata.h:679
std::error_code code_type
Type for message code.
Definition Errata.h:61
static TextView AUTOTEXT_SEVERITY
Format for auto generated annotation with severity.
Definition Errata.h:89
Errata(self_type const &that)=delete
No copy construction.
static Severity DEFAULT_SEVERITY
Severity reported if severity not set.
Definition Errata.h:81
static const code_type DEFAULT_CODE
Code used if not specified.
Definition Errata.h:79
iterator begin()
Reference to top item on the stack.
Definition Errata.h:1243
static TextView AUTOTEXT_CODE
Format for auto generated annotation with error code.
Definition Errata.h:90
static MemSpan< TextView const > SEVERITY_NAMES
Definition Errata.h:96
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)
Definition Errata.cc:79
Data * data()
Definition Errata.cc:65
static Severity FILTER_SEVERITY
Definition Errata.h:87
self_type & update(Severity severity)
Definition Errata.cc:114
std::function< void(Errata const &)> SinkHandler
Register a function as a sink.
Definition Errata.h:646
static void register_sink(SinkHandler const &f)
Register a sink function for abandonded erratum.
Definition Errata.h:660
MemSpan< char > alloc(size_t n)
Definition Errata.cc:74
const Annotation & front() const
Definition Errata.h:1153
Errata()=default
Default constructor - empty errata, very fast.
uint8_t severity_type
Underlying type for Severity.
Definition Errata.h:62
Errata self_type
Definition Errata.h:162
static TextView DEFAULT_SEVERITY_GLUE_TEXT
Default glue text for use after the severity name.
Definition Errata.h:480
Severity severity() const
Definition Errata.h:1132
self_type & assign(result_type const &result)
Definition Errata.h:1417
result_type & operator=(result_type const &r)
Definition Errata.h:1453
self_type & note(std::string_view fmt, Args &&...args)
result_type & result()
Definition Errata.h:1395
self_type & clear()
Clear the errata.
Definition Errata.h:1366
Rv self_type
Standard self reference type.
Definition Errata.h:718
self_type & note(std::string_view text)
Definition Errata.h:1316
self_type & note(Severity severity, std::string_view fmt, Args &&...args)
R result_type
Type of result value.
Definition Errata.h:713
result_type _r
The result.
Definition Errata.h:720
Errata _errata
The errata.
Definition Errata.h:721
Errata & errata()
Definition Errata.h:1407
bool is_ok() const
Definition Errata.h:1360
STL namespace.
For template deduction guides.
Definition ArenaWriter.cc:9
BufferWriter & bwformat(BufferWriter &w, bwf::Spec const &spec, std::string_view sv)
Definition bw_format.cc:649
Rv< typename std::remove_reference< R >::type > MakeRv(R &&r, Errata &&erratum)
Definition Errata.h:962
Implementation class.
Definition Errata.h:168
code_type _code
Message code / ID.
Definition Errata.h:199
bool empty() const
Check if there are any notes.
Definition Errata.h:1023
std::optional< Severity > _severity
Severity.
Definition Errata.h:198
swoc::MemSpan< char > alloc(size_t n)
Allocate from the arena.
Definition Errata.h:1018
swoc::MemArena _arena
Annotation text storage.
Definition Errata.h:201
Data(swoc::MemArena &&arena)
Definition Errata.h:1008
bool _glue_final_p
Add glue after the last annotation?
Definition Errata.h:196
swoc::MemSpan< char > remnant()
Get the remnant of the current block in the arena.
Definition Errata.h:1013
Data self_type
Self reference type.
Definition Errata.h:169
Container _notes
The message stack.
Definition Errata.h:200
std::string_view localize(std::string_view src)
Definition Errata.cc:29
constexpr Severity(severity_type n)
No implicit conversion from numeric.
Definition Errata.h:70
severity_type _raw
Severity numeric value.
Definition Errata.h:68
Convenience wrapper class to enable using functions directly for sinks.
Definition Errata.h:649
SinkWrapper(SinkHandler const &f)
Constructor.
Definition Errata.h:651
void operator()(Errata const &e) const override
Operator to invoke the function.
Definition Errata.h:1308
SinkHandler _f
Client supplied handler.
Definition Errata.h:655