From e7ca031d1e41afe4afc0ed045c49a3e850ef7722 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 23 Dec 2015 12:38:34 +0000 Subject: [PATCH] pcsx2: Replace ScopedArray with unique_ptr Same functionality, but we don't have to maintain code ourselves. --- pcsx2/AsyncFileReader.h | 9 +++++---- pcsx2/CDVD/BlockdumpFileReader.cpp | 8 ++++---- pcsx2/CDVD/CDVDaccess.cpp | 10 +++++----- pcsx2/CDVD/IsoFileFormats.h | 5 +++-- pcsx2/CDVD/OutputIsoFile.cpp | 2 +- pcsx2/gui/ConsoleLogger.h | 7 +------ pcsx2/gui/Panels/LogOptionsPanels.cpp | 2 +- pcsx2/gui/Panels/LogOptionsPanels.h | 3 ++- pcsx2/gui/Panels/MiscPanelStuff.cpp | 5 +++-- 9 files changed, 25 insertions(+), 26 deletions(-) diff --git a/pcsx2/AsyncFileReader.h b/pcsx2/AsyncFileReader.h index ef691b009d..d1fe683076 100644 --- a/pcsx2/AsyncFileReader.h +++ b/pcsx2/AsyncFileReader.h @@ -23,6 +23,7 @@ #elif defined(__APPLE__) # include #endif +#include class AsyncFileReader { @@ -147,12 +148,12 @@ class BlockdumpFileReader : public AsyncFileReader wxFileInputStream* m_file; // total number of blocks in the ISO image (including all parts) - u32 m_blocks; - s32 m_blockofs; + u32 m_blocks; + s32 m_blockofs; // index table - ScopedArray m_dtable; - int m_dtablesize; + std::unique_ptr m_dtable; + int m_dtablesize; int m_lresult; diff --git a/pcsx2/CDVD/BlockdumpFileReader.cpp b/pcsx2/CDVD/BlockdumpFileReader.cpp index 69fe172b14..b4f9f736a1 100644 --- a/pcsx2/CDVD/BlockdumpFileReader.cpp +++ b/pcsx2/CDVD/BlockdumpFileReader.cpp @@ -86,7 +86,7 @@ bool BlockdumpFileReader::Open(const wxString& fileName) pxAssert( (datalen % (m_blocksize + 4)) == 0); m_dtablesize = datalen / (m_blocksize + 4); - m_dtable = new u32[m_dtablesize]; + m_dtable = std::unique_ptr(new u32[m_dtablesize]); m_file->SeekI(BlockDumpHeaderSize); @@ -95,14 +95,14 @@ bool BlockdumpFileReader::Open(const wxString& fileName) u32 has = 0; int i = 0; - ScopedArray buffer(bs); + std::unique_ptr buffer(new u8[bs]); do { - m_file->Read(buffer.GetPtr(), bs); + m_file->Read(buffer.get(), bs); has = m_file->LastRead(); while (i < m_dtablesize && off < has) { - m_dtable[i++] = *(u32*)(buffer.GetPtr() + off); + m_dtable[i++] = *reinterpret_cast(buffer.get() + off); off += 4; off += m_blocksize; } diff --git a/pcsx2/CDVD/CDVDaccess.cpp b/pcsx2/CDVD/CDVDaccess.cpp index f588fa72bd..408d74fc15 100644 --- a/pcsx2/CDVD/CDVDaccess.cpp +++ b/pcsx2/CDVD/CDVDaccess.cpp @@ -27,11 +27,11 @@ #include #include #include +#include #include "IsoFS/IsoFS.h" #include "IsoFS/IsoFSCDVD.h" #include "CDVDisoReader.h" -#include "Utilities/ScopedPtr.h" #include "DebugTools/SymbolMap.h" #include "AppConfig.h" @@ -82,14 +82,14 @@ static int CheckDiskTypeFS(int baseType) int size = file.getLength(); - ScopedArray buffer((int)file.getLength()+1); - file.read((u8*)(buffer.GetPtr()),size); + std::unique_ptr buffer(new char[file.getLength() + 1]); + file.read(buffer.get(),size); buffer[size]='\0'; - char* pos = strstr(buffer.GetPtr(), "BOOT2"); + char* pos = strstr(buffer.get(), "BOOT2"); if (pos == NULL) { - pos = strstr(buffer.GetPtr(), "BOOT"); + pos = strstr(buffer.get(), "BOOT"); if (pos == NULL) return CDVD_TYPE_ILLEGAL; return CDVD_TYPE_PSCD; } diff --git a/pcsx2/CDVD/IsoFileFormats.h b/pcsx2/CDVD/IsoFileFormats.h index d528afdbe9..4229a5e6cb 100644 --- a/pcsx2/CDVD/IsoFileFormats.h +++ b/pcsx2/CDVD/IsoFileFormats.h @@ -19,6 +19,7 @@ #include "wx/wfstream.h" #include "AsyncFileReader.h" #include "CompressedFileReader.h" +#include enum isoType { @@ -113,8 +114,8 @@ protected: u32 m_blocks; // dtable / dtablesize are used when reading blockdumps - ScopedArray m_dtable; - int m_dtablesize; + std::unique_ptr m_dtable; + int m_dtablesize; ScopedPtr m_outstream; diff --git a/pcsx2/CDVD/OutputIsoFile.cpp b/pcsx2/CDVD/OutputIsoFile.cpp index 46918def6c..ec9c2eef4d 100644 --- a/pcsx2/CDVD/OutputIsoFile.cpp +++ b/pcsx2/CDVD/OutputIsoFile.cpp @@ -114,7 +114,7 @@ void OutputIsoFile::WriteSector(const u8* src, uint lsn) void OutputIsoFile::Close() { - m_dtable.Delete(); + m_dtable.reset(nullptr); _init(); } diff --git a/pcsx2/gui/ConsoleLogger.h b/pcsx2/gui/ConsoleLogger.h index 08f47fbf54..62bd2aefb7 100644 --- a/pcsx2/gui/ConsoleLogger.h +++ b/pcsx2/gui/ConsoleLogger.h @@ -17,6 +17,7 @@ #include "App.h" #include +#include BEGIN_DECLARE_EVENT_TYPES() DECLARE_EVENT_TYPE(pxEvt_DockConsole, -1) @@ -214,12 +215,6 @@ protected: // a similar effect) ScopedPtr m_threadlogger; - // ---------------------------------------------------------------------------- - // Window and Menu Object Handles - // ---------------------------------------------------------------------------- - - ScopedArray m_sourceChecks; - public: // ctor & dtor ConsoleLogFrame( MainEmuFrame *pParent, const wxString& szTitle, ConLogConfig& options ); diff --git a/pcsx2/gui/Panels/LogOptionsPanels.cpp b/pcsx2/gui/Panels/LogOptionsPanels.cpp index 0405f2bec9..286b6e9724 100644 --- a/pcsx2/gui/Panels/LogOptionsPanels.cpp +++ b/pcsx2/gui/Panels/LogOptionsPanels.cpp @@ -203,7 +203,7 @@ static bool traceLogEnabled( const wxString& ident ) // -------------------------------------------------------------------------------------- Panels::LogOptionsPanel::LogOptionsPanel(wxWindow* parent ) : BaseApplicableConfigPanel( parent ) - , m_checks( traceLogCount ) + , m_checks( new pxCheckBox*[traceLogCount] ) { wxStaticBoxSizer& s_misc = *new wxStaticBoxSizer( wxHORIZONTAL, this, L"Misc" ); diff --git a/pcsx2/gui/Panels/LogOptionsPanels.h b/pcsx2/gui/Panels/LogOptionsPanels.h index b7d51f4ef8..0a2cba5b66 100644 --- a/pcsx2/gui/Panels/LogOptionsPanels.h +++ b/pcsx2/gui/Panels/LogOptionsPanels.h @@ -17,6 +17,7 @@ #include "AppCommon.h" #include "ApplyState.h" +#include namespace Panels { @@ -79,7 +80,7 @@ namespace Panels pxCheckBox* m_masterEnabler; - ScopedArray m_checks; + std::unique_ptr m_checks; public: LogOptionsPanel( wxWindow* parent ); diff --git a/pcsx2/gui/Panels/MiscPanelStuff.cpp b/pcsx2/gui/Panels/MiscPanelStuff.cpp index 914128777d..80442d2814 100644 --- a/pcsx2/gui/Panels/MiscPanelStuff.cpp +++ b/pcsx2/gui/Panels/MiscPanelStuff.cpp @@ -21,6 +21,7 @@ #include "ps2/BiosTools.h" +#include #include using namespace Dialogs; @@ -107,13 +108,13 @@ Panels::LanguageSelectionPanel::LanguageSelectionPanel( wxWindow* parent, bool s i18n_EnumeratePackages( m_langs ); int size = m_langs.size(); - ScopedArray compiled( size ); + std::unique_ptr compiled( new wxString[size] ); for( int i=0; i