diff --git a/common/include/Utilities/ScopedPtr.h b/common/include/Utilities/ScopedPtr.h index 00b68829fd..0c975b183f 100644 --- a/common/include/Utilities/ScopedPtr.h +++ b/common/include/Utilities/ScopedPtr.h @@ -140,121 +140,6 @@ public: } }; -// -------------------------------------------------------------------------------------- -// ScopedArray - same as ScopedPtr but uses delete[], and has operator[] -// -------------------------------------------------------------------------------------- - -template< typename T > -class ScopedArray -{ - DeclareNoncopyableObject(ScopedArray); - -protected: - T* m_array; - uint m_valid_range; - -public: - typedef T element_type; - - wxEXPLICIT ScopedArray(T * ptr = NULL) - { - m_array = ptr; - m_valid_range = 0xffffffff; - } - - wxEXPLICIT ScopedArray( size_t size ) - { - m_array = new T[size]; - m_valid_range = size; - } - - ~ScopedArray() throw() - { Delete(); } - - ScopedArray& Reassign(T * ptr = NULL) - { - if( ptr != m_array ) - { - Delete(); - m_array = ptr; - m_valid_range = 0xffffffff; - } - return *this; - } - - ScopedArray& Delete() throw() - { - // Thread-safe deletion: Set the pointer to NULL first, and then issue - // the deletion. This allows pending Application messages that might be - // dependent on the current object to nullify their actions. - - T* deleteme = m_array; - m_array = NULL; - delete[] deleteme; - - return *this; - } - - // Removes the pointer from scoped management, but does not delete! - T *DetachPtr() - { - T *ptr = m_array; - m_array = NULL; - return ptr; - } - - // Returns the managed pointer. Can return NULL as a valid result if the ScopedPtr - // has no object in management. - T* GetPtr() const - { - return m_array; - } - - void SwapPtr(ScopedArray& other) - { - T * const tmp = other.m_array; - other.m_array = m_array; - m_array = tmp; - } - - // ---------------------------------------------------------------------------- - // ScopedPtr Operators - // ---------------------------------------------------------------------------- - // I've decided to use the ATL's approach to pointer validity tests, opposed to - // the wx/boost approach (which uses some bizarre member method pointer crap, and can't - // allow the T* implicit casting. - - bool operator!() const throw() - { - return m_array == NULL; - } - - // Equality - bool operator==(T* pT) const throw() - { - return m_array == pT; - } - - // Inequality - bool operator!=(T* pT) const throw() - { - return !operator==(pT); - } - - // Convenient assignment operator. ScopedPtr = NULL will issue an automatic deletion - // of the managed pointer. - ScopedArray& operator=( T* src ) - { - return Reassign( src ); - } - - T& operator[]( uint idx ) const - { - pxAssertDev( idx < m_valid_range, "Array index out of bounds on ScopedArray." ); - return m_array[idx]; - } -}; - // -------------------------------------------------------------------------------------- // pxObjPtr -- fancified version of wxScopedPtr // -------------------------------------------------------------------------------------- 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