Tag Parser 12.2.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
29enum class KnownField : unsigned int {
30 Invalid = std::numeric_limits<unsigned int>::max(),
31 Title = 0,
32 Album,
33 Artist,
34 Genre,
35 Comment,
36 Bpm,
37 Bps,
38 Lyricist,
43 Encoder,
46 Length,
47 Language,
49 Lyrics,
51 Grouping,
53 Cover,
54 Composer,
55 Rating,
57 Vendor,
62 Arranger,
63 Conductor,
64 Director,
72 Actor,
73 Character,
74 WrittenBy,
76 EditedBy,
77 Producer,
82 EncodedBy,
83 MixedBy,
84 RemixedBy,
86 ThanksTo,
87 Publisher,
88 Mood,
91 Subject,
92 Keywords,
93 Summary,
94 Synopsis,
96 Period,
97 LawRating,
108 Measure,
109 Tuning,
110 ISRC,
111 MCDI,
112 ISBN,
113 Barcode,
115 LabelCode,
116 LCCN,
117 IMDB,
118 TMDB,
119 TVDB,
125 Copyright,
127 License,
128 TermsOfUse,
130};
131
136
141
145constexpr unsigned int knownFieldArraySize = static_cast<unsigned int>(lastKnownField) + 1;
146
151{
152 CPP_UTILITIES_UNUSED(field)
153 return false;
154}
155
160{
161 const auto next = field == lastKnownField ? KnownField::Invalid : static_cast<KnownField>(static_cast<int>(field) + 1);
162 return isKnownFieldDeprecated(next) ? nextKnownField(next) : next;
163}
164
165struct TagPrivate;
166
167class TAG_PARSER_EXPORT Tag {
168public:
169 virtual ~Tag();
170
171 virtual TagType type() const;
172 virtual std::string_view typeName() const;
173 std::string toString() const;
174 virtual TagTextEncoding proposedTextEncoding() const;
175 virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
176 virtual const TagValue &value(KnownField field) const = 0;
177 virtual std::vector<const TagValue *> values(KnownField field) const;
178 virtual bool setValue(KnownField field, const TagValue &value) = 0;
179 virtual bool setValues(KnownField field, const std::vector<TagValue> &values);
180 virtual bool hasField(KnownField field) const = 0;
181 virtual void removeAllFields() = 0;
182 const std::string &version() const;
183 std::uint64_t size() const;
184 virtual bool supportsTarget() const;
185 const TagTarget &target() const;
186 TagTarget &target();
187 void setTarget(const TagTarget &target);
188 virtual TagTargetLevel targetLevel() const;
189 std::string_view targetLevelName() const;
190 bool isTargetingLevel(TagTargetLevel tagTargetLevel) const;
191 std::string targetString() const;
192 virtual std::size_t fieldCount() const = 0;
193 virtual bool supportsField(KnownField field) const = 0;
194 virtual TagDataType proposedDataType(KnownField field) const;
195 virtual bool supportsDescription(KnownField field) const;
196 virtual bool supportsMimeType(KnownField field) const;
197 virtual bool supportsMultipleValues(KnownField field) const;
198 virtual std::size_t insertValues(const Tag &from, bool overwrite);
200
201protected:
202 Tag();
203
204 std::string m_version;
205 std::uint64_t m_size;
206 std::unique_ptr<TagPrivate> m_p;
208};
209
210inline TagType Tag::type() const
211{
213}
214
215inline std::string_view Tag::typeName() const
216{
217 return "unspecified";
218}
219
224
225inline bool Tag::canEncodingBeUsed(TagTextEncoding encoding) const
226{
227 return encoding == proposedTextEncoding();
228}
229
230inline const std::string &Tag::version() const
231{
232 return m_version;
233}
234
235inline std::uint64_t Tag::size() const
236{
237 return m_size;
238}
239
240inline bool Tag::supportsTarget() const
241{
242 return false;
243}
244
245inline const TagTarget &Tag::target() const
246{
247 return m_target;
248}
249
251{
252 return m_target;
253}
254
255inline void Tag::setTarget(const TagTarget &target)
256{
258}
259
264
265inline std::string_view Tag::targetLevelName() const
266{
267 return supportsTarget() ? tagTargetLevelName(targetLevel()) : std::string_view();
268}
269
270inline bool Tag::isTargetingLevel(TagTargetLevel tagTargetLevel) const
271{
272 return !supportsTarget() || static_cast<std::uint8_t>(targetLevel()) >= static_cast<std::uint8_t>(tagTargetLevel);
273}
274
275inline std::string Tag::targetString() const
276{
277 return target().toString(targetLevel());
278}
279
281{
282 switch (field) {
283 case KnownField::Bpm:
284 case KnownField::Bps:
298 case KnownField::MCDI:
299 return TagDataType::Binary;
301 // could also be a plain integer but popularity should generally be used (and can be converted
302 // to an integer)
305 // not supported
307 default:
308 return TagDataType::Text;
309 }
310}
311
313{
314 return false;
315}
316
318{
319 return false;
320}
321
323{
324 return false;
325}
326
327} // namespace TagParser
328
329#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:260
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:204
std::uint64_t m_size
Definition tag.h:205
std::uint64_t size() const
Returns the size the tag within the file it is parsed from in bytes.
Definition tag.h:235
void setTarget(const TagTarget &target)
Sets the target of tag.
Definition tag.h:255
std::unique_ptr< TagPrivate > m_p
Definition tag.h:206
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:225
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition tag.h:240
std::string_view targetLevelName() const
Returns the name of the current target level.
Definition tag.h:265
virtual TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition tag.h:220
virtual std::string_view typeName() const
Returns the type name of the tag as C-style string.
Definition tag.h:215
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
Definition tag.h:210
TagTarget m_target
Definition tag.h:207
const TagTarget & target() const
Definition tag.h:245
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:280
virtual bool supportsMultipleValues(KnownField field) const
Returns an indications whether the specified field supports multiple values.
Definition tag.h:322
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:270
const std::string & version() const
Returns the version of the tag as std::string.
Definition tag.h:230
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:317
virtual bool supportsDescription(KnownField field) const
Returns an indications whether the specified field supports descriptions.
Definition tag.h:312
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:275
#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:29
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:145
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:159
TagTextEncoding
Specifies the text encoding.
Definition tagvalue.h:29
constexpr KnownField lastKnownField
The last valid entry in the TagParser::KnownField enum.
Definition tag.h:140
TagType
Specifies the tag type.
Definition tagtype.h:11
constexpr KnownField firstKnownField
The first valid entry in the TagParser::KnownField enum.
Definition tag.h:135
constexpr bool isKnownFieldDeprecated(KnownField field)
Returns whether the specified field is deprecated and should not be used anymore.
Definition tag.h:150
TagDataType
Specifies the data type.
Definition tagvalue.h:119