Tag Parser  6.2.2
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 MEDIA_TAGTARGET_H
2 #define MEDIA_TAGTARGET_H
3 
4 #include "./global.h"
5 
6 #include <c++utilities/conversion/types.h>
7 
8 #include <string>
9 #include <vector>
10 #include <functional>
11 
12 namespace Media {
13 
17 enum class TagTargetLevel : unsigned char
18 {
20  Shot,
21  Subtrack,
22  Track,
23  Part,
24  Album,
25  Edition,
27 };
28 
29 TAG_PARSER_EXPORT const char *tagTargetLevelName(TagTargetLevel tagTargetLevel);
30 
32 {
33 public:
34  typedef uint64 IdType;
35  typedef std::vector<IdType> IdContainerType;
36 
37  TagTarget(uint64 level = 0, IdContainerType tracks = IdContainerType(), IdContainerType chapters = IdContainerType(), IdContainerType editions = IdContainerType(), IdContainerType attachments = IdContainerType());
38 
39  uint64 level() const;
40  void setLevel(uint64 level);
41  const std::string &levelName() const;
42  void setLevelName(const std::string &levelName);
43  const IdContainerType &tracks() const;
44  IdContainerType &tracks();
45  const IdContainerType &chapters() const;
46  IdContainerType &chapters();
47  const IdContainerType &editions() const;
48  IdContainerType &editions();
49  const IdContainerType &attachments() const;
50  IdContainerType &attachments();
51  bool isEmpty() const;
52  void clear();
53  std::string toString(const std::function<TagTargetLevel(uint64)> &tagTargetMapping) const;
54  std::string toString(TagTargetLevel tagTargetLevel) const;
55  bool operator ==(const TagTarget &other) const;
56 
57 private:
58  uint64 m_level;
59  std::string m_levelName;
60  IdContainerType m_tracks;
61  IdContainerType m_chapters;
62  IdContainerType m_editions;
63  IdContainerType m_attachments;
64 };
65 
70 inline TagTarget::TagTarget(uint64 level, IdContainerType tracks, IdContainerType chapters, IdContainerType editions, IdContainerType attachments) :
71  m_level(level),
72  m_tracks(tracks),
73  m_chapters(chapters),
74  m_editions(editions),
75  m_attachments(attachments)
76 {}
77 
81 inline uint64 TagTarget::level() const
82 {
83  return m_level ? m_level : 50;
84 }
85 
89 inline void TagTarget::setLevel(uint64 level)
90 {
91  m_level = level;
92 }
93 
97 inline const std::string &TagTarget::levelName() const
98 {
99  return m_levelName;
100 }
101 
105 inline void TagTarget::setLevelName(const std::string &levelName)
106 {
107  m_levelName = levelName;
108 }
109 
114 {
115  return m_tracks;
116 }
117 
122 {
123  return m_tracks;
124 }
125 
130 {
131  return m_chapters;
132 }
133 
138 {
139  return m_chapters;
140 }
141 
146 {
147  return m_editions;
148 }
149 
154 {
155  return m_editions;
156 }
157 
162 {
163  return m_attachments;
164 }
165 
170 {
171  return m_attachments;
172 }
173 
177 inline bool TagTarget::isEmpty() const
178 {
179  return m_level == 0
180  && m_levelName.empty()
181  && m_tracks.empty()
182  && m_chapters.empty()
183  && m_editions.empty()
184  && m_attachments.empty();
185 }
186 
190 inline void TagTarget::clear()
191 {
192  m_level = 0;
193  m_levelName.clear();
194  m_tracks.clear();
195  m_chapters.clear();
196  m_editions.clear();
197  m_attachments.clear();
198 }
199 
204 inline bool TagTarget::operator ==(const TagTarget &other) const
205 {
206  return level() == other.level()
207  && m_tracks == other.m_tracks
208  && m_chapters == other.m_chapters
209  && m_editions == other.m_editions
210  && m_attachments == other.m_attachments;
211 }
212 
218 inline std::string TagTarget::toString(const std::function<TagTargetLevel(uint64)> &tagTargetMapping) const
219 {
220  return toString(tagTargetMapping ? tagTargetMapping(this->level()) : TagTargetLevel::Unspecified);
221 }
222 
223 }
224 
225 #endif // MEDIA_TAGTARGET_H
std::vector< IdType > IdContainerType
Definition: tagtarget.h:35
const std::string & levelName() const
Returns the level name.
Definition: tagtarget.h:97
void setLevelName(const std::string &levelName)
Sets the level name.
Definition: tagtarget.h:105
TAG_PARSER_EXPORT const char * tagTargetLevelName(TagTargetLevel tagTargetLevel)
Returns a string representation for the specified tagTargetLevel.
Definition: tagtarget.cpp:17
const IdContainerType & attachments() const
Returns the attachments.
Definition: tagtarget.h:161
bool isEmpty() const
Returns an indication whether the target is empty.
Definition: tagtarget.h:177
void setLevel(uint64 level)
Sets the level.
Definition: tagtarget.h:89
uint64 level() const
Returns the level.
Definition: tagtarget.h:81
const IdContainerType & tracks() const
Returns the tracks.
Definition: tagtarget.h:113
TagTargetLevel
The TagTargetLevel enum specifies tag target levels.
Definition: tagtarget.h:17
const IdContainerType & editions() const
Returns the editions.
Definition: tagtarget.h:145
std::string toString(const std::function< TagTargetLevel(uint64)> &tagTargetMapping) const
Returns the string representation of the current instance.
Definition: tagtarget.h:218
bool operator==(const TagTarget &other) const
Returns whether the tag targets are equal.
Definition: tagtarget.h:204
constexpr bool operator==(byte lhs, FlacMetaDataBlockType type)
Definition: flacmetadata.h:28
const IdContainerType & chapters() const
Returns the chapters.
Definition: tagtarget.h:129
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:31
void clear()
Clears the TagTarget.
Definition: tagtarget.h:190
Contains all classes and functions of the TagInfo library.
Definition: exceptions.h:9
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
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:70