Commit a74b0772 authored by Max Kellermann's avatar Max Kellermann

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

parent 7d69cbbd
...@@ -82,17 +82,7 @@ IcyInputStream::ReadTag() noexcept ...@@ -82,17 +82,7 @@ IcyInputStream::ReadTag() noexcept
/* no change */ /* no change */
return nullptr; return nullptr;
if (input_tag == nullptr && icy_tag == nullptr) return Tag::Merge(input_tag.get(), icy_tag.get());
/* 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);
} }
size_t size_t
......
...@@ -81,6 +81,22 @@ Tag::Merge(std::unique_ptr<Tag> base, std::unique_ptr<Tag> add) noexcept ...@@ -81,6 +81,22 @@ Tag::Merge(std::unique_ptr<Tag> base, std::unique_ptr<Tag> add) noexcept
return MergePtr(*base, *add); 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 * const char *
Tag::GetValue(TagType type) const noexcept Tag::GetValue(TagType type) const noexcept
{ {
......
...@@ -133,6 +133,15 @@ struct Tag { ...@@ -133,6 +133,15 @@ struct Tag {
std::unique_ptr<Tag> add) noexcept; 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 * Returns the first value of the specified tag type, or
* nullptr if none is present in this tag object. * nullptr if none is present in this tag object.
*/ */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment