Convert private raw pointers to unique_ptr (#1127)

Simplifies the code quite a bit.
This commit is contained in:
Rosen Penev
2023-09-22 21:46:05 -07:00
committed by GitHub
parent 967aaf7af2
commit e275abb8a3
17 changed files with 90 additions and 250 deletions

View File

@ -35,19 +35,9 @@ using TagLib::FLAC::Properties;
class Ogg::FLAC::File::FilePrivate
{
public:
FilePrivate() = default;
~FilePrivate()
{
delete comment;
delete properties;
}
std::unique_ptr<Ogg::XiphComment> comment;
FilePrivate(const FilePrivate &) = delete;
FilePrivate &operator=(const FilePrivate &) = delete;
Ogg::XiphComment *comment { nullptr };
Properties *properties { nullptr };
std::unique_ptr<Properties> properties;
ByteVector streamInfoData;
ByteVector xiphCommentData;
offset_t streamStart { 0 };
@ -96,7 +86,7 @@ Ogg::FLAC::File::~File() = default;
Ogg::XiphComment *Ogg::FLAC::File::tag() const
{
return d->comment;
return d->comment.get();
}
PropertyMap Ogg::FLAC::File::properties() const
@ -111,10 +101,9 @@ PropertyMap Ogg::FLAC::File::setProperties(const PropertyMap &properties)
Properties *Ogg::FLAC::File::audioProperties() const
{
return d->properties;
return d->properties.get();
}
bool Ogg::FLAC::File::save()
{
d->xiphCommentData = d->comment->render(false);
@ -174,13 +163,12 @@ void Ogg::FLAC::File::read(bool readProperties, Properties::ReadStyle properties
if(d->hasXiphComment)
d->comment = new Ogg::XiphComment(xiphCommentData());
d->comment = std::make_unique<Ogg::XiphComment>(xiphCommentData());
else
d->comment = new Ogg::XiphComment();
d->comment = std::make_unique<Ogg::XiphComment>();
if(readProperties)
d->properties = new Properties(streamInfoData(), streamLength(), propertiesStyle);
d->properties = std::make_unique<Properties>(streamInfoData(), streamLength(), propertiesStyle);
}
ByteVector Ogg::FLAC::File::streamInfoData()

View File

@ -53,19 +53,10 @@ public:
pages.setAutoDelete(true);
}
~FilePrivate()
{
delete firstPageHeader;
delete lastPageHeader;
}
FilePrivate(const FilePrivate &) = delete;
FilePrivate &operator=(const FilePrivate &) = delete;
unsigned int streamSerialNumber;
List<Page *> pages;
PageHeader *firstPageHeader { nullptr };
PageHeader *lastPageHeader { nullptr };
std::unique_ptr<PageHeader> firstPageHeader;
std::unique_ptr<PageHeader> lastPageHeader;
Map<unsigned int, ByteVector> dirtyPackets;
};
@ -131,10 +122,10 @@ const Ogg::PageHeader *Ogg::File::firstPageHeader()
if(firstPageHeaderOffset < 0)
return nullptr;
d->firstPageHeader = new PageHeader(this, firstPageHeaderOffset);
d->firstPageHeader = std::make_unique<PageHeader>(this, firstPageHeaderOffset);
}
return d->firstPageHeader->isValid() ? d->firstPageHeader : nullptr;
return d->firstPageHeader->isValid() ? d->firstPageHeader.get() : nullptr;
}
const Ogg::PageHeader *Ogg::File::lastPageHeader()
@ -144,10 +135,10 @@ const Ogg::PageHeader *Ogg::File::lastPageHeader()
if(lastPageHeaderOffset < 0)
return nullptr;
d->lastPageHeader = new PageHeader(this, lastPageHeaderOffset);
d->lastPageHeader = std::make_unique<PageHeader>(this, lastPageHeaderOffset);
}
return d->lastPageHeader->isValid() ? d->lastPageHeader : nullptr;
return d->lastPageHeader->isValid() ? d->lastPageHeader.get() : nullptr;
}
bool Ogg::File::save()

View File

@ -39,18 +39,8 @@ using namespace TagLib::Ogg;
class Opus::File::FilePrivate
{
public:
FilePrivate() = default;
~FilePrivate()
{
delete comment;
delete properties;
}
FilePrivate(const FilePrivate &) = delete;
FilePrivate &operator=(const FilePrivate &) = delete;
Ogg::XiphComment *comment { nullptr };
Properties *properties { nullptr };
std::unique_ptr<Ogg::XiphComment> comment;
std::unique_ptr<Properties> properties;
};
////////////////////////////////////////////////////////////////////////////////
@ -89,7 +79,7 @@ Opus::File::~File() = default;
Ogg::XiphComment *Opus::File::tag() const
{
return d->comment;
return d->comment.get();
}
PropertyMap Opus::File::properties() const
@ -104,13 +94,13 @@ PropertyMap Opus::File::setProperties(const PropertyMap &properties)
Opus::Properties *Opus::File::audioProperties() const
{
return d->properties;
return d->properties.get();
}
bool Opus::File::save()
{
if(!d->comment)
d->comment = new Ogg::XiphComment();
d->comment = std::make_unique<Ogg::XiphComment>();
setPacket(1, ByteVector("OpusTags", 8) + d->comment->render(false));
@ -139,8 +129,8 @@ void Opus::File::read(bool readProperties)
return;
}
d->comment = new Ogg::XiphComment(commentHeaderData.mid(8));
d->comment = std::make_unique<Ogg::XiphComment>(commentHeaderData.mid(8));
if(readProperties)
d->properties = new Properties(this);
d->properties = std::make_unique<Properties>(this);
}

View File

@ -39,18 +39,8 @@ using namespace TagLib::Ogg;
class Speex::File::FilePrivate
{
public:
FilePrivate() = default;
~FilePrivate()
{
delete comment;
delete properties;
}
FilePrivate(const FilePrivate &) = delete;
FilePrivate &operator=(const FilePrivate &) = delete;
Ogg::XiphComment *comment { nullptr };
Properties *properties { nullptr };
std::unique_ptr<Ogg::XiphComment> comment;
std::unique_ptr<Properties> properties;
};
////////////////////////////////////////////////////////////////////////////////
@ -89,7 +79,7 @@ Speex::File::~File() = default;
Ogg::XiphComment *Speex::File::tag() const
{
return d->comment;
return d->comment.get();
}
PropertyMap Speex::File::properties() const
@ -104,13 +94,13 @@ PropertyMap Speex::File::setProperties(const PropertyMap &properties)
Speex::Properties *Speex::File::audioProperties() const
{
return d->properties;
return d->properties.get();
}
bool Speex::File::save()
{
if(!d->comment)
d->comment = new Ogg::XiphComment();
d->comment = std::make_unique<Ogg::XiphComment>();
setPacket(1, d->comment->render());
@ -133,8 +123,8 @@ void Speex::File::read(bool readProperties)
ByteVector commentHeaderData = packet(1);
d->comment = new Ogg::XiphComment(commentHeaderData);
d->comment = std::make_unique<Ogg::XiphComment>(commentHeaderData);
if(readProperties)
d->properties = new Properties(this);
d->properties = std::make_unique<Properties>(this);
}

View File

@ -34,18 +34,8 @@ using namespace TagLib;
class Vorbis::File::FilePrivate
{
public:
FilePrivate() = default;
~FilePrivate()
{
delete comment;
delete properties;
}
FilePrivate(const FilePrivate &) = delete;
FilePrivate &operator=(const FilePrivate &) = delete;
Ogg::XiphComment *comment { nullptr };
Properties *properties { nullptr };
std::unique_ptr<Ogg::XiphComment> comment;
std::unique_ptr<Properties> properties;
};
namespace TagLib {
@ -92,7 +82,7 @@ Vorbis::File::~File() = default;
Ogg::XiphComment *Vorbis::File::tag() const
{
return d->comment;
return d->comment.get();
}
PropertyMap Vorbis::File::properties() const
@ -107,7 +97,7 @@ PropertyMap Vorbis::File::setProperties(const PropertyMap &properties)
Vorbis::Properties *Vorbis::File::audioProperties() const
{
return d->properties;
return d->properties.get();
}
bool Vorbis::File::save()
@ -115,7 +105,7 @@ bool Vorbis::File::save()
ByteVector v(vorbisCommentHeaderID);
if(!d->comment)
d->comment = new Ogg::XiphComment();
d->comment = std::make_unique<Ogg::XiphComment>();
v.append(d->comment->render());
setPacket(1, v);
@ -137,8 +127,8 @@ void Vorbis::File::read(bool readProperties)
return;
}
d->comment = new Ogg::XiphComment(commentHeaderData.mid(7));
d->comment = std::make_unique<Ogg::XiphComment>(commentHeaderData.mid(7));
if(readProperties)
d->properties = new Properties(this);
d->properties = std::make_unique<Properties>(this);
}