tag/Tag: Merge() returns Tag, MergePtr() returns std::unique_ptr<Tag>

This commit is contained in:
Max Kellermann 2021-08-05 17:31:31 +02:00
parent 955502f881
commit 7d69cbbda7
4 changed files with 19 additions and 8 deletions

View File

@ -474,8 +474,8 @@ DecoderBridge::SubmitData(InputStream *is,
if (UpdateStreamTag(is)) {
if (decoder_tag != nullptr)
/* merge with tag from decoder plugin */
cmd = DoSendTag(*Tag::Merge(*decoder_tag,
*stream_tag));
cmd = DoSendTag(Tag::Merge(*decoder_tag,
*stream_tag));
else
/* send only the stream tag */
cmd = DoSendTag(*stream_tag);
@ -598,7 +598,7 @@ DecoderBridge::SubmitTag(InputStream *is, Tag &&tag) noexcept
if (stream_tag != nullptr)
/* merge with tag from input stream */
cmd = DoSendTag(*Tag::Merge(*stream_tag, *decoder_tag));
cmd = DoSendTag(Tag::Merge(*stream_tag, *decoder_tag));
else
/* send only the decoder tag */
cmd = DoSendTag(*decoder_tag);

View File

@ -92,7 +92,7 @@ IcyInputStream::ReadTag() noexcept
if (icy_tag == nullptr)
return std::make_unique<Tag>(*input_tag);
return Tag::Merge(*input_tag, *icy_tag);
return Tag::MergePtr(*input_tag, *icy_tag);
}
size_t

View File

@ -53,8 +53,16 @@ Tag::Tag(const Tag &other) noexcept
}
}
std::unique_ptr<Tag>
Tag
Tag::Merge(const Tag &base, const Tag &add) noexcept
{
TagBuilder builder(add);
builder.Complement(base);
return builder.Commit();
}
std::unique_ptr<Tag>
Tag::MergePtr(const Tag &base, const Tag &add) noexcept
{
TagBuilder builder(add);
builder.Complement(base);
@ -70,7 +78,7 @@ Tag::Merge(std::unique_ptr<Tag> base, std::unique_ptr<Tag> add) noexcept
if (base == nullptr)
return add;
return Merge(*base, *add);
return MergePtr(*base, *add);
}
const char *

View File

@ -117,8 +117,11 @@ struct Tag {
*
* @return a newly allocated tag
*/
static std::unique_ptr<Tag> Merge(const Tag &base,
const Tag &add) noexcept;
static Tag Merge(const Tag &base,
const Tag &add) noexcept;
static std::unique_ptr<Tag> MergePtr(const Tag &base,
const Tag &add) noexcept;
/**
* Merges the data from two tags. Any of the two may be nullptr. Both