Tag Parser: tagtarget.h Source File

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

Loading...
Searching...
No Matches
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
16 enum class TagTargetLevel : unsigned char { Unspecified, Shot, Subtrack, Track, Part, Album, Edition, Collection };
17
18 TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel);
19
20 class TAG_PARSER_EXPORT TagTarget {
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(),
26 IdContainerType editions = IdContainerType(), IdContainerType attachments = 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 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
60 inline TagTarget::TagTarget(
61 std::uint64_t level, IdContainerType tracks, IdContainerType chapters, IdContainerType editions, IdContainerType attachments)
62 : m_level(level)
63 , m_tracks(tracks)
64 , m_chapters(chapters)
65 , m_editions(editions)
66 , m_attachments(attachments)
67{
68}
69
73 inline std::uint64_t TagTarget::level() const
74{
75 return m_level ? m_level : 50;
76}
77
81 inline void TagTarget::setLevel(std::uint64_t level)
82{
83 m_level = level;
84}
85
89 inline const std::string &TagTarget::levelName() const
90{
91 return m_levelName;
92}
93
97 inline void TagTarget::setLevelName(const std::string &levelName)
98{
99 m_levelName = levelName;
100}
101
105 inline const TagTarget::IdContainerType &TagTarget::tracks() const
106{
107 return m_tracks;
108}
109
113 inline TagTarget::IdContainerType &TagTarget::tracks()
114{
115 return m_tracks;
116}
117
121 inline const TagTarget::IdContainerType &TagTarget::chapters() const
122{
123 return m_chapters;
124}
125
129 inline TagTarget::IdContainerType &TagTarget::chapters()
130{
131 return m_chapters;
132}
133
137 inline const TagTarget::IdContainerType &TagTarget::editions() const
138{
139 return m_editions;
140}
141
145 inline TagTarget::IdContainerType &TagTarget::editions()
146{
147 return m_editions;
148}
149
153 inline const TagTarget::IdContainerType &TagTarget::attachments() const
154{
155 return m_attachments;
156}
157
161 inline TagTarget::IdContainerType &TagTarget::attachments()
162{
163 return m_attachments;
164}
165
169 inline 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
177 inline 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
193 inline 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
205 inline 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
217 inline 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
TagParser::TagTarget::tracks
const IdContainerType & tracks() const
Returns the tracks.
Definition tagtarget.h:105
TagParser::TagTarget::IdContainerType
std::vector< IdType > IdContainerType
Definition tagtarget.h:23
TagParser::TagTarget::matches
bool matches(const TagTarget &other) const
Returns whether the current instance matches other.
Definition tagtarget.h:205
TagParser::TagTarget::chapters
const IdContainerType & chapters() const
Returns the chapters.
Definition tagtarget.h:121
TagParser::TagTarget::level
std::uint64_t level() const
Returns the level.
Definition tagtarget.h:73
TagParser::TagTarget::toString
std::string toString(const std::function< TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
Returns the string representation of the current instance.
Definition tagtarget.h:217
TagParser::TagTarget::TagTarget
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
TagParser::TagTarget::levelName
const std::string & levelName() const
Returns the level name.
Definition tagtarget.h:89
TagParser::TagTarget::isEmpty
bool isEmpty() const
Returns an indication whether the target is empty.
Definition tagtarget.h:169
TagParser::TagTarget::operator==
bool operator==(const TagTarget &other) const
Returns whether the tag targets are equal.
Definition tagtarget.h:193
TagParser::TagTarget::editions
const IdContainerType & editions() const
Returns the editions.
Definition tagtarget.h:137
TagParser::TagTarget::clear
void clear()
Clears the TagTarget.
Definition tagtarget.h:177
TagParser::TagTarget::attachments
const IdContainerType & attachments() const
Returns the attachments.
Definition tagtarget.h:153
TagParser::TagTarget::setLevel
void setLevel(std::uint64_t level)
Sets the level.
Definition tagtarget.h:81
TagParser::TagTarget::IdType
std::uint64_t IdType
Definition tagtarget.h:22
TagParser::TagTarget::setLevelName
void setLevelName(const std::string &levelName)
Sets the level name.
Definition tagtarget.h:97
global.h
TAG_PARSER_EXPORT
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:14
TagParser
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
TagParser::KnownField::Album
@ Album
Definition tag.h:40
TagParser::tagTargetLevelName
TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel)
Returns a string representation for the specified tagTargetLevel.
Definition tagtarget.cpp:17
TagParser::TagTargetLevel
TagTargetLevel
The TagTargetLevel enum specifies tag target levels.
Definition tagtarget.h:16
TagParser::TagTargetLevel::Edition
@ Edition
Definition tagtarget.h:16
TagParser::TagTargetLevel::Shot
@ Shot
Definition tagtarget.h:16
TagParser::TagTargetLevel::Part
@ Part
Definition tagtarget.h:16
TagParser::TagTargetLevel::Subtrack
@ Subtrack
Definition tagtarget.h:16
TagParser::TagTargetLevel::Unspecified
@ Unspecified
Definition tagtarget.h:16
TagParser::TagTargetLevel::Track
@ Track
Definition tagtarget.h:16
TagParser::TagTargetLevel::Collection
@ Collection
Definition tagtarget.h:16
TagParser::TrackType::Unspecified
@ Unspecified
Definition abstracttrack.h:33