Tag Parser  7.0.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 
3 using namespace std;
4 
5 namespace TagParser {
6 
22  : m_size(0)
23 {
24 }
25 
30 {
31 }
32 
36 string 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 
55 std::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 
73 bool Tag::setValues(KnownField field, const std::vector<TagValue> &values)
74 {
75  return setValue(field, values.size() ? *values.begin() : TagValue());
76 }
77 
129 unsigned int Tag::insertValues(const Tag &from, bool overwrite)
130 {
131  unsigned int count = 0;
132  for (int i = static_cast<int>(KnownField::Invalid) + 1, last = static_cast<int>(KnownField::Description); i <= last; ++i) {
133  KnownField field = static_cast<KnownField>(i);
134  const TagValue &ownValue = value(field);
135  if (overwrite || ownValue.isEmpty()) {
136  const TagValue &otherValue = from.value(field);
137  if (!otherValue.isEmpty() && setValue(field, otherValue)) {
138  ++count;
139  }
140  }
141  }
142  return count;
143 }
144 
151 } // namespace TagParser
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition: tag.h:282
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition: tag.h:221
virtual ~Tag()
Destroys the Tag.
Definition: tag.cpp:29
STL namespace.
KnownField
Specifies the field.
Definition: tag.h:40
virtual bool setValue(KnownField field, const TagValue &value)=0
Assigns the given value to the specified field.
std::string toString() const
Returns a string representation of the tag.
Definition: tag.cpp:36
bool isEmpty() const
Returns an indication whether an value is assigned.
Definition: tagvalue.h:367
virtual bool setValues(KnownField field, const std::vector< TagValue > &values)
Assigns the given values to the specified field.
Definition: tag.cpp:73
virtual unsigned int insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
Definition: tag.cpp:129
virtual std::vector< const TagValue * > values(KnownField field) const
Returns the values of the specified field.
Definition: tag.cpp:55
virtual const char * typeName() const
Returns the type name of the tag as C-style string.
Definition: tag.h:152
virtual const TagValue & value(KnownField field) const =0
Returns the value of the specified field.