2018-03-05 17:49:29 +01:00
|
|
|
#include "./diagnostics.h"
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
2018-03-06 23:09:15 +01:00
|
|
|
namespace TagParser {
|
2018-03-05 17:49:29 +01:00
|
|
|
|
2018-06-03 20:32:15 +02:00
|
|
|
/*!
|
|
|
|
* \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.
|
|
|
|
*/
|
2021-01-30 21:53:06 +01:00
|
|
|
std::string_view diagLevelName(DiagLevel diagLevel)
|
2018-03-05 17:49:29 +01:00
|
|
|
{
|
2018-03-07 01:17:50 +01:00
|
|
|
switch (diagLevel) {
|
2018-03-05 17:49:29 +01:00
|
|
|
case DiagLevel::Information:
|
|
|
|
return "information";
|
|
|
|
case DiagLevel::Warning:
|
|
|
|
return "warning";
|
|
|
|
case DiagLevel::Critical:
|
|
|
|
return "critical";
|
2020-12-01 01:51:27 +01:00
|
|
|
case DiagLevel::Debug:
|
|
|
|
return "debug";
|
2018-03-05 17:49:29 +01:00
|
|
|
case DiagLevel::None:
|
|
|
|
default:
|
2021-01-30 21:53:06 +01:00
|
|
|
return std::string_view();
|
2018-03-05 17:49:29 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-06-03 20:32:15 +02:00
|
|
|
/*!
|
|
|
|
* \brief Returns whether there's at least one DiagMessage which is at least as worse as \a level.
|
|
|
|
*/
|
2018-03-05 17:49:29 +01:00
|
|
|
bool Diagnostics::has(DiagLevel level) const
|
|
|
|
{
|
|
|
|
for (const auto &msg : *this) {
|
|
|
|
if (msg.level() >= level) {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2018-06-03 20:32:15 +02:00
|
|
|
/*!
|
|
|
|
* \brief Returns the worst diag level present in the container.
|
|
|
|
*/
|
2018-03-05 17:49:29 +01:00
|
|
|
DiagLevel Diagnostics::level() const
|
|
|
|
{
|
|
|
|
auto level = DiagLevel::None;
|
|
|
|
for (const auto &msg : *this) {
|
|
|
|
if ((level |= msg.level()) >= worstDiagLevel) {
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return level;
|
|
|
|
}
|
|
|
|
|
2018-07-01 22:11:34 +02:00
|
|
|
/*!
|
|
|
|
* \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;
|
|
|
|
}
|
|
|
|
|
2018-03-07 01:17:50 +01:00
|
|
|
} // namespace TagParser
|