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 const auto id = fieldId(field);
189 if constexpr (std::is_arithmetic_v<IdentifierType>) {
198 return setValue(
id, value);
207 auto i = m_fields.find(
id);
208 if (i != m_fields.end()) {
209 i->second.setValue(value);
211 m_fields.insert(std::make_pair(
id,
FieldType(
id, value)));
222template <
class ImplementationType>
225 auto valuesIterator = values.cbegin();
226 auto range = m_fields.equal_range(
id);
228 for (; valuesIterator != values.cend() && range.first != range.second; ++valuesIterator) {
230 if (!valuesIterator->isEmpty()) {
231 auto &field = range.first->second;
233 field.setValue(*valuesIterator);
238 for (; valuesIterator != values.cend(); ++valuesIterator) {
239 if (!valuesIterator->isEmpty()) {
240 m_fields.insert(std::make_pair(
id,
FieldType(
id, *valuesIterator)));
244 for (; range.first != range.second; ++range.first) {
245 range.first->second.clearValue();
256 return static_cast<ImplementationType *
>(
this)->internallySetValue(
id, value);
265template <
class ImplementationType>
268 return static_cast<ImplementationType *
>(
this)->internallySetValues(
id, values);
279 const auto id = fieldId(field);
280 if constexpr (std::is_arithmetic_v<IdentifierType>) {
289 return setValues(
id, values);
294 return hasField(fieldId(field));
303 for (
auto range = m_fields.equal_range(
id); range.first != range.second; ++range.first) {
304 if (!range.first->second.value().isEmpty()) {
316 return static_cast<const ImplementationType *
>(
this)->internallyHasField(
id);
327template <
class ImplementationType>
343 auto count = std::size_t(0);
344 for (
const auto &field : m_fields) {
345 if (!field.second.value().isEmpty()) {
356template <
class ImplementationType>
359 return static_cast<const ImplementationType *
>(
this)->internallyGetFieldId(value);
368 return static_cast<const ImplementationType *
>(
this)->internallyGetKnownField(
id);
374 return fieldId(field) != def;
381template <
class ImplementationType>
392 return static_cast<ImplementationType *
>(
this)->determineProposedDataType(
id);
401template <
class ImplementationType>
404 auto fieldsInserted = std::size_t(0);
405 for (
const auto &pair : from.
fields()) {
406 const FieldType &fromField = pair.second;
407 if (fromField.value().isEmpty()) {
410 bool fieldInserted =
false;
411 auto range = fields().equal_range(fromField.id());
412 for (
auto i = range.first; i != range.second; ++i) {
414 if ((fromField.isTypeInfoAssigned() && ownField.isTypeInfoAssigned() && fromField.typeInfo() == ownField.typeInfo())
415 || (!fromField.isTypeInfoAssigned() && !ownField.isTypeInfoAssigned())) {
416 if (overwrite || ownField.value().isEmpty()) {
417 ownField = fromField;
420 fieldInserted =
true;
424 if (!fieldInserted) {
425 fields().insert(std::make_pair(fromField.id(), fromField));
429 return fieldsInserted;
434 if (type() == from.
type()) {
444 for (
auto &field : fields()) {
445 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.