Tag Parser 12.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
Loading...
Searching...
No Matches
tag.h
Go to the documentation of this file.
1#ifndef TAG_PARSER_TAG_H
2#define TAG_PARSER_TAG_H
3
4#include "./tagtarget.h"
5#include "./tagtype.h"
6#include "./tagvalue.h"
7
8#include <c++utilities/io/binaryreader.h>
9
10#include <cstdint>
11#include <memory>
12#include <string>
13#include <type_traits>
14
15namespace TagParser {
16
37enum class KnownField : unsigned int {
38 Invalid = std::numeric_limits<unsigned int>::max(),
39 Title = 0,
40 Album,
41 Artist,
42 Genre,
43 Comment,
44 Bpm,
45 Bps,
46 Lyricist,
51 Encoder,
54 Length,
55 Language,
57 Lyrics,
59 Grouping,
61 Cover,
62 Composer,
63 Rating,
65 Vendor,
68 Subtitle,
70 Arranger,
71 Conductor,
72 Director,
80 Actor,
81 Character,
82 WrittenBy,
84 EditedBy,
85 Producer,
90 EncodedBy,
91 MixedBy,
92 RemixedBy,
94 ThanksTo,
95 Publisher,
96 Mood,
99 Subject,
100 Keywords,
101 Summary,
102 Synopsis,
103 InitialKey,
104 Period,
105 LawRating,
116 Measure,
117 Tuning,
118 ISRC,
119 MCDI,
120 ISBN,
121 Barcode,
123 LabelCode,
124 LCCN,
125 IMDB,
126 TMDB,
127 TVDB,
133 Copyright,
135 License,
136 TermsOfUse,
139 MediaType,
142};
143
148
153
157constexpr unsigned int knownFieldArraySize = static_cast<unsigned int>(lastKnownField) + 1;
158
163{
164 CPP_UTILITIES_UNUSED(field)
165 return false;
166}
167
172{
173 const auto next = field == lastKnownField ? KnownField::Invalid : static_cast<KnownField>(static_cast<int>(field) + 1);
174 return isKnownFieldDeprecated(next) ? nextKnownField(next) : next;
175}
176
177struct TagPrivate;
178
179class TAG_PARSER_EXPORT Tag {
180public:
181 virtual ~Tag();
182
183 virtual TagType type() const;
184 virtual std::string_view typeName() const;
185 std::string toString() const;
186 virtual TagTextEncoding proposedTextEncoding() const;
187 virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
188 virtual const TagValue &value(KnownField field) const = 0;
189 virtual std::vector<const TagValue *> values(KnownField field) const;
190 virtual bool setValue(KnownField field, const TagValue &value) = 0;
191 virtual bool setValues(KnownField field, const std::vector<TagValue> &values);
192 virtual bool hasField(KnownField field) const = 0;
193 virtual void removeAllFields() = 0;
194 const std::string &version() const;
195 std::uint64_t size() const;
196 virtual bool supportsTarget() const;
197 const TagTarget &target() const;
198 TagTarget &target();
199 void setTarget(const TagTarget &target);
200 virtual TagTargetLevel targetLevel() const;
201 std::string_view targetLevelName() const;
202 bool isTargetingLevel(TagTargetLevel tagTargetLevel) const;
203 std::string targetString() const;
204 virtual std::size_t fieldCount() const = 0;
205 virtual bool supportsField(KnownField field) const = 0;
206 virtual TagDataType proposedDataType(KnownField field) const;
207 virtual bool supportsDescription(KnownField field) const;
208 virtual bool supportsMimeType(KnownField field) const;
209 virtual bool supportsMultipleValues(KnownField field) const;
210 virtual std::size_t insertValues(const Tag &from, bool overwrite);
212
213protected:
214 Tag();
215
216 std::string m_version;
217 std::uint64_t m_size;
218 std::unique_ptr<TagPrivate> m_p;
220};
221
222inline TagType Tag::type() const
223{
225}
226
227inline std::string_view Tag::typeName() const
228{
229 return "unspecified";
230}
231
236
237inline bool Tag::canEncodingBeUsed(TagTextEncoding encoding) const
238{
239 return encoding == proposedTextEncoding();
240}
241
242inline const std::string &Tag::version() const
243{
244 return m_version;
245}
246
247inline std::uint64_t Tag::size() const
248{
249 return m_size;
250}
251
252inline bool Tag::supportsTarget() const
253{
254 return false;
255}
256
257inline const TagTarget &Tag::target() const
258{
259 return m_target;
260}
261
263{
264 return m_target;
265}
266
267inline void Tag::setTarget(const TagTarget &target)
268{
270}
271
276
277inline std::string_view Tag::targetLevelName() const
278{
279 return supportsTarget() ? tagTargetLevelName(targetLevel()) : std::string_view();
280}
281
282inline bool Tag::isTargetingLevel(TagTargetLevel tagTargetLevel) const
283{
284 return !supportsTarget() || static_cast<std::uint8_t>(targetLevel()) >= static_cast<std::uint8_t>(tagTargetLevel);
285}
286
287inline std::string Tag::targetString() const
288{
289 return target().toString(targetLevel());
290}
291
293{
294 switch (field) {
295 case KnownField::Bpm:
296 case KnownField::Bps:
310 case KnownField::MCDI:
311 return TagDataType::Binary;
313 // could also be a plain integer but popularity should generally be used (and can be converted
314 // to an integer)
317 // not supported
319 default:
320 return TagDataType::Text;
321 }
322}
323
325{
326 return false;
327}
328
330{
331 return false;
332}
333
335{
336 return false;
337}
338
339} // namespace TagParser
340
341#endif // TAG_PARSER_TAG_H
The TagTarget class specifies the target of a tag.
std::string toString(const std::function< TagTargetLevel(std::uint64_t)> &tagTargetMapping) const
Returns the string representation of the current instance.
Definition tagtarget.h:217
The TagValue class wraps values of different types.
The Tag class is used to store, read and write tag information.
virtual TagTargetLevel targetLevel() const
Returns the name of the current tag target level.
Definition tag.h:272
virtual bool setValue(KnownField field, const TagValue &value)=0
Assigns the given value to the specified field.
virtual void ensureTextValuesAreProperlyEncoded()=0
Ensures the encoding of all assigned text values is supported by the tag by converting the character ...
std::string m_version
Definition tag.h:216
std::uint64_t m_size
Definition tag.h:217
std::uint64_t size() const
Returns the size the tag within the file it is parsed from in bytes.
Definition tag.h:247
void setTarget(const TagTarget &target)
Sets the target of tag.
Definition tag.h:267
std::unique_ptr< TagPrivate > m_p
Definition tag.h:218
virtual bool canEncodingBeUsed(TagTextEncoding encoding) const
Returns an indication whether the specified encoding can be used to provide string values for the tag...
Definition tag.h:237
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition tag.h:252
std::string_view targetLevelName() const
Returns the name of the current target level.
Definition tag.h:277
virtual TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition tag.h:232
virtual std::string_view typeName() const
Returns the type name of the tag as C-style string.
Definition tag.h:227
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
Definition tag.h:222
TagTarget m_target
Definition tag.h:219
const TagTarget & target() const
Definition tag.h:257
virtual bool supportsField(KnownField field) const =0
Returns an indication whether the specified field is supported by the tag.
virtual TagDataType proposedDataType(KnownField field) const
Returns the proposed data type for the specified field as TagDataType.
Definition tag.h:292
virtual bool supportsMultipleValues(KnownField field) const
Returns an indications whether the specified field supports multiple values.
Definition tag.h:334
virtual void removeAllFields()=0
Removes all fields from the tag.
bool isTargetingLevel(TagTargetLevel tagTargetLevel) const
Returns whether the tag is targeting the specified tagTargetLevel.
Definition tag.h:282
const std::string & version() const
Returns the version of the tag as std::string.
Definition tag.h:242
virtual bool hasField(KnownField field) const =0
Returns an indication whether the specified field is present.
virtual bool supportsMimeType(KnownField field) const
Returns an indications whether the specified field supports mime types.
Definition tag.h:329
virtual bool supportsDescription(KnownField field) const
Returns an indications whether the specified field supports descriptions.
Definition tag.h:324
virtual const TagValue & value(KnownField field) const =0
Returns the value of the specified field.
virtual std::size_t fieldCount() const =0
Returns the number of present fields.
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition tag.h:287
#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
KnownField
Specifies the field.
Definition tag.h:37
TAG_PARSER_EXPORT std::string_view tagTargetLevelName(TagTargetLevel tagTargetLevel)
Returns a string representation for the specified tagTargetLevel.
Definition tagtarget.cpp:17
constexpr unsigned int knownFieldArraySize
The number of valid entries in the TagParser::KnownField enum.
Definition tag.h:157
TagTargetLevel
The TagTargetLevel enum specifies tag target levels.
Definition tagtarget.h:16
constexpr KnownField nextKnownField(KnownField field)
Returns the next known field skipping any deprecated fields.
Definition tag.h:171
TagTextEncoding
Specifies the text encoding.
Definition tagvalue.h:29
constexpr KnownField lastKnownField
The last valid entry in the TagParser::KnownField enum.
Definition tag.h:152
TagType
Specifies the tag type.
Definition tagtype.h:11
constexpr KnownField firstKnownField
The first valid entry in the TagParser::KnownField enum.
Definition tag.h:147
constexpr bool isKnownFieldDeprecated(KnownField field)
Returns whether the specified field is deprecated and should not be used anymore.
Definition tag.h:162
MediaType
The MediaType enum specifies the type of media data (audio, video, text, ...).
Definition mediaformat.h:14
TagDataType
Specifies the data type.
Definition tagvalue.h:119