tag/Tag: add Merge() which takes Tag pointers

This commit is contained in:
Max Kellermann 2021-08-05 17:34:05 +02:00
parent 7d69cbbda7
commit a74b07728e
3 changed files with 26 additions and 11 deletions

View File

@ -82,17 +82,7 @@ IcyInputStream::ReadTag() noexcept
/* no change */
return nullptr;
if (input_tag == nullptr && icy_tag == nullptr)
/* no tag */
return nullptr;
if (input_tag == nullptr)
return std::make_unique<Tag>(*icy_tag);
if (icy_tag == nullptr)
return std::make_unique<Tag>(*input_tag);
return Tag::MergePtr(*input_tag, *icy_tag);
return Tag::Merge(input_tag.get(), icy_tag.get());
}
size_t

View File

@ -81,6 +81,22 @@ Tag::Merge(std::unique_ptr<Tag> base, std::unique_ptr<Tag> add) noexcept
return MergePtr(*base, *add);
}
std::unique_ptr<Tag>
Tag::Merge(const Tag *base, const Tag *add) noexcept
{
if (base == nullptr && add == nullptr)
/* no tag */
return nullptr;
if (base == nullptr)
return std::make_unique<Tag>(*add);
if (add == nullptr)
return std::make_unique<Tag>(*base);
return MergePtr(*base, *add);
}
const char *
Tag::GetValue(TagType type) const noexcept
{

View File

@ -132,6 +132,15 @@ struct Tag {
static std::unique_ptr<Tag> Merge(std::unique_ptr<Tag> base,
std::unique_ptr<Tag> add) noexcept;
/**
* Merges the data from two tags. Any of the two may be nullptr.
*
* @return a newly allocated tag (or nullptr if both
* parameters are nullptr)
*/
static std::unique_ptr<Tag> Merge(const Tag *base,
const Tag *add) noexcept;
/**
* Returns the first value of the specified tag type, or
* nullptr if none is present in this tag object.