Tag Parser  10.0.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
diagnostics.cpp
Go to the documentation of this file.
1 #include "./diagnostics.h"
2 
3 using namespace std;
4 
5 namespace TagParser {
6 
22 std::string_view diagLevelName(DiagLevel diagLevel)
23 {
24  switch (diagLevel) {
25  case DiagLevel::Information:
26  return "information";
27  case DiagLevel::Warning:
28  return "warning";
29  case DiagLevel::Critical:
30  return "critical";
31  case DiagLevel::Debug:
32  return "debug";
33  case DiagLevel::None:
34  default:
35  return std::string_view();
36  }
37 }
38 
42 bool Diagnostics::has(DiagLevel level) const
43 {
44  for (const auto &msg : *this) {
45  if (msg.level() >= level) {
46  return true;
47  }
48  }
49  return false;
50 }
51 
55 DiagLevel Diagnostics::level() const
56 {
57  auto level = DiagLevel::None;
58  for (const auto &msg : *this) {
59  if ((level |= msg.level()) >= worstDiagLevel) {
60  return level;
61  }
62  }
63  return level;
64 }
65 
69 string DiagMessage::formatList(const std::vector<string> &values)
70 {
71  auto size = values.size() * 4;
72  for (const auto &str : values) {
73  size += str.size();
74  }
75  std::string res;
76  res.reserve(size);
77  for (auto value = values.cbegin(), end = values.cend(), last = values.cend() - 1; value != end; ++value) {
78  if (value == last) {
79  res += " and ";
80  } else if (!res.empty()) {
81  res += ", ";
82  }
83  res += '\"';
84  res += *value;
85  res += '\"';
86  }
87  return res;
88 }
89 
90 } // namespace TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TAG_PARSER_EXPORT std::string_view diagLevelName(DiagLevel diagLevel)
Returns the string representation of the specified diagLevel.
Definition: diagnostics.cpp:22
DiagLevel
Specifies the level of the diagnostic message.
Definition: diagnostics.h:16
constexpr auto worstDiagLevel
The worst diag level.
Definition: diagnostics.h:26