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
tagtarget.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_TAGTARGET_H
2#define TAG_PARSER_TAGTARGET_H
3
4#include "./global.h"
5
6#include <cstdint>
7#include <functional>
8#include <string>
9#include <vector>
10
11namespace TagParser {
12
17
18TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel);
19
21public:
22 using IdType = std::uint64_t;
23 using IdContainerType = std::vector<IdType>;
24
27
28 std::uint64_t level() const;
29 void setLevel(std::uint64_t level);
30 const std::string &levelName() const;
31 void setLevelName(const std::string &levelName);
32 const IdContainerType &tracks() const;
34 const IdContainerType &chapters() const;
36 const IdContainerType &editions() const;
38 const IdContainerType &attachments() const;
40 bool isEmpty() const;
41 void clear();
42 std::string toString(const std::function<TagTargetLevel(std::uint64_t)> &tagTargetMapping) const;
43 std::string toString(TagTargetLevel tagTargetLevel) const;
44 bool operator==(const TagTarget &other) const;
45 bool matches(const TagTarget &other) const;
46
47private:
48 std::uint64_t m_level;
49 std::string m_levelName;
50 IdContainerType m_tracks;
51 IdContainerType m_chapters;
52 IdContainerType m_editions;
53 IdContainerType m_attachments;
54};
55
62 : m_level(level)
63 , m_tracks(tracks)
64 , m_chapters(chapters)
65 , m_editions(editions)
66 , m_attachments(attachments)
67{
68}
69
73inline std::uint64_t TagTarget::level() const
74{
75 return m_level ? m_level : 50;
76}
77
81inline void TagTarget::setLevel(std::uint64_t level)
82{
83 m_level = level;
84}
85
89inline const std::string &TagTarget::levelName() const
90{
91 return m_levelName;
92}
93
97inline void TagTarget::setLevelName(const std::string &levelName)
98{
99 m_levelName = levelName;
100}
101
106{
107 return m_tracks;
108}
109
114{
115 return m_tracks;
116}
117
122{
123 return m_chapters;
124}
125
130{
131 return m_chapters;
132}
133
138{
139 return m_editions;
140}
141
146{
147 return m_editions;
148}
149
154{
155 return m_attachments;
156}
157
162{
163 return m_attachments;
164}
165
169inline bool TagTarget::isEmpty() const
170{
171 return m_level == 0 && m_levelName.empty() && m_tracks.empty() && m_chapters.empty() && m_editions.empty() && m_attachments.empty();
172}
173
177inline void TagTarget::clear()
178{
179 m_level = 0;
180 m_levelName.clear();
181 m_tracks.clear();
182 m_chapters.clear();
183 m_editions.clear();
184 m_attachments.clear();
185}
186
193inline bool TagTarget::operator==(const TagTarget &other) const
194{
195 return level() == other.level() && m_tracks == other.m_tracks && m_chapters == other.m_chapters && m_editions == other.m_editions
196 && m_attachments == other.m_attachments;
197}
198
205inline bool TagTarget::matches(const TagTarget &other) const
206{
207 return (!m_level || level() == other.level()) && (m_tracks.empty() || m_tracks == other.m_tracks)
208 && (m_chapters.empty() || m_chapters == other.m_chapters) && (m_editions.empty() || m_editions == other.m_editions)
209 && (m_attachments.empty() || m_attachments == other.m_attachments);
210}
211
217inline std::string TagTarget::toString(const std::function<TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
218{
219 return toString(tagTargetMapping ? tagTargetMapping(this->level()) : TagTargetLevel::Unspecified);
220}
221
222} // namespace TagParser
223
224#endif // TAG_PARSER_TAGTARGET_H
const IdContainerType & tracks() const
Returns the tracks.
Definition tagtarget.h:105
std::vector< IdType > IdContainerType
Definition tagtarget.h:23
bool matches(const TagTarget &other) const
Returns whether the current instance matches other.
Definition tagtarget.h:205
const IdContainerType & chapters() const
Returns the chapters.
Definition tagtarget.h:121
std::uint64_t level() const
Returns the level.
Definition tagtarget.h:73
std::string toString(const std::function< TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
Returns the string representation of the current instance.
Definition tagtarget.h:217
TagTarget(std::uint64_t level=0, IdContainerType tracks=IdContainerType(), IdContainerType chapters=IdContainerType(), IdContainerType editions=IdContainerType(), IdContainerType attachments=IdContainerType())
Constructs a new TagTarget with the specified level, track, chapter, edition and attachment.
Definition tagtarget.h:60
const std::string & levelName() const
Returns the level name.
Definition tagtarget.h:89
bool isEmpty() const
Returns an indication whether the target is empty.
Definition tagtarget.h:169
bool operator==(const TagTarget &other) const
Returns whether the tag targets are equal.
Definition tagtarget.h:193
const IdContainerType & editions() const
Returns the editions.
Definition tagtarget.h:137
void clear()
Clears the TagTarget.
Definition tagtarget.h:177
const IdContainerType & attachments() const
Returns the attachments.
Definition tagtarget.h:153
void setLevel(std::uint64_t level)
Sets the level.
Definition tagtarget.h:81
std::uint64_t IdType
Definition tagtarget.h:22
void setLevelName(const std::string &levelName)
Sets the level name.
Definition tagtarget.h:97
#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
TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel)
Returns a string representation for the specified tagTargetLevel.
Definition tagtarget.cpp:17
TagTargetLevel
The TagTargetLevel enum specifies tag target levels.
Definition tagtarget.h:16