Tag Parser  9.1.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.front() : TagValue());
76 }
77 
86 unsigned int Tag::insertValues(const Tag &from, bool overwrite)
87 {
88  unsigned int count = 0;
89  for (int i = static_cast<int>(KnownField::Invalid) + 1, last = static_cast<int>(KnownField::Description); i <= last; ++i) {
90  KnownField 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 
323 } // namespace TagParser
TagParser::KnownField::Description
TagParser::Tag::setValues
virtual bool setValues(KnownField field, const std::vector< TagValue > &values)
Assigns the given values to the specified field.
Definition: tag.cpp:73
TagParser::Tag
The Tag class is used to store, read and write tag information.
Definition: tag.h:98
TagParser
Contains all classes and functions of the TagInfo library.
Definition: aaccodebook.h:10
TagParser::TagValue::isEmpty
bool isEmpty() const
Returns whether an empty value is assigned.
Definition: tagvalue.h:449
TagParser::Tag::values
virtual std::vector< const TagValue * > values(KnownField field) const
Returns the values of the specified field.
Definition: tag.cpp:55
TagParser::KnownField::Invalid
TagParser::Tag::value
virtual const TagValue & value(KnownField field) const =0
Returns the value of the specified field.
TagParser::Tag::insertValues
virtual unsigned int insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
Definition: tag.cpp:86
TagParser::KnownField
KnownField
Specifies the field.
Definition: tag.h:42
TagParser::Tag::typeName
virtual const char * typeName() const
Returns the type name of the tag as C-style string.
Definition: tag.h:144
TagParser::Tag::toString
std::string toString() const
Returns a string representation of the tag.
Definition: tag.cpp:36
TagParser::Tag::supportsTarget
virtual bool supportsTarget() const
Returns an indication whether a target is supported by the tag.
Definition: tag.h:169
TagParser::Tag::targetString
std::string targetString() const
Returns the string representation for the assigned tag target.
Definition: tag.h:199
TagParser::TagValue
The TagValue class wraps values of different types. It is meant to be assigned to a tag field.
Definition: tagvalue.h:75
TagParser::MatroskaIds::Tag
Definition: matroskaid.h:204
tag.h
TagParser::Tag::~Tag
virtual ~Tag()
Destroys the Tag.
Definition: tag.cpp:29
TagParser::Tag::setValue
virtual bool setValue(KnownField field, const TagValue &value)=0
Assigns the given value to the specified field.