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.cpp
Go to the documentation of this file.
1#include "./tag.h"
2
3using namespace std;
4
5namespace TagParser {
6
8struct TagPrivate {};
9
25 : m_size(0)
26{
27}
28
33{
34}
35
39string Tag::toString() const
40{
41 string res;
42 res += typeName();
43 if (supportsTarget()) {
44 res += " targeting ";
45 res += targetString();
46 }
47 return res;
48}
49
58std::vector<const TagValue *> Tag::values(KnownField field) const
59{
60 std::vector<const TagValue *> values;
61 const TagValue &v = value(field);
62 if (!v.isEmpty()) {
63 values.push_back(&v);
64 }
65 return values;
66}
67
76bool Tag::setValues(KnownField field, const std::vector<TagValue> &values)
77{
78 return setValue(field, values.size() ? values.front() : TagValue());
79}
80
89std::size_t Tag::insertValues(const Tag &from, bool overwrite)
90{
91 auto count = std::size_t(0);
92 for (int i = static_cast<int>(KnownField::Invalid) + 1, last = static_cast<int>(KnownField::Description); i <= last; ++i) {
93 auto field = static_cast<KnownField>(i);
94 const TagValue &ownValue = value(field);
95 if (overwrite || ownValue.isEmpty()) {
96 const TagValue &otherValue = from.value(field);
97 if (!otherValue.isEmpty() && setValue(field, otherValue)) {
98 ++count;
99 }
100 }
101 }
102 return count;
103}
104
332} // namespace TagParser
The TagValue class wraps values of different types.
Definition tagvalue.h:147
bool isEmpty() const
Returns whether no or an empty value is assigned.
Definition tagvalue.h:490
The Tag class is used to store, read and write tag information.
Definition tag.h:166
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition tag.h:274
virtual std::size_t insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
Definition tag.cpp:89
std::string toString() const
Returns a string representation of the tag.
Definition tag.cpp:39
virtual std::string_view typeName() const
Returns the type name of the tag as C-style string.
Definition tag.h:214
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:32
Tag()
Constructs a new Tag.
Definition tag.cpp:24
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:58
virtual bool setValues(KnownField field, const std::vector< TagValue > &values)
Assigns the given values to the specified field.
Definition tag.cpp:76
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition tag.h:239
Contains all classes and functions of the TagInfo library.
Definition aaccodebook.h:10
KnownField
Specifies the field.
Definition tag.h:29
The TagPrivate struct contains private fields of the Tag class.
Definition tag.cpp:8