Tag Parser
9.3.0
C++ library for reading and writing MP4 (iTunes), ID3, Vorbis, Opus, FLAC and Matroska tags
|
Go to the documentation of this file. 1 #ifndef TAG_PARSER_FIELDBASEDTAG_H
2 #define TAG_PARSER_FIELDBASEDTAG_H
55 const std::multimap<IdentifierType, FieldType, Compare> &
fields()
const;
56 std::multimap<IdentifierType, FieldType, Compare> &
fields();
80 std::multimap<IdentifierType, FieldType, Compare> m_fields;
106 return ImplementationType::tagType;
111 return ImplementationType::tagName;
116 return ImplementationType::defaultTextEncoding;
125 auto i = m_fields.find(
id);
133 template <
class ImplementationType>
136 auto range = m_fields.equal_range(
id);
137 std::vector<const TagValue *> values;
138 for (
auto i = range.first; i != range.second; ++i) {
139 if (!i->second.value().isEmpty()) {
140 values.push_back(&i->second.value());
152 return static_cast<const ImplementationType *
>(
this)->internallyGetValue(
id);
157 return value(fieldId(field));
166 return static_cast<const ImplementationType *
>(
this)->internallyGetValues(
id);
171 return static_cast<const ImplementationType *
>(
this)->values(fieldId(field));
176 return setValue(fieldId(field), value);
185 auto i = m_fields.find(
id);
186 if (i != m_fields.end()) {
187 i->second.setValue(value);
189 m_fields.insert(std::make_pair(
id,
FieldType(
id, value)));
200 template <
class ImplementationType>
203 auto valuesIterator = values.cbegin();
204 auto range = m_fields.equal_range(
id);
206 for (; valuesIterator != values.cend() && range.first != range.second; ++valuesIterator) {
208 if (!valuesIterator->isEmpty()) {
209 range.first->second.setValue(*valuesIterator);
214 for (; valuesIterator != values.cend(); ++valuesIterator) {
215 m_fields.insert(std::make_pair(
id,
FieldType(
id, *valuesIterator)));
218 for (; range.first != range.second; ++range.first) {
219 range.first->second.setValue(
TagValue());
230 return static_cast<ImplementationType *
>(
this)->internallySetValue(
id, value);
239 template <
class ImplementationType>
242 return static_cast<ImplementationType *
>(
this)->internallySetValues(
id, values);
253 return setValues(fieldId(field), values);
258 return hasField(fieldId(field));
267 for (
auto range = m_fields.equal_range(
id); range.first != range.second; ++range.first) {
268 if (!range.first->second.value().isEmpty()) {
280 return static_cast<const ImplementationType *
>(
this)->internallyHasField(
id);
291 template <
class ImplementationType>
307 unsigned int count = 0;
308 for (
const auto &field : m_fields) {
309 if (!field.second.value().isEmpty()) {
320 template <
class ImplementationType>
323 return static_cast<const ImplementationType *
>(
this)->internallyGetFieldId(value);
332 return static_cast<const ImplementationType *
>(
this)->internallyGetKnownField(
id);
338 return fieldId(field) != def;
345 template <
class ImplementationType>
356 return static_cast<ImplementationType *
>(
this)->determineProposedDataType(
id);
365 template <
class ImplementationType>
368 int fieldsInserted = 0;
369 for (
const auto &pair : from.
fields()) {
370 const FieldType &fromField = pair.second;
371 if (fromField.value().isEmpty()) {
374 bool fieldInserted =
false;
375 auto range = fields().equal_range(fromField.id());
376 for (
auto i = range.first; i != range.second; ++i) {
378 if ((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned() && fromField.typeInfo() == ownField.typeInfo())
379 || (!fromField.isTypeInfoAssigned() && !ownField.isTypeInfoAssigned())) {
380 if (overwrite || ownField.value().isEmpty()) {
381 ownField = fromField;
384 fieldInserted =
true;
388 if (!fieldInserted) {
389 fields().insert(std::make_pair(fromField.id(), fromField));
393 return fieldsInserted;
398 if (type() == from.
type()) {
408 for (
auto &field : fields()) {
409 field.second.value().convertDataEncodingForTag(
this);
415 #endif // TAG_PARSER_FIELDBASEDTAG_H
void ensureTextValuesAreProperlyEncoded()
Ensures the encoding of all assigned text values is supported by the tag by converting the character ...
TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
FieldMapBasedTag()
Constructs a new FieldMapBasedTag.
bool hasField(KnownField field) const
Returns an indication whether the specified field is present.
bool supportsField(KnownField field) const
Returns an indication whether the specified field is supported by the tag.
bool setValue(const IdentifierType &id, const TagValue &value)
Assigns the given value to the field with the specified id.
const TagValue & internallyGetValue(const IdentifierType &id) const
Default implementation for value().
typename FieldMapBasedTagTraits< Mp4Tag >::FieldType::IdentifierType IdentifierType
TagTextEncoding
Specifies the text encoding.
bool setValues(const IdentifierType &id, const std::vector< TagValue > &values)
Assigns the given values to the field with the specified id.
const TagValue & value(KnownField field) const
Returns the value of the specified field.
const TagValue & value(const IdentifierType &id) const
Returns the value of the field with the specified id.
virtual TagDataType proposedDataType(KnownField field) const
Returns the proposed data type for the specified field as TagDataType.
std::vector< const TagValue * > values(const IdentifierType &id) const
Returns the values of the field with the specified id.
The Tag class is used to store, read and write tag information.
const char * typeName() const
Returns the type name of the tag as C-style string.
typename FieldMapBasedTagTraits< Mp4Tag >::FieldType FieldType
Contains all classes and functions of the TagInfo library.
TagDataType internallyGetProposedDataType(const IdentifierType &id) const
Default implementation for proposedDataType().
bool internallyHasField(const IdentifierType &id) const
Default implementation for hasField().
KnownField knownField(const IdentifierType &id) const
Returns the field for the specified ID.
TagDataType
Specifies the data type.
bool isEmpty() const
Returns whether no or an empty value is assigned.
void removeAllFields()
Removes all fields from the tag.
std::multimap< IdentifierType, FieldType, Compare > & fields()
Returns the fields of the tag by providing direct access to the field map of the tag.
TagType type() const
Returns the type of the tag as TagParser::TagType.
std::vector< const TagValue * > values(KnownField field) const
Returns the values of the specified field.
virtual unsigned int insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
unsigned int insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
KnownField
Specifies the field.
bool hasField(const IdentifierType &id) const
Returns an indication whether the field with the specified id is present.
TagDataType proposedDataType(const IdentifierType &id) const
Returns the proposed data type for the field with the specified id.
const std::multimap< IdentifierType, FieldType, Compare > & fields() const
Returns the fields of the tag by providing direct access to the field map of the tag.
The FieldMapBasedTag provides a generic implementation of Tag which stores the tag fields using std::...
The TagValue class wraps values of different types.
bool setValues(KnownField field, const std::vector< TagValue > &values)
Assigns the given values to the field with the specified id.
int insertFields(const FieldMapBasedTag< ImplementationType > &from, bool overwrite)
Inserts all fields from another tag of the same field type and compare function.
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
typename FieldMapBasedTagTraits< Mp4Tag >::Compare Compare
bool setValue(KnownField field, const TagValue &value)
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.
IdentifierType fieldId(KnownField value) const
Returns the ID for the specified field.
Defines traits for the specified ImplementationType.
bool internallySetValues(const IdentifierType &id, const std::vector< TagValue > &values)
Default implementation for setValues().
static const TagValue & empty()
Returns a default-constructed TagValue where TagValue::isNull() and TagValue::isEmpty() both return t...
std::vector< const TagValue * > internallyGetValues(const IdentifierType &id) const
Default implementation for values().
TagType
Specifies the tag type.
bool internallySetValue(const IdentifierType &id, const TagValue &value)
Default implementation for setValue().
unsigned int fieldCount() const
Returns the number of present fields.