Tag Parser: diagnostics.h Source File

Tag Parser 12.5.2 C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags

Loading...
Searching...
No Matches
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
16 enum class DiagLevel {
17 None = 0,
18 Debug = 1,
19 Information = 2,
20 Warning = 3,
21 Critical = 4,
22 Fatal = 5,
23};
24
26 constexpr auto worstDiagLevel = DiagLevel::Fatal;
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 {
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
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
111 inline DiagLevel DiagMessage::level() const
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> {
157public:
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
TagParser::DiagMessage
The DiagMessage class holds an information, warning or error gathered during parsing or making.
Definition diagnostics.h:41
TagParser::DiagMessage::levelName
std::string_view levelName() const
Returns the string representation of the level().
Definition diagnostics.h:119
TagParser::DiagMessage::DiagMessage
DiagMessage(DiagLevel level, const std::string &message, const std::string &context)
Constructs a new DiagMessage.
Definition diagnostics.h:67
TagParser::DiagMessage::formatList
static std::string formatList(const std::vector< std::string > &values)
Concatenates the specified string values to a list.
Definition diagnostics.cpp:69
TagParser::DiagMessage::level
DiagLevel level() const
Returns the level.
Definition diagnostics.h:111
TagParser::DiagMessage::operator==
bool operator==(const DiagMessage &other) const
Returns whether the current instance equals other.
Definition diagnostics.h:151
TagParser::DiagMessage::creationTime
const CppUtilities::DateTime & creationTime() const
Returns the creation time (using GMT timezone).
Definition diagnostics.h:143
TagParser::DiagMessage::context
const std::string & context() const
Returns the context.
Definition diagnostics.h:135
TagParser::DiagMessage::message
const std::string & message() const
Returns the message.
Definition diagnostics.h:127
TagParser::Diagnostics::has
bool has(DiagLevel level) const
Returns whether there's at least one DiagMessage which is at least as worse as level.
Definition diagnostics.cpp:42
TagParser::Diagnostics::Diagnostics
Diagnostics()=default
TagParser::Diagnostics::level
DiagLevel level() const
Returns the worst diag level present in the container.
Definition diagnostics.cpp:55
global.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
CppUtilities
Definition abstractcontainer.h:16
TagParser::SubFormats::None
@ None
Definition mediaformat.h:112
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::operator|=
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
TagParser::diagLevelName
TAG_PARSER_EXPORT std::string_view diagLevelName(DiagLevel diagLevel)
Returns the string representation of the specified diagLevel.
Definition diagnostics.cpp:22
TagParser::DiagLevel
DiagLevel
Specifies the level of the diagnostic message.
Definition diagnostics.h:16
TagParser::DiagLevel::Warning
@ Warning
Definition diagnostics.h:20
TagParser::DiagLevel::Critical
@ Critical
Definition diagnostics.h:21
TagParser::DiagLevel::Fatal
@ Fatal
Definition diagnostics.h:22
TagParser::DiagLevel::Debug
@ Debug
Definition diagnostics.h:18
TagParser::DiagLevel::Information
@ Information
Definition diagnostics.h:19
TagParser::TagDataType::DateTime
@ DateTime
Definition tagvalue.h:125
TagParser::worstDiagLevel
constexpr auto worstDiagLevel
The worst diag level.
Definition diagnostics.h:26