FifoDataFile: Make Load return a unique_ptr

This commit is contained in:
Lioncash 2016-06-28 21:19:40 -04:00
parent 41335752e5
commit 8943d23a4c
4 changed files with 8 additions and 9 deletions

View File

@ -130,7 +130,7 @@ bool FifoDataFile::Save(const std::string& filename)
return true; return true;
} }
FifoDataFile* FifoDataFile::Load(const std::string& filename, bool flagsOnly) std::unique_ptr<FifoDataFile> FifoDataFile::Load(const std::string& filename, bool flagsOnly)
{ {
File::IOFile file; File::IOFile file;
file.Open(filename, "rb"); file.Open(filename, "rb");
@ -146,7 +146,7 @@ FifoDataFile* FifoDataFile::Load(const std::string& filename, bool flagsOnly)
return nullptr; return nullptr;
} }
FifoDataFile* dataFile = new FifoDataFile; auto dataFile = std::make_unique<FifoDataFile>();
dataFile->m_Flags = header.flags; dataFile->m_Flags = header.flags;
dataFile->m_Version = header.file_version; dataFile->m_Version = header.file_version;

View File

@ -4,6 +4,7 @@
#pragma once #pragma once
#include <memory>
#include <string> #include <string>
#include <vector> #include <vector>
@ -70,7 +71,7 @@ public:
u32 GetFrameCount() const { return static_cast<u32>(m_Frames.size()); } u32 GetFrameCount() const { return static_cast<u32>(m_Frames.size()); }
bool Save(const std::string& filename); bool Save(const std::string& filename);
static FifoDataFile* Load(const std::string& filename, bool flagsOnly); static std::unique_ptr<FifoDataFile> Load(const std::string& filename, bool flagsOnly);
private: private:
enum enum

View File

@ -28,7 +28,6 @@ bool IsPlayingBackFifologWithBrokenEFBCopies = false;
FifoPlayer::~FifoPlayer() FifoPlayer::~FifoPlayer()
{ {
delete m_File;
} }
bool FifoPlayer::Open(const std::string& filename) bool FifoPlayer::Open(const std::string& filename)
@ -40,7 +39,7 @@ bool FifoPlayer::Open(const std::string& filename)
if (m_File) if (m_File)
{ {
FifoAnalyzer::Init(); FifoAnalyzer::Init();
FifoPlaybackAnalyzer::AnalyzeFrames(m_File, m_FrameInfo); FifoPlaybackAnalyzer::AnalyzeFrames(m_File.get(), m_FrameInfo);
m_FrameRangeEnd = m_File->GetFrameCount(); m_FrameRangeEnd = m_File->GetFrameCount();
} }
@ -53,8 +52,7 @@ bool FifoPlayer::Open(const std::string& filename)
void FifoPlayer::Close() void FifoPlayer::Close()
{ {
delete m_File; m_File.reset();
m_File = nullptr;
m_FrameRangeStart = 0; m_FrameRangeStart = 0;
m_FrameRangeEnd = 0; m_FrameRangeEnd = 0;

View File

@ -64,7 +64,7 @@ public:
// PowerPC state. // PowerPC state.
std::unique_ptr<CPUCoreBase> GetCPUCore(); std::unique_ptr<CPUCoreBase> GetCPUCore();
FifoDataFile* GetFile() { return m_File; } FifoDataFile* GetFile() { return m_File.get(); }
u32 GetFrameObjectCount(); u32 GetFrameObjectCount();
u32 GetCurrentFrameNum() const { return m_CurrentFrame; } u32 GetCurrentFrameNum() const { return m_CurrentFrame; }
const AnalyzedFrameInfo& GetAnalyzedFrameInfo(u32 frame) const { return m_FrameInfo[frame]; } const AnalyzedFrameInfo& GetAnalyzedFrameInfo(u32 frame) const { return m_FrameInfo[frame]; }
@ -143,7 +143,7 @@ private:
CallbackFunc m_FileLoadedCb; CallbackFunc m_FileLoadedCb;
CallbackFunc m_FrameWrittenCb; CallbackFunc m_FrameWrittenCb;
FifoDataFile* m_File; std::unique_ptr<FifoDataFile> m_File;
std::vector<AnalyzedFrameInfo> m_FrameInfo; std::vector<AnalyzedFrameInfo> m_FrameInfo;
}; };