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();
76 std::multimap<IdentifierType, FieldType, Compare> m_fields;
102 return ImplementationType::tagType;
107 return ImplementationType::tagName;
112 return ImplementationType::defaultTextEncoding;
121 auto i = m_fields.find(
id);
131 return static_cast<const ImplementationType *
>(
this)->internallyGetValue(
id);
136 return value(fieldId(field));
145 auto range = m_fields.equal_range(
id);
146 std::vector<const TagValue *> values;
147 for (
auto i = range.first; i != range.second; ++i) {
148 if (!i->second.value().isEmpty()) {
149 values.push_back(&i->second.value());
157 return values(fieldId(field));
162 return setValue(fieldId(field), value);
171 auto i = m_fields.find(
id);
172 if (i != m_fields.end()) {
173 i->second.setValue(value);
175 m_fields.insert(std::make_pair(
id,
FieldType(
id, value)));
188 return static_cast<ImplementationType *
>(
this)->internallySetValue(
id, value);
197 template <
class ImplementationType>
200 auto valuesIterator = values.cbegin();
201 auto range = m_fields.equal_range(
id);
203 for (; valuesIterator != values.cend() && range.first != range.second; ++valuesIterator) {
205 if (!valuesIterator->isEmpty()) {
206 range.first->second.setValue(*valuesIterator);
211 for (; valuesIterator != values.cend(); ++valuesIterator) {
212 m_fields.insert(std::make_pair(
id,
FieldType(
id, *valuesIterator)));
215 for (; range.first != range.second; ++range.first) {
216 range.first->second.setValue(
TagValue());
229 return setValues(fieldId(field), values);
234 return hasField(fieldId(field));
243 for (
auto range = m_fields.equal_range(
id); range.first != range.second; ++range.first) {
244 if (!range.first->second.value().isEmpty()) {
256 return static_cast<const ImplementationType *
>(
this)->internallyHasField(
id);
267 template <
class ImplementationType>
283 unsigned int count = 0;
284 for (
const auto &field : m_fields) {
285 if (!field.second.value().isEmpty()) {
296 template <
class ImplementationType>
299 return static_cast<const ImplementationType *
>(
this)->internallyGetFieldId(value);
314 return fieldId(field) != def;
321 template <
class ImplementationType>
332 return static_cast<ImplementationType *
>(
this)->determineProposedDataType(
id);
341 template <
class ImplementationType>
344 int fieldsInserted = 0;
345 for (
const auto &pair : from.
fields()) {
346 const FieldType &fromField = pair.second;
347 if (fromField.value().isEmpty()) {
350 bool fieldInserted =
false;
351 auto range = fields().equal_range(fromField.id());
352 for (
auto i = range.first; i != range.second; ++i) {
354 if ((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned() && fromField.typeInfo() == ownField.typeInfo())
355 || (!fromField.isTypeInfoAssigned() && !ownField.isTypeInfoAssigned())) {
356 if (overwrite || ownField.value().isEmpty()) {
357 ownField = fromField;
360 fieldInserted =
true;
364 if (!fieldInserted) {
365 fields().insert(std::make_pair(fromField.id(), fromField));
369 return fieldsInserted;
374 if (type() == from.
type()) {
384 for (
auto &field : fields()) {
385 field.second.value().convertDataEncodingForTag(
this);
391 #endif // TAG_PARSER_FIELDBASEDTAG_H
virtual TagDataType proposedDataType(KnownField field) const
Returns the proposed data type for the specified field as TagDataType.
FieldMapBasedTagTraits< ImplementationType >::FieldType::IdentifierType IdentifierType
bool supportsField(KnownField field) const
Returns an indication whether the specified field is supported by the tag.
const TagValue & internallyGetValue(const IdentifierType &id) const
Default implementation for value().
bool internallySetValue(const IdentifierType &id, const TagValue &value)
Default implementation for setValue().
unsigned int fieldCount() const
Returns the number of present fields.
void ensureTextValuesAreProperlyEncoded()
Ensures the encoding of all assigned text values is supported by the tag by converting the character ...
bool setValues(const IdentifierType &id, const std::vector< TagValue > &values)
Assigns the given values to the field with the specified id.
FieldMapBasedTag()
Constructs a new FieldMapBasedTag.
const TagValue & value(const IdentifierType &id) const
Returns the value of the field with the specified id.
bool hasField(KnownField field) const
Returns an indication whether the specified field is present.
bool setValue(const IdentifierType &id, const TagValue &value)
Assigns the given value to the field with the specified id.
FieldMapBasedTagTraits< ImplementationType >::Compare Compare
const char * typeName() const
Returns the type name of the tag as C-style string.
TagDataType
Specifies the data type.
TagDataType internallyGetProposedDataType(const IdentifierType &id) const
Default implementation for proposedDataType().
KnownField knownField(const IdentifierType &id) const
Returns the field for the specified ID.
std::vector< const TagValue * > values(const IdentifierType &id) const
Returns the values of the field with the specified id.
KnownField
Specifies the field.
bool internallyHasField(const IdentifierType &id) const
Default implementation for hasField().
bool isEmpty() const
Returns an indication whether an value is assigned.
TagType type() const
Returns the type of the tag as Media::TagType.
static const TagValue & empty()
Returns an empty TagValue.
FieldMapBasedTagTraits< ImplementationType >::FieldType FieldType
void removeAllFields()
Removes all fields from the tag.
unsigned int insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
TagDataType proposedDataType(const IdentifierType &id) const
Returns the proposed data type for the field with the specified id.
virtual TagType type() const
Returns the type of the tag as Media::TagType.
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.
int insertFields(const FieldMapBasedTag< ImplementationType > &from, bool overwrite)
Inserts all fields from another tag of the same field type and compare function.
IdentifierType fieldId(KnownField value) const
Returns the ID for the specified field.
TagType
Specifies the tag type.
virtual unsigned int insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
TagTextEncoding
Specifies the text encoding.
TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.