Tag Parser  8.2.0
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 <c++utilities/conversion/types.h>
7 
8 #include <functional>
9 #include <string>
10 #include <vector>
11 
12 namespace TagParser {
13 
17 enum class TagTargetLevel : unsigned char { Unspecified, Shot, Subtrack, Track, Part, Album, Edition, Collection };
18 
19 TAG_PARSER_EXPORT const char *tagTargetLevelName(TagTargetLevel tagTargetLevel);
20 
22 public:
23  using IdType = uint64;
24  using IdContainerType = std::vector<IdType>;
25 
26  TagTarget(uint64 level = 0, IdContainerType tracks = IdContainerType(), IdContainerType chapters = IdContainerType(),
27  IdContainerType editions = IdContainerType(), IdContainerType attachments = IdContainerType());
28 
29  uint64 level() const;
30  void setLevel(uint64 level);
31  const std::string &levelName() const;
32  void setLevelName(const std::string &levelName);
33  const IdContainerType &tracks() const;
34  IdContainerType &tracks();
35  const IdContainerType &chapters() const;
36  IdContainerType &chapters();
37  const IdContainerType &editions() const;
38  IdContainerType &editions();
39  const IdContainerType &attachments() const;
40  IdContainerType &attachments();
41  bool isEmpty() const;
42  void clear();
43  std::string toString(const std::function<TagTargetLevel(uint64)> &tagTargetMapping) const;
44  std::string toString(TagTargetLevel tagTargetLevel) const;
45  bool operator==(const TagTarget &other) const;
46 
47 private:
48  uint64 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(uint64 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 
72 inline uint64 TagTarget::level() const
73 {
74  return m_level ? m_level : 50;
75 }
76 
80 inline void TagTarget::setLevel(uint64 level)
81 {
82  m_level = level;
83 }
84 
88 inline const std::string &TagTarget::levelName() const
89 {
90  return m_levelName;
91 }
92 
96 inline 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 
168 inline 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 
176 inline 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 
190 inline 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 
201 inline std::string TagTarget::toString(const std::function<TagTargetLevel(uint64)> &tagTargetMapping) const
202 {
203  return toString(tagTargetMapping ? tagTargetMapping(this->level()) : TagTargetLevel::Unspecified);
204 }
205 
206 } // namespace TagParser
207 
208 #endif // TAG_PARSER_TAGTARGET_H
void clear()
Clears the TagTarget.
Definition: tagtarget.h:176
std::string toString(const std::function< TagTargetLevel(uint64)> &tagTargetMapping) const
Returns the string representation of the current instance.
Definition: tagtarget.h:201
TagTargetLevel
The TagTargetLevel enum specifies tag target levels.
Definition: tagtarget.h:17
const IdContainerType & attachments() const
Returns the attachments.
Definition: tagtarget.h:152
bool operator==(const TagTarget &other) const
Returns whether the tag targets are equal.
Definition: tagtarget.h:190
uint64 level() const
Returns the level.
Definition: tagtarget.h:72
constexpr bool operator==(byte lhs, FlacMetaDataBlockType type)
Definition: flacmetadata.h:19
TAG_PARSER_EXPORT const char * tagTargetLevelName(TagTargetLevel tagTargetLevel)
Returns a string representation for the specified tagTargetLevel.
Definition: tagtarget.cpp:17
bool isEmpty() const
Returns an indication whether the target is empty.
Definition: tagtarget.h:168
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:21
TagTarget(uint64 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
void setLevel(uint64 level)
Sets the level.
Definition: tagtarget.h:80
const IdContainerType & tracks() const
Returns the tracks.
Definition: tagtarget.h:104
std::vector< IdType > IdContainerType
Definition: tagtarget.h:24
void setLevelName(const std::string &levelName)
Sets the level name.
Definition: tagtarget.h:96
const std::string & levelName() const
Returns the level name.
Definition: tagtarget.h:88
const IdContainerType & editions() const
Returns the editions.
Definition: tagtarget.h:136
const IdContainerType & chapters() const
Returns the chapters.
Definition: tagtarget.h:120
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.