Tag Parser 12.5.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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
11namespace TagParser {
12
16enum class DiagLevel {
17 None = 0,
18 Debug = 1,
20 Warning = 3,
22 Fatal = 5,
23};
24
27
28TAG_PARSER_EXPORT std::string_view diagLevelName(DiagLevel diagLevel);
29
33constexpr DiagLevel &operator|=(DiagLevel &lhs, const DiagLevel &rhs)
34{
35 if (lhs < rhs) {
36 lhs = rhs;
37 }
38 return lhs;
39}
40
42public:
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
57private:
58 DiagLevel m_level;
59 std::string m_message;
60 std::string m_context;
61 CppUtilities::DateTime m_creationTime;
62};
63
67inline 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
78inline 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
89inline 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
100inline 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
119inline std::string_view DiagMessage::levelName() const
120{
121 return diagLevelName(m_level);
122}
123
127inline const std::string &DiagMessage::message() const
128{
129 return m_message;
130}
131
135inline const std::string &DiagMessage::context() const
136{
137 return m_context;
138}
139
143inline const CppUtilities::DateTime &DiagMessage::creationTime() const
144{
145 return m_creationTime;
146}
147
151inline 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
156class TAG_PARSER_EXPORT Diagnostics : public std::vector<DiagMessage> {
157public:
158 Diagnostics() = default;
159 Diagnostics(std::initializer_list<DiagMessage> list);
160
161 bool has(DiagLevel level) const;
162 DiagLevel level() const;
163};
164
168inline 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().
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.
DiagLevel level() const
Returns the level.
bool operator==(const DiagMessage &other) const
Returns whether the current instance equals other.
const CppUtilities::DateTime & creationTime() const
Returns the creation time (using GMT timezone).
const std::string & context() const
Returns the context.
const std::string & message() const
Returns the message.
bool has(DiagLevel level) const
Returns whether there's at least one DiagMessage which is at least as worse as level.
DiagLevel level() const
Returns the worst diag level present in the container.
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
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.
DiagLevel
Specifies the level of the diagnostic message.
Definition diagnostics.h:16
constexpr auto worstDiagLevel
The worst diag level.
Definition diagnostics.h:26