Tag Parser 11.2.1
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
tag.cpp
Go to the documentation of this file.
1#include "./tag.h"
2
3using namespace std;
4
5namespace TagParser {
6
22 : m_size(0)
23{
24}
25
30{
31}
32
36string Tag::toString() const
37{
38 string res;
39 res += typeName();
40 if (supportsTarget()) {
41 res += " targeting ";
42 res += targetString();
43 }
44 return res;
45}
46
55std::vector<const TagValue *> Tag::values(KnownField field) const
56{
57 std::vector<const TagValue *> values;
58 const TagValue &v = value(field);
59 if (!v.isEmpty()) {
60 values.push_back(&v);
61 }
62 return values;
63}
64
73bool Tag::setValues(KnownField field, const std::vector<TagValue> &values)
74{
75 return setValue(field, values.size() ? values.front() : TagValue());
76}
77
86std::size_t Tag::insertValues(const Tag &from, bool overwrite)
87{
88 auto count = std::size_t(0);
89 for (int i = static_cast<int>(KnownField::Invalid) + 1, last = static_cast<int>(KnownField::Description); i <= last; ++i) {
90 auto field = static_cast<KnownField>(i);
91 const TagValue &ownValue = value(field);
92 if (overwrite || ownValue.isEmpty()) {
93 const TagValue &otherValue = from.value(field);
94 if (!otherValue.isEmpty() && setValue(field, otherValue)) {
95 ++count;
96 }
97 }
98 }
99 return count;
100}
101
329} // namespace TagParser
The TagValue class wraps values of different types.
Definition: tagvalue.h:95
bool isEmpty() const
Returns whether no or an empty value is assigned.
Definition: tagvalue.h:525
The Tag class is used to store, read and write tag information.
Definition: tag.h:177
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition: tag.h:284
virtual std::size_t insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
Definition: tag.cpp:86
std::string toString() const
Returns a string representation of the tag.
Definition: tag.cpp:36
virtual std::string_view typeName() const
Returns the type name of the tag as C-style string.
Definition: tag.h:224
virtual bool setValue(KnownField field, const TagValue &value)=0
Assigns the given value to the specified field.
virtual ~Tag()
Destroys the Tag.
Definition: tag.cpp:29
Tag()
Constructs a new Tag.
Definition: tag.cpp:21
virtual const TagValue & value(KnownField field) const =0
Returns the value of the specified field.
virtual std::vector< const TagValue * > values(KnownField field) const
Returns the values of the specified field.
Definition: tag.cpp:55
virtual bool setValues(KnownField field, const std::vector< TagValue > &values)
Assigns the given values to the specified field.
Definition: tag.cpp:73
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition: tag.h:249
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
KnownField
Specifies the field.
Definition: tag.h:42