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
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().
The FieldMapBasedTag provides a generic implementation of Tag which stores the tag fields using std::...
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.
The Tag class is used to store, read and write tag information.
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.
typename FieldMapBasedTagTraits< MatroskaTag >::FieldType::IdentifierType IdentifierType
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.
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
typename FieldMapBasedTagTraits< MatroskaTag >::FieldType FieldType
Defines traits for the specified ImplementationType.
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 TagParser::TagType.
static const TagValue & empty()
Returns an empty TagValue.
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.
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.
bool internallySetValues(const IdentifierType &id, const std::vector< TagValue > &values)
Default implementation for setValues().
typename FieldMapBasedTagTraits< MatroskaTag >::Compare Compare
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.
The TagValue class wraps values of different types.
std::vector< const TagValue * > internallyGetValues(const IdentifierType &id) const
Default implementation for values().
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.
Contains all classes and functions of the TagInfo library.
TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.