Tag Parser 11.4.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
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 <string>
12#include <type_traits>
13
14namespace TagParser {
15
28enum class KnownField : unsigned int {
29 Invalid = std::numeric_limits<unsigned int>::max(),
30 Title = 0,
31 Album,
32 Artist,
33 Genre,
34 Comment,
35 Bpm,
36 Bps,
37 Lyricist,
38 TrackPosition,
39 DiskPosition,
42 Encoder,
44 Performers,
45 Length,
46 Language,
48 Lyrics,
50 Grouping,
51 RecordLabel,
52 Cover,
53 Composer,
54 Rating,
55 Description,
56 Vendor,
57 AlbumArtist,
59 Subtitle,
61 Arranger,
62 Conductor,
63 Director,
66 SoundEngineer,
67 ArtDirector,
71 Actor,
72 Character,
73 WrittenBy,
75 EditedBy,
76 Producer,
78 ExecutiveProducer,
81 EncodedBy,
82 MixedBy,
83 RemixedBy,
85 ThanksTo,
86 Publisher,
87 Mood,
90 Subject,
91 Keywords,
92 Summary,
93 Synopsis,
95 Period,
96 LawRating,
107 Measure,
108 Tuning,
109 ISRC,
110 MCDI,
111 ISBN,
112 Barcode,
114 LabelCode,
115 LCCN,
116 IMDB,
117 TMDB,
118 TVDB,
124 Copyright,
126 License,
127 TermsOfUse,
128};
129
134
139
143constexpr unsigned int knownFieldArraySize = static_cast<unsigned int>(lastKnownField) + 1;
144
149{
150 CPP_UTILITIES_UNUSED(field)
151 return false;
152}
153
158{
159 const auto next = field == lastKnownField ? KnownField::Invalid : static_cast<KnownField>(static_cast<int>(field) + 1);
160 return isKnownFieldDeprecated(next) ? nextKnownField(next) : next;
161}
162
164public:
165 virtual ~Tag();
166
167 virtual TagType type() const;
168 virtual std::string_view typeName() const;
169 std::string toString() const;
170 virtual TagTextEncoding proposedTextEncoding() const;
171 virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
172 virtual const TagValue &value(KnownField field) const = 0;
173 virtual std::vector<const TagValue *> values(KnownField field) const;
174 virtual bool setValue(KnownField field, const TagValue &value) = 0;
175 virtual bool setValues(KnownField field, const std::vector<TagValue> &values);
176 virtual bool hasField(KnownField field) const = 0;
177 virtual void removeAllFields() = 0;
178 const std::string &version() const;
179 std::uint64_t size() const;
180 virtual bool supportsTarget() const;
181 const TagTarget &target() const;
182 TagTarget &target();
183 void setTarget(const TagTarget &target);
184 virtual TagTargetLevel targetLevel() const;
185 std::string_view targetLevelName() const;
186 bool isTargetingLevel(TagTargetLevel tagTargetLevel) const;
187 std::string targetString() const;
188 virtual std::size_t fieldCount() const = 0;
189 virtual bool supportsField(KnownField field) const = 0;
190 virtual TagDataType proposedDataType(KnownField field) const;
191 virtual bool supportsDescription(KnownField field) const;
192 virtual bool supportsMimeType(KnownField field) const;
193 virtual bool supportsMultipleValues(KnownField field) const;
194 virtual std::size_t insertValues(const Tag &from, bool overwrite);
196
197protected:
198 Tag();
199
200 std::string m_version;
201 std::uint64_t m_size;
203};
204
205inline TagType Tag::type() const
206{
208}
209
210inline std::string_view Tag::typeName() const
211{
212 return "unspecified";
213}
214
216{
218}
219
220inline bool Tag::canEncodingBeUsed(TagTextEncoding encoding) const
221{
222 return encoding == proposedTextEncoding();
223}
224
225inline const std::string &Tag::version() const
226{
227 return m_version;
228}
229
230inline std::uint64_t Tag::size() const
231{
232 return m_size;
233}
234
235inline bool Tag::supportsTarget() const
236{
237 return false;
238}
239
240inline const TagTarget &Tag::target() const
241{
242 return m_target;
243}
244
246{
247 return m_target;
248}
249
250inline void Tag::setTarget(const TagTarget &target)
251{
253}
254
256{
258}
259
260inline std::string_view Tag::targetLevelName() const
261{
262 return supportsTarget() ? tagTargetLevelName(targetLevel()) : std::string_view();
263}
264
265inline bool Tag::isTargetingLevel(TagTargetLevel tagTargetLevel) const
266{
267 return !supportsTarget() || static_cast<std::uint8_t>(targetLevel()) >= static_cast<std::uint8_t>(tagTargetLevel);
268}
269
270inline std::string Tag::targetString() const
271{
272 return target().toString(targetLevel());
273}
274
276{
277 switch (field) {
278 case KnownField::Bpm:
279 case KnownField::Bps:
293 case KnownField::MCDI:
294 return TagDataType::Binary;
296 // could also be a plain integer but popularity should generally be used (and can be converted
297 // to an integer)
300 // not supported
302 default:
303 return TagDataType::Text;
304 }
305}
306
308{
309 return false;
310}
311
313{
314 return false;
315}
316
318{
319 return false;
320}
321
322} // namespace TagParser
323
324#endif // TAG_PARSER_TAG_H
The TagTarget class specifies the target of a tag.
Definition: tagtarget.h:20
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.
Definition: tagvalue.h:142
The Tag class is used to store, read and write tag information.
Definition: tag.h:163
std::uint64_t size() const
Returns the size the tag within the file it is parsed from in bytes.
Definition: tag.h:230
std::string_view targetLevelName() const
Returns the name of the current target level.
Definition: tag.h:260
void setTarget(const TagTarget &target)
Sets the target of tag.
Definition: tag.h:250
bool isTargetingLevel(TagTargetLevel tagTargetLevel) const
Returns whether the tag is targeting the specified tagTargetLevel.
Definition: tag.h:265
std::string m_version
Definition: tag.h:200
std::uint64_t m_size
Definition: tag.h:201
virtual std::size_t fieldCount() const =0
Returns the number of present fields.
const std::string & version() const
Returns the version of the tag as std::string.
Definition: tag.h:225
virtual bool supportsDescription(KnownField field) const
Returns an indications whether the specified field supports descriptions.
Definition: tag.h:307
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition: tag.h:270
virtual TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition: tag.h:215
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
Definition: tag.h:205
virtual std::string_view typeName() const
Returns the type name of the tag as C-style string.
Definition: tag.h:210
virtual bool hasField(KnownField field) const =0
Returns an indication whether the specified field is present.
virtual void removeAllFields()=0
Removes all fields from the tag.
TagTarget m_target
Definition: tag.h:202
virtual TagTargetLevel targetLevel() const
Returns the name of the current tag target level.
Definition: tag.h:255
const TagTarget & target() const
Definition: tag.h:240
virtual bool setValue(KnownField field, const TagValue &value)=0
Assigns the given value to the specified field.
virtual TagDataType proposedDataType(KnownField field) const
Returns the proposed data type for the specified field as TagDataType.
Definition: tag.h:275
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:220
virtual bool supportsMultipleValues(KnownField field) const
Returns an indications whether the specified field supports multiple values.
Definition: tag.h:317
virtual void ensureTextValuesAreProperlyEncoded()=0
Ensures the encoding of all assigned text values is supported by the tag by converting the character ...
virtual bool supportsMimeType(KnownField field) const
Returns an indications whether the specified field supports mime types.
Definition: tag.h:312
virtual bool supportsField(KnownField field) const =0
Returns an indication whether the specified field is supported by the tag.
virtual const TagValue & value(KnownField field) const =0
Returns the value of the specified field.
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition: tag.h:235
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
constexpr TAG_PARSER_EXPORT std::string_view version()
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
KnownField
Specifies the field.
Definition: tag.h:28
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:143
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:157
TagTextEncoding
Specifies the text encoding.
Definition: tagvalue.h:29
constexpr KnownField lastKnownField
The last valid entry in the TagParser::KnownField enum.
Definition: tag.h:138
TagType
Specifies the tag type.
Definition: tagtype.h:11
constexpr KnownField firstKnownField
The first valid entry in the TagParser::KnownField enum.
Definition: tag.h:133
constexpr bool isKnownFieldDeprecated(KnownField field)
Returns whether the specified field is deprecated and should not be used anymore.
Definition: tag.h:148
TagDataType
Specifies the data type.
Definition: tagvalue.h:119