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();
81 std::multimap<IdentifierType, FieldType, Compare> m_fields;
107 return ImplementationType::tagType;
112 return ImplementationType::tagName;
117 return ImplementationType::defaultTextEncoding;
126 auto i = m_fields.find(
id);
134template <
class ImplementationType>
139 values.emplace_back(&field.
value());
147template <
class ImplementationType>
150 auto range = m_fields.equal_range(
id);
151 std::vector<const TagValue *> values;
152 for (
auto i = range.first; i != range.second; ++i) {
153 static_cast<const ImplementationType *
>(
this)->internallyGetValuesFromField(i->second, values);
164 return static_cast<const ImplementationType *
>(
this)->internallyGetValue(
id);
169 return value(fieldId(field));
178 return static_cast<const ImplementationType *
>(
this)->internallyGetValues(
id);
183 return static_cast<const ImplementationType *
>(
this)->values(fieldId(field));
188 return setValue(fieldId(field), value);
197 auto i = m_fields.find(
id);
198 if (i != m_fields.end()) {
199 i->second.setValue(value);
201 m_fields.insert(std::make_pair(
id,
FieldType(
id, value)));
212template <
class ImplementationType>
215 auto valuesIterator = values.cbegin();
216 auto range = m_fields.equal_range(
id);
218 for (; valuesIterator != values.cend() && range.first != range.second; ++valuesIterator) {
220 if (!valuesIterator->isEmpty()) {
221 auto &field = range.first->second;
223 field.setValue(*valuesIterator);
228 for (; valuesIterator != values.cend(); ++valuesIterator) {
229 if (!valuesIterator->isEmpty()) {
230 m_fields.insert(std::make_pair(
id,
FieldType(
id, *valuesIterator)));
234 for (; range.first != range.second; ++range.first) {
235 range.first->second.clearValue();
246 return static_cast<ImplementationType *
>(
this)->internallySetValue(
id, value);
255template <
class ImplementationType>
258 return static_cast<ImplementationType *
>(
this)->internallySetValues(
id, values);
269 return setValues(fieldId(field), values);
274 return hasField(fieldId(field));
283 for (
auto range = m_fields.equal_range(
id); range.first != range.second; ++range.first) {
284 if (!range.first->second.value().isEmpty()) {
296 return static_cast<const ImplementationType *
>(
this)->internallyHasField(
id);
307template <
class ImplementationType>
323 auto count = std::size_t(0);
324 for (
const auto &field : m_fields) {
325 if (!field.second.value().isEmpty()) {
336template <
class ImplementationType>
339 return static_cast<const ImplementationType *
>(
this)->internallyGetFieldId(value);
348 return static_cast<const ImplementationType *
>(
this)->internallyGetKnownField(
id);
354 return fieldId(field) != def;
361template <
class ImplementationType>
372 return static_cast<ImplementationType *
>(
this)->determineProposedDataType(
id);
381template <
class ImplementationType>
384 auto fieldsInserted = std::size_t(0);
385 for (
const auto &pair : from.
fields()) {
386 const FieldType &fromField = pair.second;
387 if (fromField.value().isEmpty()) {
390 bool fieldInserted =
false;
391 auto range = fields().equal_range(fromField.id());
392 for (
auto i = range.first; i != range.second; ++i) {
394 if ((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned() && fromField.typeInfo() == ownField.typeInfo())
395 || (!fromField.isTypeInfoAssigned() && !ownField.isTypeInfoAssigned())) {
396 if (overwrite || ownField.value().isEmpty()) {
397 ownField = fromField;
400 fieldInserted =
true;
404 if (!fieldInserted) {
405 fields().insert(std::make_pair(fromField.id(), fromField));
409 return fieldsInserted;
414 if (type() == from.
type()) {
424 for (
auto &field : fields()) {
425 field.second.value().convertDataEncodingForTag(
this);
Defines traits for the specified ImplementationType.
The FieldMapBasedTag provides a generic implementation of Tag which stores the tag fields using std::...
bool hasField(const IdentifierType &id) const
Returns an indication whether the field with the specified id is present.
bool setValue(const IdentifierType &id, const TagValue &value)
Assigns the given value to the field with the specified id.
void ensureTextValuesAreProperlyEncoded()
Ensures the encoding of all assigned text values is supported by the tag by converting the character ...
bool setValue(KnownField field, const TagValue &value)
Assigns the given value to the specified field.
bool hasField(KnownField field) const
Returns an indication whether the specified field is present.
std::vector< const TagValue * > values(KnownField field) const
Returns the values of the specified field.
std::multimap< IdentifierType, FieldType, Compare > & fields()
Returns the fields of the tag by providing direct access to the field map of the tag.
std::vector< const TagValue * > internallyGetValues(const IdentifierType &id) const
Default implementation for values().
typename FieldMapBasedTagTraits< ImplementationType >::Compare Compare
std::string_view typeName() const
Returns the type name of the tag as C-style string.
typename FieldMapBasedTagTraits< ImplementationType >::FieldType::IdentifierType IdentifierType
const TagValue & value(KnownField field) const
Returns the value of the specified field.
FieldMapBasedTag()
Constructs a new FieldMapBasedTag.
TagTextEncoding proposedTextEncoding() const
Returns the proposed text encoding.
const TagValue & value(const IdentifierType &id) const
Returns the value of the field with the specified id.
void removeAllFields()
Removes all fields from the tag.
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.
TagDataType proposedDataType(const IdentifierType &id) const
Returns the proposed data type for the field with the specified id.
bool internallySetValues(const IdentifierType &id, const std::vector< TagValue > &values)
Default implementation for setValues().
TagType type() const
Returns the type of the tag as TagParser::TagType.
std::size_t insertFields(const FieldMapBasedTag< ImplementationType > &from, bool overwrite)
Inserts all fields from another tag of the same field type and compare function.
typename FieldMapBasedTagTraits< ImplementationType >::FieldType FieldType
TagDataType internallyGetProposedDataType(const IdentifierType &id) const
Default implementation for proposedDataType().
void internallyGetValuesFromField(const FieldType &field, std::vector< const TagValue * > &values) const
Default way to gather values from a field in internallyGetValues().
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.
const TagValue & internallyGetValue(const IdentifierType &id) const
Default implementation for value().
bool internallyHasField(const IdentifierType &id) const
Default implementation for hasField().
bool setValues(const IdentifierType &id, const std::vector< TagValue > &values)
Assigns the given values to the field with the specified id.
std::size_t fieldCount() const
Returns the number of present fields.
bool supportsField(KnownField field) const
Returns an indication whether the specified field is supported by the tag.
bool setValues(KnownField field, const std::vector< TagValue > &values)
Assigns the given values to the field with the specified id.
IdentifierType fieldId(KnownField value) const
Returns the ID for the specified field.
std::size_t insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
bool internallySetValue(const IdentifierType &id, const TagValue &value)
Default implementation for setValue().
The TagValue class wraps values of different types.
static const TagValue & empty()
Returns a default-constructed TagValue where TagValue::isNull() and TagValue::isEmpty() both return t...
bool isEmpty() const
Returns whether no or an empty value is assigned.
The Tag class is used to store, read and write tag information.
virtual std::size_t insertValues(const Tag &from, bool overwrite)
Inserts all compatible values from another Tag.
virtual TagType type() const
Returns the type of the tag as TagParser::TagType.
virtual TagDataType proposedDataType(KnownField field) const
Returns the proposed data type for the specified field as TagDataType.
Contains all classes and functions of the TagInfo library.
KnownField
Specifies the field.
TagTextEncoding
Specifies the text encoding.
TagType
Specifies the tag type.
TagDataType
Specifies the data type.