Tag Parser 10.3.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
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
25 explicit TagTarget(std::uint64_t level = 0, IdContainerType tracks = IdContainerType(), IdContainerType chapters = IdContainerType(),
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;
33 IdContainerType &tracks();
34 const IdContainerType &chapters() const;
35 IdContainerType &chapters();
36 const IdContainerType &editions() const;
37 IdContainerType &editions();
38 const IdContainerType &attachments() const;
39 IdContainerType &attachments();
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
46private:
47 std::uint64_t m_level;
48 std::string m_levelName;
49 IdContainerType m_tracks;
50 IdContainerType m_chapters;
51 IdContainerType m_editions;
52 IdContainerType m_attachments;
53};
54
60 std::uint64_t level, IdContainerType tracks, IdContainerType chapters, IdContainerType editions, IdContainerType attachments)
61 : m_level(level)
62 , m_tracks(tracks)
63 , m_chapters(chapters)
64 , m_editions(editions)
65 , m_attachments(attachments)
66{
67}
68
72inline std::uint64_t TagTarget::level() const
73{
74 return m_level ? m_level : 50;
75}
76
80inline void TagTarget::setLevel(std::uint64_t level)
81{
82 m_level = level;
83}
84
88inline const std::string &TagTarget::levelName() const
89{
90 return m_levelName;
91}
92
96inline void TagTarget::setLevelName(const std::string &levelName)
97{
98 m_levelName = levelName;
99}
100
105{
106 return m_tracks;
107}
108
113{
114 return m_tracks;
115}
116
121{
122 return m_chapters;
123}
124
129{
130 return m_chapters;
131}
132
137{
138 return m_editions;
139}
140
145{
146 return m_editions;
147}
148
153{
154 return m_attachments;
155}
156
161{
162 return m_attachments;
163}
164
168inline bool TagTarget::isEmpty() const
169{
170 return m_level == 0 && m_levelName.empty() && m_tracks.empty() && m_chapters.empty() && m_editions.empty() && m_attachments.empty();
171}
172
176inline void TagTarget::clear()
177{
178 m_level = 0;
179 m_levelName.clear();
180 m_tracks.clear();
181 m_chapters.clear();
182 m_editions.clear();
183 m_attachments.clear();
184}
185
190inline bool TagTarget::operator==(const TagTarget &other) const
191{
192 return level() == other.level() && m_tracks == other.m_tracks && m_chapters == other.m_chapters && m_editions == other.m_editions
193 && m_attachments == other.m_attachments;
194}
195
201inline std::string TagTarget::toString(const std::function<TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
202{
203 return toString(tagTargetMapping ? tagTargetMapping(this->level()) : TagTargetLevel::Unspecified);
204}
205
206} // namespace TagParser
207
208#endif // TAG_PARSER_TAGTARGET_H
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:20
const IdContainerType & tracks() const
Returns the tracks.
Definition: tagtarget.h:104
std::vector< IdType > IdContainerType
Definition: tagtarget.h:23
const IdContainerType & chapters() const
Returns the chapters.
Definition: tagtarget.h:120
std::uint64_t level() const
Returns the level.
Definition: tagtarget.h:72
std::string toString(const std::function< TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
Returns the string representation of the current instance.
Definition: tagtarget.h:201
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:59
const std::string & levelName() const
Returns the level name.
Definition: tagtarget.h:88
bool isEmpty() const
Returns an indication whether the target is empty.
Definition: tagtarget.h:168
bool operator==(const TagTarget &other) const
Returns whether the tag targets are equal.
Definition: tagtarget.h:190
const IdContainerType & editions() const
Returns the editions.
Definition: tagtarget.h:136
void clear()
Clears the TagTarget.
Definition: tagtarget.h:176
const IdContainerType & attachments() const
Returns the attachments.
Definition: tagtarget.h:152
void setLevel(std::uint64_t level)
Sets the level.
Definition: tagtarget.h:80
std::uint64_t IdType
Definition: tagtarget.h:22
void setLevelName(const std::string &levelName)
Sets the level name.
Definition: tagtarget.h:96
#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
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
constexpr bool operator==(std::uint8_t lhs, FlacMetaDataBlockType type)
Definition: flacmetadata.h:18