Tag Parser 12.1.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,
129};
130
135
140
144constexpr unsigned int knownFieldArraySize = static_cast<unsigned int>(lastKnownField) + 1;
145
150{
151 CPP_UTILITIES_UNUSED(field)
152 return false;
153}
154
159{
160 const auto next = field == lastKnownField ? KnownField::Invalid : static_cast<KnownField>(static_cast<int>(field) + 1);
161 return isKnownFieldDeprecated(next) ? nextKnownField(next) : next;
162}
163
164struct TagPrivate;
165
167public:
168 virtual ~Tag();
169
170 virtual TagType type() const;
171 virtual std::string_view typeName() const;
172 std::string toString() const;
173 virtual TagTextEncoding proposedTextEncoding() const;
174 virtual bool canEncodingBeUsed(TagTextEncoding encoding) const;
175 virtual const TagValue &value(KnownField field) const = 0;
176 virtual std::vector<const TagValue *> values(KnownField field) const;
177 virtual bool setValue(KnownField field, const TagValue &value) = 0;
178 virtual bool setValues(KnownField field, const std::vector<TagValue> &values);
179 virtual bool hasField(KnownField field) const = 0;
180 virtual void removeAllFields() = 0;
181 const std::string &version() const;
182 std::uint64_t size() const;
183 virtual bool supportsTarget() const;
184 const TagTarget &target() const;
185 TagTarget &target();
186 void setTarget(const TagTarget &target);
187 virtual TagTargetLevel targetLevel() const;
188 std::string_view targetLevelName() const;
189 bool isTargetingLevel(TagTargetLevel tagTargetLevel) const;
190 std::string targetString() const;
191 virtual std::size_t fieldCount() const = 0;
192 virtual bool supportsField(KnownField field) const = 0;
193 virtual TagDataType proposedDataType(KnownField field) const;
194 virtual bool supportsDescription(KnownField field) const;
195 virtual bool supportsMimeType(KnownField field) const;
196 virtual bool supportsMultipleValues(KnownField field) const;
197 virtual std::size_t insertValues(const Tag &from, bool overwrite);
199
200protected:
201 Tag();
202
203 std::string m_version;
204 std::uint64_t m_size;
205 std::unique_ptr<TagPrivate> m_p;
207};
208
209inline TagType Tag::type() const
210{
212}
213
214inline std::string_view Tag::typeName() const
215{
216 return "unspecified";
217}
218
223
224inline bool Tag::canEncodingBeUsed(TagTextEncoding encoding) const
225{
226 return encoding == proposedTextEncoding();
227}
228
229inline const std::string &Tag::version() const
230{
231 return m_version;
232}
233
234inline std::uint64_t Tag::size() const
235{
236 return m_size;
237}
238
239inline bool Tag::supportsTarget() const
240{
241 return false;
242}
243
244inline const TagTarget &Tag::target() const
245{
246 return m_target;
247}
248
250{
251 return m_target;
252}
253
254inline void Tag::setTarget(const TagTarget &target)
255{
257}
258
263
264inline std::string_view Tag::targetLevelName() const
265{
266 return supportsTarget() ? tagTargetLevelName(targetLevel()) : std::string_view();
267}
268
269inline bool Tag::isTargetingLevel(TagTargetLevel tagTargetLevel) const
270{
271 return !supportsTarget() || static_cast<std::uint8_t>(targetLevel()) >= static_cast<std::uint8_t>(tagTargetLevel);
272}
273
274inline std::string Tag::targetString() const
275{
276 return target().toString(targetLevel());
277}
278
280{
281 switch (field) {
282 case KnownField::Bpm:
283 case KnownField::Bps:
297 case KnownField::MCDI:
298 return TagDataType::Binary;
300 // could also be a plain integer but popularity should generally be used (and can be converted
301 // to an integer)
304 // not supported
306 default:
307 return TagDataType::Text;
308 }
309}
310
312{
313 return false;
314}
315
317{
318 return false;
319}
320
322{
323 return false;
324}
325
326} // namespace TagParser
327
328#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:147
The Tag class is used to store, read and write tag information.
Definition tag.h:166
std::uint64_t size() const
Returns the size the tag within the file it is parsed from in bytes.
Definition tag.h:234
std::string_view targetLevelName() const
Returns the name of the current target level.
Definition tag.h:264
void setTarget(const TagTarget &target)
Sets the target of tag.
Definition tag.h:254
bool isTargetingLevel(TagTargetLevel tagTargetLevel) const
Returns whether the tag is targeting the specified tagTargetLevel.
Definition tag.h:269
std::string m_version
Definition tag.h:203
std::uint64_t m_size
Definition tag.h:204
std::unique_ptr< TagPrivate > m_p
Definition tag.h:205
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:229
virtual bool supportsDescription(KnownField field) const
Returns an indications whether the specified field supports descriptions.
Definition tag.h:311
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition tag.h:274
virtual TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
Definition tag.h:219
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
Definition tag.h:209
virtual std::string_view typeName() const
Returns the type name of the tag as C-style string.
Definition tag.h:214
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:206
virtual TagTargetLevel targetLevel() const
Returns the name of the current tag target level.
Definition tag.h:259
const TagTarget & target() const
Definition tag.h:244
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:279
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:224
virtual bool supportsMultipleValues(KnownField field) const
Returns an indications whether the specified field supports multiple values.
Definition tag.h:321
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:316
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:239
#define TAG_PARSER_EXPORT
Marks the symbol to be exported by the tagparser library.
Definition global.h:13
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:144
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:158
TagTextEncoding
Specifies the text encoding.
Definition tagvalue.h:29
constexpr KnownField lastKnownField
The last valid entry in the TagParser::KnownField enum.
Definition tag.h:139
TagType
Specifies the tag type.
Definition tagtype.h:11
constexpr KnownField firstKnownField
The first valid entry in the TagParser::KnownField enum.
Definition tag.h:134
constexpr bool isKnownFieldDeprecated(KnownField field)
Returns whether the specified field is deprecated and should not be used anymore.
Definition tag.h:149
TagDataType
Specifies the data type.
Definition tagvalue.h:119