-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathdiagnostics.cpp
90 lines (81 loc) · 2.12 KB
/
diagnostics.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include "./diagnostics.h"
using namespace std;
namespace TagParser {
/*!
* \class DiagMessage
* \brief The DiagMessage class holds an information, warning or error gathered during parsing or making.
*/
/*!
* \class Diagnostics
* \brief The Diagnostics class is a container for DiagMessage.
* \remarks A lot of methods in this library take such a container as argument. The method will add additional
* information, warnings or errors to it.
*/
/*!
* \brief Returns the string representation of the specified \a diagLevel.
*/
std::string_view diagLevelName(DiagLevel diagLevel)
{
switch (diagLevel) {
case DiagLevel::Information:
return "information";
case DiagLevel::Warning:
return "warning";
case DiagLevel::Critical:
return "critical";
case DiagLevel::Debug:
return "debug";
case DiagLevel::None:
default:
return std::string_view();
}
}
/*!
* \brief Returns whether there's at least one DiagMessage which is at least as worse as \a level.
*/
bool Diagnostics::has(DiagLevel level) const
{
for (const auto &msg : *this) {
if (msg.level() >= level) {
return true;
}
}
return false;
}
/*!
* \brief Returns the worst diag level present in the container.
*/
DiagLevel Diagnostics::level() const
{
auto level = DiagLevel::None;
for (const auto &msg : *this) {
if ((level |= msg.level()) >= worstDiagLevel) {
return level;
}
}
return level;
}
/*!
* \brief Concatenates the specified string \a values to a list.
*/
string DiagMessage::formatList(const std::vector<string> &values)
{
auto size = values.size() * 4;
for (const auto &str : values) {
size += str.size();
}
std::string res;
res.reserve(size);
for (auto value = values.cbegin(), end = values.cend(), last = values.cend() - 1; value != end; ++value) {
if (value == last) {
res += " and ";
} else if (!res.empty()) {
res += ", ";
}
res += '\"';
res += *value;
res += '\"';
}
return res;
}
} // namespace TagParser