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);
134 template <
class ImplementationType>
139 values.emplace_back(&field.
value());
147 template <
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)));
212 template <
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 m_fields.insert(std::make_pair(
id,
FieldType(
id, *valuesIterator)));
232 for (; range.first != range.second; ++range.first) {
233 range.first->second.clearValue();
244 return static_cast<ImplementationType *
>(
this)->internallySetValue(
id, value);
253 template <
class ImplementationType>
256 return static_cast<ImplementationType *
>(
this)->internallySetValues(
id, values);
267 return setValues(fieldId(field), values);
272 return hasField(fieldId(field));
281 for (
auto range = m_fields.equal_range(
id); range.first != range.second; ++range.first) {
282 if (!range.first->second.value().isEmpty()) {
294 return static_cast<const ImplementationType *
>(
this)->internallyHasField(
id);
305 template <
class ImplementationType>
321 auto count = std::size_t(0);
322 for (
const auto &field : m_fields) {
323 if (!field.second.value().isEmpty()) {
334 template <
class ImplementationType>
337 return static_cast<const ImplementationType *
>(
this)->internallyGetFieldId(value);
346 return static_cast<const ImplementationType *
>(
this)->internallyGetKnownField(
id);
352 return fieldId(field) != def;
359 template <
class ImplementationType>
370 return static_cast<ImplementationType *
>(
this)->determineProposedDataType(
id);
379 template <
class ImplementationType>
382 auto fieldsInserted = std::size_t(0);
383 for (
const auto &pair : from.
fields()) {
384 const FieldType &fromField = pair.second;
385 if (fromField.value().isEmpty()) {
388 bool fieldInserted =
false;
389 auto range = fields().equal_range(fromField.id());
390 for (
auto i = range.first; i != range.second; ++i) {
392 if ((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned() && fromField.typeInfo() == ownField.typeInfo())
393 || (!fromField.isTypeInfoAssigned() && !ownField.isTypeInfoAssigned())) {
394 if (overwrite || ownField.value().isEmpty()) {
395 ownField = fromField;
398 fieldInserted =
true;
402 if (!fieldInserted) {
403 fields().insert(std::make_pair(fromField.id(), fromField));
407 return fieldsInserted;
412 if (type() == from.
type()) {
422 for (
auto &field : fields()) {
423 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.
virtual TagDataType proposedDataType(KnownField field) const
Returns the proposed data type for the specified field as TagDataType.
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.