input/Icy: use std::unique_ptr<Tag>

This commit is contained in:
Max Kellermann 2017-12-20 15:13:22 +01:00
parent 43d2fd73ab
commit 4c4fa68268
2 changed files with 11 additions and 17 deletions

View File

@ -23,16 +23,11 @@
IcyInputStream::IcyInputStream(InputStream *_input) IcyInputStream::IcyInputStream(InputStream *_input)
:ProxyInputStream(_input), :ProxyInputStream(_input),
input_tag(nullptr), icy_tag(nullptr),
override_offset(0) override_offset(0)
{ {
} }
IcyInputStream::~IcyInputStream() IcyInputStream::~IcyInputStream() = default;
{
delete input_tag;
delete icy_tag;
}
void void
IcyInputStream::Update() IcyInputStream::Update()
@ -50,18 +45,15 @@ IcyInputStream::ReadTag()
if (!IsEnabled()) if (!IsEnabled())
return new_input_tag; return new_input_tag;
if (new_input_tag != nullptr) { if (new_input_tag != nullptr)
delete input_tag; input_tag.reset(new_input_tag);
input_tag = new_input_tag;
}
auto new_icy_tag = parser.ReadTag(); auto new_icy_tag = parser.ReadTag();
if (new_icy_tag != nullptr) { const bool had_new_icy_tag = !!new_icy_tag;
delete icy_tag; if (new_icy_tag != nullptr)
icy_tag = new_icy_tag.release(); icy_tag = std::move(new_icy_tag);
}
if (new_input_tag == nullptr && new_icy_tag == nullptr) if (new_input_tag == nullptr && !had_new_icy_tag)
/* no change */ /* no change */
return nullptr; return nullptr;

View File

@ -24,6 +24,8 @@
#include "IcyMetaDataParser.hxx" #include "IcyMetaDataParser.hxx"
#include "Compiler.h" #include "Compiler.h"
#include <memory>
struct Tag; struct Tag;
/** /**
@ -35,12 +37,12 @@ class IcyInputStream final : public ProxyInputStream {
/** /**
* The #Tag object ready to be requested via ReadTag(). * The #Tag object ready to be requested via ReadTag().
*/ */
Tag *input_tag; std::unique_ptr<Tag> input_tag;
/** /**
* The #Tag object ready to be requested via ReadTag(). * The #Tag object ready to be requested via ReadTag().
*/ */
Tag *icy_tag; std::unique_ptr<Tag> icy_tag;
offset_type override_offset; offset_type override_offset;