| 539 | |
| 540 | /// \brief Sets the first of the specified \a values as front-cover with no description replacing any existing cover values. |
| 541 | template <class TagType> static void setId3v2CoverValues(TagType *tag, std::vector<TagParser::TagValue> &&values) |
| 542 | { |
| 543 | auto &fields = tag->fields(); |
| 544 | const auto id = tag->fieldId(TagParser::KnownField::Cover); |
| 545 | const auto range = fields.equal_range(id); |
| 546 | const auto first = range.first; |
| 547 | |
| 548 | constexpr auto coverType = CoverType(3); // assume front cover |
| 549 | constexpr auto description = std::optional<std::string_view>(); // assume no description |
| 550 | |
| 551 | for (auto &tagValue : values) { |
| 552 | // check whether there is already a tag value with the current type and description |
| 553 | auto pair = std::find_if(first, range.second, std::bind(&fieldPredicate<TagType>, coverType, description, std::placeholders::_1)); |
| 554 | if (pair != range.second) { |
| 555 | // there is already a tag value with the current type and description |
| 556 | // -> update this value |
| 557 | pair->second.setValue(tagValue); |
| 558 | // check whether there are more values with the current type and description |
| 559 | while ((pair = std::find_if(++pair, range.second, std::bind(&fieldPredicate<TagType>, coverType, description, std::placeholders::_1))) |
| 560 | != range.second) { |
| 561 | // -> remove these values as we only support one value of a type/description in the same tag |
| 562 | pair->second.setValue(TagParser::TagValue()); |
| 563 | } |
| 564 | } else if (!tagValue.isEmpty()) { |
| 565 | using FieldType = typename TagType::FieldType; |
| 566 | auto newField = FieldType(id, tagValue); |
| 567 | newField.setTypeInfo(static_cast<typename FieldType::TypeInfoType>(coverType)); |
| 568 | fields.insert(std::pair(id, std::move(newField))); |
| 569 | } |
| 570 | break; // allow only setting one value for now |
| 571 | } |
| 572 | } |
| 573 | |
| 574 | void TagObject::applyChanges() |
| 575 | { |
no test coverage detected