Tag Parser  10.0.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
diagnostics.h
Go to the documentation of this file.
1 #ifndef TAGPARSER_DIAGNOSTICS_H
2 #define TAGPARSER_DIAGNOSTICS_H
3 
4 #include "./global.h"
5 
6 #include <c++utilities/chrono/datetime.h>
7 
8 #include <string>
9 #include <vector>
10 
11 namespace TagParser {
12 
16 enum class DiagLevel {
17  None = 0,
18  Debug = 1,
19  Information = 2,
20  Warning = 3,
21  Critical = 4,
22  Fatal = 5,
23 };
24 
27 
28 TAG_PARSER_EXPORT std::string_view diagLevelName(DiagLevel diagLevel);
29 
33 constexpr DiagLevel &operator|=(DiagLevel &lhs, const DiagLevel &rhs)
34 {
35  if (lhs < rhs) {
36  lhs = rhs;
37  }
38  return lhs;
39 }
40 
41 class DiagMessage {
42 public:
43  DiagMessage(DiagLevel level, const std::string &message, const std::string &context);
44  DiagMessage(DiagLevel level, std::string &&message, const std::string &context);
45  DiagMessage(DiagLevel level, const std::string &message, std::string &&context);
46  DiagMessage(DiagLevel level, std::string &&message, std::string &&context);
47 
48  DiagLevel level() const;
49  std::string_view levelName() const;
50  const std::string &message() const;
51  const std::string &context() const;
52  const CppUtilities::DateTime &creationTime() const;
53  bool operator==(const DiagMessage &other) const;
54 
55  static std::string formatList(const std::vector<std::string> &values);
56 
57 private:
58  DiagLevel m_level;
59  std::string m_message;
60  std::string m_context;
61  CppUtilities::DateTime m_creationTime;
62 };
63 
67 inline DiagMessage::DiagMessage(DiagLevel level, const std::string &message, const std::string &context)
68  : m_level(level)
69  , m_message(message)
70  , m_context(context)
71  , m_creationTime(CppUtilities::DateTime::gmtNow())
72 {
73 }
74 
78 inline DiagMessage::DiagMessage(DiagLevel level, std::string &&message, const std::string &context)
79  : m_level(level)
80  , m_message(message)
81  , m_context(context)
82  , m_creationTime(CppUtilities::DateTime::gmtNow())
83 {
84 }
85 
89 inline DiagMessage::DiagMessage(DiagLevel level, const std::string &message, std::string &&context)
90  : m_level(level)
91  , m_message(message)
92  , m_context(context)
93  , m_creationTime(CppUtilities::DateTime::gmtNow())
94 {
95 }
96 
100 inline DiagMessage::DiagMessage(DiagLevel level, std::string &&message, std::string &&context)
101  : m_level(level)
102  , m_message(message)
103  , m_context(context)
104  , m_creationTime(CppUtilities::DateTime::gmtNow())
105 {
106 }
107 
112 {
113  return m_level;
114 }
115 
119 inline std::string_view DiagMessage::levelName() const
120 {
121  return diagLevelName(m_level);
122 }
123 
127 inline const std::string &DiagMessage::message() const
128 {
129  return m_message;
130 }
131 
135 inline const std::string &DiagMessage::context() const
136 {
137  return m_context;
138 }
139 
143 inline const CppUtilities::DateTime &DiagMessage::creationTime() const
144 {
145  return m_creationTime;
146 }
147 
151 inline bool DiagMessage::operator==(const DiagMessage &other) const
152 {
153  return m_level == other.m_level && m_message == other.m_message && m_context == other.m_context;
154 }
155 
156 class TAG_PARSER_EXPORT Diagnostics : public std::vector<DiagMessage> {
157 public:
158  Diagnostics() = default;
159  Diagnostics(std::initializer_list<DiagMessage> list);
160 
161  bool has(DiagLevel level) const;
162  DiagLevel level() const;
163 };
164 
168 inline Diagnostics::Diagnostics(std::initializer_list<DiagMessage> list)
169  : std::vector<DiagMessage>(list)
170 {
171 }
172 
173 } // namespace TagParser
174 
175 #endif // TAGPARSER_DIAGNOSTICS_H
The DiagMessage class holds an information, warning or error gathered during parsing or making.
Definition: diagnostics.h:41
std::string_view levelName() const
Returns the string representation of the level().
Definition: diagnostics.h:119
DiagMessage(DiagLevel level, const std::string &message, const std::string &context)
Constructs a new DiagMessage.
Definition: diagnostics.h:67
static std::string formatList(const std::vector< std::string > &values)
Concatenates the specified string values to a list.
Definition: diagnostics.cpp:69
DiagLevel level() const
Returns the level.
Definition: diagnostics.h:111
bool operator==(const DiagMessage &other) const
Returns whether the current instance equals other.
Definition: diagnostics.h:151
const CppUtilities::DateTime & creationTime() const
Returns the creation time (using GMT timezone).
Definition: diagnostics.h:143
const std::string & context() const
Returns the context.
Definition: diagnostics.h:135
const std::string & message() const
Returns the message.
Definition: diagnostics.h:127
The Diagnostics class is a container for DiagMessage.
Definition: diagnostics.h:156
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
constexpr DiagLevel & operator|=(DiagLevel &lhs, const DiagLevel &rhs)
Sets lhs to rhs if rhs is more critical than lhs and returns lhs.
Definition: diagnostics.h:33
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