From 115b14bc94a6d40e8f5c8eac1113722ec81534ae Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Tue, 26 Jan 2016 22:07:52 +0000 Subject: [PATCH 1/6] cdvd: Replace ScopedPtr with unique_ptr --- common/include/Utilities/Dependencies.h | 1 + pcsx2/CDVD/CDVD.cpp | 5 ++--- pcsx2/CDVD/IsoFS/IsoFS.cpp | 6 ++++-- pcsx2/CDVD/IsoFileFormats.h | 2 +- pcsx2/CDVD/OutputIsoFile.cpp | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/common/include/Utilities/Dependencies.h b/common/include/Utilities/Dependencies.h index f0c70cad19..1ad38db121 100644 --- a/common/include/Utilities/Dependencies.h +++ b/common/include/Utilities/Dependencies.h @@ -199,6 +199,7 @@ public: #include #include #include +#include #include "Pcsx2Defs.h" diff --git a/pcsx2/CDVD/CDVD.cpp b/pcsx2/CDVD/CDVD.cpp index 3daa786f01..13d6089e3d 100644 --- a/pcsx2/CDVD/CDVD.cpp +++ b/pcsx2/CDVD/CDVD.cpp @@ -17,6 +17,7 @@ #include "IopCommon.h" #include "AppConfig.h" +#include #include #include @@ -341,8 +342,6 @@ static __fi ElfObject* loadElf( const wxString filename ) static __fi void _reloadElfInfo(wxString elfpath) { - ScopedPtr elfptr; - // Now's a good time to reload the ELF info... ScopedLock locker( Mutex_NewDiskCB ); @@ -357,7 +356,7 @@ static __fi void _reloadElfInfo(wxString elfpath) if (fname.Matches(L"????_???.??*")) DiscSerial = fname(0,4) + L"-" + fname(5,3) + fname(9,2); - elfptr = loadElf(elfpath); + std::unique_ptr elfptr(loadElf(elfpath)); elfptr->loadHeaders(); ElfCRC = elfptr->getCRC(); diff --git a/pcsx2/CDVD/IsoFS/IsoFS.cpp b/pcsx2/CDVD/IsoFS/IsoFS.cpp index 80a215ccd4..2925edec3a 100644 --- a/pcsx2/CDVD/IsoFS/IsoFS.cpp +++ b/pcsx2/CDVD/IsoFS/IsoFS.cpp @@ -18,6 +18,7 @@ #include "IsoFS.h" #include "IsoFile.h" +#include ////////////////////////////////////////////////////////////////////////// // IsoDirectory @@ -172,7 +173,7 @@ IsoFileDescriptor IsoDirectory::FindFile(const wxString& filePath) const wxFileName parts( filePath, wxPATH_DOS ); IsoFileDescriptor info; const IsoDirectory* dir = this; - ScopedPtr deleteme; + std::unique_ptr deleteme; // walk through path ("." and ".." entries are in the directories themselves, so even if the // path included . and/or .., it still works) @@ -182,7 +183,8 @@ IsoFileDescriptor IsoDirectory::FindFile(const wxString& filePath) const info = dir->GetEntry(parts.GetDirs()[i]); if(info.IsFile()) throw Exception::FileNotFound( filePath ); - dir = deleteme = new IsoDirectory(internalReader, info); + deleteme.reset(new IsoDirectory(internalReader, info)); + dir = deleteme.get(); } if( !parts.GetFullName().IsEmpty() ) diff --git a/pcsx2/CDVD/IsoFileFormats.h b/pcsx2/CDVD/IsoFileFormats.h index 4229a5e6cb..2100ef168e 100644 --- a/pcsx2/CDVD/IsoFileFormats.h +++ b/pcsx2/CDVD/IsoFileFormats.h @@ -117,7 +117,7 @@ protected: std::unique_ptr m_dtable; int m_dtablesize; - ScopedPtr m_outstream; + std::unique_ptr m_outstream; public: OutputIsoFile(); diff --git a/pcsx2/CDVD/OutputIsoFile.cpp b/pcsx2/CDVD/OutputIsoFile.cpp index ec9c2eef4d..dab16be95c 100644 --- a/pcsx2/CDVD/OutputIsoFile.cpp +++ b/pcsx2/CDVD/OutputIsoFile.cpp @@ -62,7 +62,7 @@ void OutputIsoFile::Create(const wxString& filename, int version) m_blockofs = 24; m_blocksize = 2048; - m_outstream = new wxFileOutputStream( m_filename ); + m_outstream = std::unique_ptr(new wxFileOutputStream(m_filename)); pxStream_OpenCheck( *m_outstream, m_filename, L"writing" ); Console.WriteLn("isoFile create ok: %s ", WX_STR(m_filename)); From 92bb849e7ca1c301b64f5b51262c1246275e3f36 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 27 Jan 2016 17:50:51 +0000 Subject: [PATCH 2/6] Use unique_ptr instead of ScopedPtr for exceptions --- common/include/Utilities/Exceptions.h | 4 ++-- common/src/Utilities/wxAppWithHelpers.cpp | 4 ++-- pcsx2/System.cpp | 16 ++++++++-------- pcsx2/System.h | 4 ++-- pcsx2/x86/ix86-32/iR5900-32.cpp | 10 +++++----- 5 files changed, 19 insertions(+), 19 deletions(-) diff --git a/common/include/Utilities/Exceptions.h b/common/include/Utilities/Exceptions.h index 635564e336..9eb3b83a1a 100644 --- a/common/include/Utilities/Exceptions.h +++ b/common/include/Utilities/Exceptions.h @@ -16,7 +16,7 @@ #pragma once #include "Assertions.h" -#include "ScopedPtr.h" +#include // Because wxTrap isn't available on Linux builds of wxWidgets (non-Debug, typically) void pxTrap(); @@ -108,7 +108,7 @@ namespace Exception virtual BaseException* Clone() const=0; }; - typedef ScopedPtr ScopedExcept; + typedef std::unique_ptr ScopedExcept; // -------------------------------------------------------------------------------------- // Ps2Generic Exception diff --git a/common/src/Utilities/wxAppWithHelpers.cpp b/common/src/Utilities/wxAppWithHelpers.cpp index e86e9edf31..c231a6a2db 100644 --- a/common/src/Utilities/wxAppWithHelpers.cpp +++ b/common/src/Utilities/wxAppWithHelpers.cpp @@ -55,14 +55,14 @@ void BaseDeletableObject::DoDeletion() void SynchronousActionState::SetException( const BaseException& ex ) { - m_exception = ex.Clone(); + m_exception = ScopedExcept(ex.Clone()); } void SynchronousActionState::SetException( BaseException* ex ) { if( !m_posted ) { - m_exception = ex; + m_exception = ScopedExcept(ex); } else if( wxTheApp ) { diff --git a/pcsx2/System.cpp b/pcsx2/System.cpp index 62fc32d8d2..42572ece47 100644 --- a/pcsx2/System.cpp +++ b/pcsx2/System.cpp @@ -325,13 +325,13 @@ CpuInitializer< CpuType >::CpuInitializer() { Console.Error( L"CPU provider error:\n\t" + ex.FormatDiagnosticMessage() ); MyCpu = NULL; - ExThrown = ex.Clone(); + ExThrown = ScopedExcept(ex.Clone()); } catch( std::runtime_error& ex ) { Console.Error( L"CPU provider error (STL Exception)\n\tDetails:" + fromUTF8( ex.what() ) ); MyCpu = NULL; - ExThrown = new Exception::RuntimeError(ex); + ExThrown = ScopedExcept(new Exception::RuntimeError(ex)); } } @@ -492,7 +492,7 @@ SysCpuProviderPack::SysCpuProviderPack() } catch( Exception::RuntimeError& ex ) { - m_RecExceptionEE = ex.Clone(); + m_RecExceptionEE = ScopedExcept(ex.Clone()); Console.Error( L"EE Recompiler Reservation Failed:\n" + ex.FormatDiagnosticMessage() ); recCpu.Shutdown(); } @@ -502,7 +502,7 @@ SysCpuProviderPack::SysCpuProviderPack() } catch( Exception::RuntimeError& ex ) { - m_RecExceptionIOP = ex.Clone(); + m_RecExceptionIOP = ScopedExcept(ex.Clone()); Console.Error( L"IOP Recompiler Reservation Failed:\n" + ex.FormatDiagnosticMessage() ); psxRec.Shutdown(); } @@ -518,14 +518,14 @@ SysCpuProviderPack::SysCpuProviderPack() bool SysCpuProviderPack::IsRecAvailable_MicroVU0() const { return CpuProviders->microVU0.IsAvailable(); } bool SysCpuProviderPack::IsRecAvailable_MicroVU1() const { return CpuProviders->microVU1.IsAvailable(); } -BaseException* SysCpuProviderPack::GetException_MicroVU0() const { return CpuProviders->microVU0.ExThrown; } -BaseException* SysCpuProviderPack::GetException_MicroVU1() const { return CpuProviders->microVU1.ExThrown; } +BaseException* SysCpuProviderPack::GetException_MicroVU0() const { return CpuProviders->microVU0.ExThrown.get(); } +BaseException* SysCpuProviderPack::GetException_MicroVU1() const { return CpuProviders->microVU1.ExThrown.get(); } #ifndef DISABLE_SVU bool SysCpuProviderPack::IsRecAvailable_SuperVU0() const { return CpuProviders->superVU0.IsAvailable(); } bool SysCpuProviderPack::IsRecAvailable_SuperVU1() const { return CpuProviders->superVU1.IsAvailable(); } -BaseException* SysCpuProviderPack::GetException_SuperVU0() const { return CpuProviders->superVU0.ExThrown; } -BaseException* SysCpuProviderPack::GetException_SuperVU1() const { return CpuProviders->superVU1.ExThrown; } +BaseException* SysCpuProviderPack::GetException_SuperVU0() const { return CpuProviders->superVU0.ExThrown.get(); } +BaseException* SysCpuProviderPack::GetException_SuperVU1() const { return CpuProviders->superVU1.ExThrown.get(); } #endif diff --git a/pcsx2/System.h b/pcsx2/System.h index 75c855d20a..2071527791 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -150,8 +150,8 @@ public: bool IsRecAvailable_EE() const { return !m_RecExceptionEE; } bool IsRecAvailable_IOP() const { return !m_RecExceptionIOP; } - BaseException* GetException_EE() const { return m_RecExceptionEE; } - BaseException* GetException_IOP() const { return m_RecExceptionIOP; } + BaseException* GetException_EE() const { return m_RecExceptionEE.get(); } + BaseException* GetException_IOP() const { return m_RecExceptionIOP.get(); } bool IsRecAvailable_MicroVU0() const; bool IsRecAvailable_MicroVU1() const; diff --git a/pcsx2/x86/ix86-32/iR5900-32.cpp b/pcsx2/x86/ix86-32/iR5900-32.cpp index 4648ac08a6..6093792147 100644 --- a/pcsx2/x86/ix86-32/iR5900-32.cpp +++ b/pcsx2/x86/ix86-32/iR5900-32.cpp @@ -641,9 +641,9 @@ void recStep() #if !PCSX2_SEH # define SETJMP_CODE(x) x - static jmp_buf m_SetJmp_StateCheck; - static ScopedPtr m_cpuException; - static ScopedExcept m_Exception; + static jmp_buf m_SetJmp_StateCheck; + static std::unique_ptr m_cpuException; + static ScopedExcept m_Exception; #else # define SETJMP_CODE(x) #endif @@ -2045,7 +2045,7 @@ static void recThrowException( const BaseR5900Exception& ex ) ex.Rethrow(); #else if (!eeCpuExecuting) ex.Rethrow(); - m_cpuException = ex.Clone(); + m_cpuException = std::unique_ptr(ex.Clone()); recExitExecution(); #endif } @@ -2056,7 +2056,7 @@ static void recThrowException( const BaseException& ex ) ex.Rethrow(); #else if (!eeCpuExecuting) ex.Rethrow(); - m_Exception = ex.Clone(); + m_Exception = ScopedExcept(ex.Clone()); recExitExecution(); #endif } From 8889f4fdcc6d5e1f8e0ee6e108a915f7df18bcb7 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Tue, 26 Jan 2016 22:08:14 +0000 Subject: [PATCH 3/6] gui: Replace ScopedPtr with unique_ptr --- pcsx2/gui/App.h | 31 ++++++++++--------- pcsx2/gui/AppConfig.cpp | 17 ++++++----- pcsx2/gui/AppConfig.h | 3 +- pcsx2/gui/AppCorePlugins.cpp | 18 ++++++----- pcsx2/gui/AppCoreThread.cpp | 8 ++--- pcsx2/gui/AppCoreThread.h | 2 +- pcsx2/gui/AppGameDatabase.cpp | 4 +-- pcsx2/gui/AppInit.cpp | 7 +++-- pcsx2/gui/AppMain.cpp | 4 +-- pcsx2/gui/AppRes.cpp | 31 ++++++++++--------- pcsx2/gui/AppUserMode.cpp | 32 +++++++++---------- pcsx2/gui/ConsoleLogger.cpp | 8 ++--- pcsx2/gui/ConsoleLogger.h | 4 +-- pcsx2/gui/CpuUsageProvider.h | 3 +- pcsx2/gui/ExecutorThread.cpp | 21 +++++++------ pcsx2/gui/FrameForGS.cpp | 3 +- pcsx2/gui/GSFrame.h | 3 +- pcsx2/gui/GlobalCommands.cpp | 4 +-- pcsx2/gui/MainMenuClicks.cpp | 2 +- pcsx2/gui/Panels/BiosSelectorPanel.cpp | 9 +++--- pcsx2/gui/Panels/ConfigurationPanels.h | 17 ++++++----- pcsx2/gui/Panels/GameFixesPanel.cpp | 2 +- pcsx2/gui/Panels/PluginSelectorPanel.cpp | 18 ++++++----- pcsx2/gui/Panels/SpeedhacksPanel.cpp | 2 +- pcsx2/gui/Panels/ThemeSelectorPanel.cpp | 11 ++++--- pcsx2/gui/RecentIsoList.h | 4 +-- pcsx2/gui/SysState.cpp | 39 ++++++++++++------------ pcsx2/gui/i18n.cpp | 12 ++++---- pcsx2/gui/pxEventThread.h | 6 ++-- pcsx2/gui/pxLogTextCtrl.cpp | 5 +-- 30 files changed, 175 insertions(+), 155 deletions(-) diff --git a/pcsx2/gui/App.h b/pcsx2/gui/App.h index 03cf7476f8..2adeb87bd3 100644 --- a/pcsx2/gui/App.h +++ b/pcsx2/gui/App.h @@ -19,6 +19,7 @@ #include #include +#include #include "pxEventThread.h" @@ -241,12 +242,12 @@ class pxAppResources public: AppImageIds ImageId; - ScopedPtr ConfigImages; - ScopedPtr ToolbarImages; - ScopedPtr IconBundle; - ScopedPtr Bitmap_Logo; - ScopedPtr ScreenshotBitmap; - ScopedPtr GameDB; + std::unique_ptr ConfigImages; + std::unique_ptr ToolbarImages; + std::unique_ptr IconBundle; + std::unique_ptr Bitmap_Logo; + std::unique_ptr ScreenshotBitmap; + std::unique_ptr GameDB; pxAppResources(); virtual ~pxAppResources() throw(); @@ -469,28 +470,28 @@ protected: public: FramerateManager FpsManager; - ScopedPtr GlobalCommands; - ScopedPtr GlobalAccels; + std::unique_ptr GlobalCommands; + std::unique_ptr GlobalAccels; StartupOptions Startup; CommandlineOverrides Overrides; - ScopedPtr m_timer_Termination; + std::unique_ptr m_timer_Termination; protected: - ScopedPtr m_StdoutRedirHandle; - ScopedPtr m_StderrRedirHandle; + std::unique_ptr m_StdoutRedirHandle; + std::unique_ptr m_StderrRedirHandle; - ScopedPtr m_RecentIsoList; - ScopedPtr m_Resources; + std::unique_ptr m_RecentIsoList; + std::unique_ptr m_Resources; public: // Executor Thread for complex VM/System tasks. This thread is used to execute such tasks // in parallel to the main message pump, to allow the main pump to run without fear of // blocked threads stalling the GUI. ExecutorThread SysExecutorThread; - ScopedPtr m_CpuProviders; - ScopedPtr m_VmReserve; + std::unique_ptr m_CpuProviders; + std::unique_ptr m_VmReserve; protected: wxWindowID m_id_MainFrame; diff --git a/pcsx2/gui/AppConfig.cpp b/pcsx2/gui/AppConfig.cpp index 061c26cd3e..285dcee342 100644 --- a/pcsx2/gui/AppConfig.cpp +++ b/pcsx2/gui/AppConfig.cpp @@ -24,6 +24,7 @@ #include #include "DebugTools/Debug.h" +#include ////////////////////////////////////////////////////////////////////////////////////////// // PathDefs Namespace -- contains default values for various pcsx2 path names and locations. @@ -1242,7 +1243,7 @@ static void LoadUiSettings() ConLog_LoadSaveSettings( loader ); SysTraceLog_LoadSaveSettings( loader ); - g_Conf = new AppConfig(); + g_Conf = std::unique_ptr(new AppConfig()); g_Conf->LoadSave( loader ); if( !wxFile::Exists( g_Conf->CurrentIso ) ) @@ -1256,8 +1257,8 @@ static void LoadVmSettings() // Load virtual machine options and apply some defaults overtop saved items, which // are regulated by the PCSX2 UI. - ScopedPtr vmini( OpenFileConfig( GetVmSettingsFilename() ) ); - IniLoader vmloader( vmini ); + std::unique_ptr vmini( OpenFileConfig( GetVmSettingsFilename() ) ); + IniLoader vmloader( vmini.get() ); g_Conf->EmuOptions.LoadSave( vmloader ); g_Conf->EmuOptions.GS.LimitScalar = g_Conf->Framerate.NominalScalar; @@ -1293,8 +1294,8 @@ static void SaveUiSettings() static void SaveVmSettings() { - ScopedPtr vmini( OpenFileConfig( GetVmSettingsFilename() ) ); - IniSaver vmsaver( vmini ); + std::unique_ptr vmini( OpenFileConfig( GetVmSettingsFilename() ) ); + IniSaver vmsaver( vmini.get() ); g_Conf->EmuOptions.LoadSave( vmsaver ); sApp.DispatchVmSettingsEvent( vmsaver ); @@ -1302,15 +1303,15 @@ static void SaveVmSettings() static void SaveRegSettings() { - ScopedPtr conf_install; + std::unique_ptr conf_install; if (InstallationMode == InstallMode_Portable) return; // sApp. macro cannot be use because you need the return value of OpenInstallSettingsFile method - if( Pcsx2App* __app_ = (Pcsx2App*)wxApp::GetInstance() ) conf_install = (*__app_).OpenInstallSettingsFile(); + if( Pcsx2App* __app_ = (Pcsx2App*)wxApp::GetInstance() ) conf_install = std::unique_ptr((*__app_).OpenInstallSettingsFile()); conf_install->SetRecordDefaults(false); - App_SaveInstallSettings( conf_install ); + App_SaveInstallSettings( conf_install.get() ); } void AppSaveSettings() diff --git a/pcsx2/gui/AppConfig.h b/pcsx2/gui/AppConfig.h index 750bc09755..b432225af5 100644 --- a/pcsx2/gui/AppConfig.h +++ b/pcsx2/gui/AppConfig.h @@ -18,6 +18,7 @@ #include "AppForwardDefs.h" #include "PathDefs.h" #include "CDVD/CDVDaccess.h" +#include enum DocsModeType { @@ -383,4 +384,4 @@ extern void RelocateLogfile(); extern void AppConfig_OnChangedSettingsFolder( bool overwrite = false ); extern wxConfigBase* GetAppConfig(); -extern ScopedPtr g_Conf; +extern std::unique_ptr g_Conf; diff --git a/pcsx2/gui/AppCorePlugins.cpp b/pcsx2/gui/AppCorePlugins.cpp index ebcdb0da67..0f10491874 100644 --- a/pcsx2/gui/AppCorePlugins.cpp +++ b/pcsx2/gui/AppCorePlugins.cpp @@ -416,14 +416,17 @@ protected: // Public API / Interface // -------------------------------------------------------------------------------------- -int EnumeratePluginsInFolder( const wxDirName& searchpath, wxArrayString* dest ) +int EnumeratePluginsInFolder(const wxDirName& searchpath, wxArrayString* dest) { if (!searchpath.Exists()) return 0; - ScopedPtr placebo; + std::unique_ptr placebo; wxArrayString* realdest = dest; - if( realdest == NULL ) - placebo = realdest = new wxArrayString(); // placebo is our /dev/null -- gets deleted when done + if (realdest == NULL) + { + placebo = std::unique_ptr(new wxArrayString()); + realdest = placebo.get(); + } #ifdef __WXMSW__ // Windows pretty well has a strict "must end in .dll" rule. @@ -558,12 +561,13 @@ void SysExecEvent_SaveSinglePlugin::InvokeEvent() if( CorePlugins.AreLoaded() ) { - ScopedPtr plugstore; + std::unique_ptr plugstore; if( CoreThread.HasActiveMachine() ) { Console.WriteLn( Color_Green, L"Suspending single plugin: " + tbl_PluginInfo[m_pid].GetShortname() ); - memSavingState save( plugstore=new VmStateBuffer(L"StateCopy_SinglePlugin") ); + plugstore = std::unique_ptr(new VmStateBuffer(L"StateCopy_SinglePlugin")); + memSavingState save( plugstore.get() ); GetCorePlugins().Freeze( m_pid, save ); } @@ -573,7 +577,7 @@ void SysExecEvent_SaveSinglePlugin::InvokeEvent() if( plugstore ) { Console.WriteLn( Color_Green, L"Recovering single plugin: " + tbl_PluginInfo[m_pid].GetShortname() ); - memLoadingState load( plugstore ); + memLoadingState load( plugstore.get() ); GetCorePlugins().Freeze( m_pid, load ); // GS plugin suspend / resume hack. Removed in r4363, hopefully never to return :p //GetCorePlugins().Close( m_pid ); // hack for stupid GS plugins. diff --git a/pcsx2/gui/AppCoreThread.cpp b/pcsx2/gui/AppCoreThread.cpp index ff41edc8cf..20589b2d07 100644 --- a/pcsx2/gui/AppCoreThread.cpp +++ b/pcsx2/gui/AppCoreThread.cpp @@ -702,13 +702,13 @@ void BaseScopedCoreThread::DoResume() // handle the code directly). bool BaseScopedCoreThread::PostToSysExec( BaseSysExecEvent_ScopedCore* msg ) { - ScopedPtr smsg( msg ); + std::unique_ptr smsg( msg ); if( !smsg || GetSysExecutorThread().IsSelf()) return false; msg->SetSyncState(m_sync); msg->SetResumeStates(m_sync_resume, m_mtx_resume); - GetSysExecutorThread().PostEvent( smsg.DetachPtr() ); + GetSysExecutorThread().PostEvent( smsg.release() ); m_sync.WaitForResult(); m_sync.RethrowException(); @@ -781,9 +781,9 @@ ScopedCoreThreadPopup::ScopedCoreThreadPopup() // is maximized or fullscreen. if( !GSopen2 ) - m_scoped_core = new ScopedCoreThreadClose(); + m_scoped_core = std::unique_ptr(new ScopedCoreThreadClose()); else - m_scoped_core = new ScopedCoreThreadPause(); + m_scoped_core = std::unique_ptr(new ScopedCoreThreadPause()); }; void ScopedCoreThreadPopup::AllowResume() diff --git a/pcsx2/gui/AppCoreThread.h b/pcsx2/gui/AppCoreThread.h index 895fb635e4..6e49661953 100644 --- a/pcsx2/gui/AppCoreThread.h +++ b/pcsx2/gui/AppCoreThread.h @@ -237,7 +237,7 @@ public: struct ScopedCoreThreadPopup : public IScopedCoreThread { protected: - ScopedPtr m_scoped_core; + std::unique_ptr m_scoped_core; public: ScopedCoreThreadPopup(); diff --git a/pcsx2/gui/AppGameDatabase.cpp b/pcsx2/gui/AppGameDatabase.cpp index e51b4e4bcb..180e19878a 100644 --- a/pcsx2/gui/AppGameDatabase.cpp +++ b/pcsx2/gui/AppGameDatabase.cpp @@ -229,10 +229,10 @@ AppGameDatabase* Pcsx2App::GetGameDatabase() ScopedLock lock( m_mtx_LoadingGameDB ); if( !res.GameDB ) { - res.GameDB = new AppGameDatabase(); + res.GameDB = std::unique_ptr(new AppGameDatabase()); res.GameDB->LoadFromFile(); } - return res.GameDB; + return res.GameDB.get(); } IGameDatabase* AppHost_GetGameDatabase() diff --git a/pcsx2/gui/AppInit.cpp b/pcsx2/gui/AppInit.cpp index 93658d614e..284129b06d 100644 --- a/pcsx2/gui/AppInit.cpp +++ b/pcsx2/gui/AppInit.cpp @@ -29,6 +29,7 @@ #include #include #include +#include using namespace pxSizerFlags; @@ -128,7 +129,7 @@ void Pcsx2App::AllocateCoreStuffs() // FIXME : Some or all of SysCpuProviderPack should be run from the SysExecutor thread, // so that the thread is safely blocked from being able to start emulation. - m_CpuProviders = new SysCpuProviderPack(); + m_CpuProviders = std::unique_ptr(new SysCpuProviderPack()); if( m_CpuProviders->HadSomeFailures( g_Conf->EmuOptions.Cpu.Recompiler ) ) { @@ -422,7 +423,7 @@ bool Pcsx2App::OnInit() pxDoAssert = AppDoAssert; pxDoOutOfMemory = SysOutOfMemory_EmergencyResponse; - g_Conf = new AppConfig(); + g_Conf = std::unique_ptr(new AppConfig()); wxInitAllImageHandlers(); Console.WriteLn("Applying operating system default language..."); @@ -472,7 +473,7 @@ bool Pcsx2App::OnInit() // PCSX2 has a lot of event handling logistics, so we *cannot* depend on wxWidgets automatic event // loop termination code. We have a much safer system in place that continues to process messages // until all "important" threads are closed out -- not just until the main frame is closed(-ish). - m_timer_Termination = new wxTimer( this, wxID_ANY ); + m_timer_Termination = std::unique_ptr(new wxTimer( this, wxID_ANY )); Connect( m_timer_Termination->GetId(), wxEVT_TIMER, wxTimerEventHandler(Pcsx2App::OnScheduledTermination) ); SetExitOnFrameDelete( false ); diff --git a/pcsx2/gui/AppMain.cpp b/pcsx2/gui/AppMain.cpp index 854566e7b8..b42717852a 100644 --- a/pcsx2/gui/AppMain.cpp +++ b/pcsx2/gui/AppMain.cpp @@ -71,7 +71,7 @@ DEFINE_EVENT_TYPE( pxEvt_LogicalVsync ); DEFINE_EVENT_TYPE( pxEvt_ThreadTaskTimeout_SysExec ); -ScopedPtr g_Conf; +std::unique_ptr g_Conf; static bool HandlePluginError( BaseException& ex ) { @@ -904,7 +904,7 @@ void Pcsx2App::PostIdleAppMethod( FnPtr_Pcsx2App method ) SysMainMemory& Pcsx2App::GetVmReserve() { - if (!m_VmReserve) m_VmReserve = new SysMainMemory(); + if (!m_VmReserve) m_VmReserve = std::unique_ptr(new SysMainMemory()); return *m_VmReserve; } diff --git a/pcsx2/gui/AppRes.cpp b/pcsx2/gui/AppRes.cpp index 1bb548ad1f..b35506ffea 100644 --- a/pcsx2/gui/AppRes.cpp +++ b/pcsx2/gui/AppRes.cpp @@ -20,6 +20,7 @@ #include #include #include +#include #include "MSWstuff.h" @@ -61,9 +62,9 @@ const wxImage& LoadImageAny( RecentIsoList::RecentIsoList(int firstIdForMenuItems_or_wxID_ANY) { - Menu = new wxMenu(); + Menu = std::unique_ptr(new wxMenu()); Menu->Append( MenuId_IsoBrowse, _("Browse..."), _("Browse for an Iso that is not in your recent history.") ); - Manager = new RecentIsoManager( Menu, firstIdForMenuItems_or_wxID_ANY ); + Manager = std::unique_ptr(new RecentIsoManager( Menu.get(), firstIdForMenuItems_or_wxID_ANY )); } pxAppResources::pxAppResources() @@ -74,13 +75,13 @@ pxAppResources::~pxAppResources() throw() {} wxMenu& Pcsx2App::GetRecentIsoMenu() { - if (!m_RecentIsoList) m_RecentIsoList = new RecentIsoList( MenuId_RecentIsos_reservedStart ); + if (!m_RecentIsoList) m_RecentIsoList = std::unique_ptr(new RecentIsoList( MenuId_RecentIsos_reservedStart )); return *m_RecentIsoList->Menu; } RecentIsoManager& Pcsx2App::GetRecentIsoManager() { - if (!m_RecentIsoList) m_RecentIsoList = new RecentIsoList( MenuId_RecentIsos_reservedStart ); + if (!m_RecentIsoList) m_RecentIsoList = std::unique_ptr(new RecentIsoList( MenuId_RecentIsos_reservedStart )); return *m_RecentIsoList->Manager; } @@ -88,17 +89,17 @@ pxAppResources& Pcsx2App::GetResourceCache() { ScopedLock lock( m_mtx_Resources ); if( !m_Resources ) - m_Resources = new pxAppResources(); + m_Resources = std::unique_ptr(new pxAppResources()); return *m_Resources; } const wxIconBundle& Pcsx2App::GetIconBundle() { - ScopedPtr& bundle( GetResourceCache().IconBundle ); + std::unique_ptr& bundle( GetResourceCache().IconBundle ); if( !bundle ) { - bundle = new wxIconBundle(); + bundle = std::unique_ptr(new wxIconBundle()); bundle->AddIcon( EmbeddedImage().GetIcon() ); bundle->AddIcon( EmbeddedImage().GetIcon() ); bundle->AddIcon( EmbeddedImage().GetIcon() ); @@ -109,7 +110,7 @@ const wxIconBundle& Pcsx2App::GetIconBundle() const wxBitmap& Pcsx2App::GetLogoBitmap() { - ScopedPtr& logo( GetResourceCache().Bitmap_Logo ); + std::unique_ptr & logo(GetResourceCache().Bitmap_Logo); if( logo ) return *logo; wxFileName themeDirectory; @@ -137,14 +138,14 @@ const wxBitmap& Pcsx2App::GetLogoBitmap() EmbeddedImage temp; // because gcc can't allow non-const temporaries. LoadImageAny(img, useTheme, themeDirectory, L"BackgroundLogo", temp); float scale = MSW_GetDPIScale(); // 1.0 for non-Windows - logo = new wxBitmap(img.Scale(img.GetWidth() * scale, img.GetHeight() * scale, wxIMAGE_QUALITY_HIGH)); + logo = std::unique_ptr(new wxBitmap(img.Scale(img.GetWidth() * scale, img.GetHeight() * scale, wxIMAGE_QUALITY_HIGH))); return *logo; } const wxBitmap& Pcsx2App::GetScreenshotBitmap() { - ScopedPtr& screenshot(GetResourceCache().ScreenshotBitmap); + std::unique_ptr& screenshot(GetResourceCache().ScreenshotBitmap); if (screenshot) return *screenshot; wxFileName themeDirectory; @@ -159,18 +160,18 @@ const wxBitmap& Pcsx2App::GetScreenshotBitmap() EmbeddedImage temp; // because gcc can't allow non-const temporaries. LoadImageAny(img, useTheme, themeDirectory, L"ButtonIcon_Camera", temp); float scale = MSW_GetDPIScale(); // 1.0 for non-Windows - screenshot = new wxBitmap(img.Scale(img.GetWidth() * scale, img.GetHeight() * scale, wxIMAGE_QUALITY_HIGH)); + screenshot = std::unique_ptr(new wxBitmap(img.Scale(img.GetWidth() * scale, img.GetHeight() * scale, wxIMAGE_QUALITY_HIGH))); return *screenshot; } wxImageList& Pcsx2App::GetImgList_Config() { - ScopedPtr& images( GetResourceCache().ConfigImages ); + std::unique_ptr& images( GetResourceCache().ConfigImages ); if( !images ) { int image_size = MSW_GetDPIScale() * g_Conf->Listbook_ImageSize; - images = new wxImageList(image_size, image_size); + images = std::unique_ptr(new wxImageList(image_size, image_size)); wxFileName themeDirectory; bool useTheme = (g_Conf->DeskTheme != L"default"); @@ -213,12 +214,12 @@ wxImageList& Pcsx2App::GetImgList_Config() // This stuff seems unused? wxImageList& Pcsx2App::GetImgList_Toolbars() { - ScopedPtr& images( GetResourceCache().ToolbarImages ); + std::unique_ptr& images( GetResourceCache().ToolbarImages ); if( !images ) { const int imgSize = g_Conf->Toolbar_ImageSize ? 64 : 32; - images = new wxImageList( imgSize, imgSize ); + images = std::unique_ptr(new wxImageList(imgSize, imgSize)); wxFileName mess; bool useTheme = (g_Conf->DeskTheme != L"default"); diff --git a/pcsx2/gui/AppUserMode.cpp b/pcsx2/gui/AppUserMode.cpp index 348624e2c1..f05d2a2927 100644 --- a/pcsx2/gui/AppUserMode.cpp +++ b/pcsx2/gui/AppUserMode.cpp @@ -129,7 +129,7 @@ wxConfigBase* Pcsx2App::TestForPortableInstall() // mode. In order to determine our read/write permissions to the PCSX2, we must try to // modify the configured documents folder, and catch any ensuing error. - ScopedPtr conf_portable( OpenFileConfig( portableIniFile.GetFullPath() ) ); + std::unique_ptr conf_portable( OpenFileConfig( portableIniFile.GetFullPath() ) ); conf_portable->SetRecordDefaults(false); while( true ) @@ -187,7 +187,7 @@ wxConfigBase* Pcsx2App::TestForPortableInstall() InstallationMode = InstallMode_Portable; DocsFolderMode = DocsFolder_Custom; CustomDocumentsFolder = portableDocsFolder; - return conf_portable.DetachPtr(); + return conf_portable.release(); } return NULL; @@ -200,13 +200,13 @@ void Pcsx2App::WipeUserModeSettings() { // Remove the portable.ini entry "RunWizard" conforming to this instance of PCSX2. wxFileName portableIniFile( GetPortableIniPath() ); - ScopedPtr conf_portable( OpenFileConfig( portableIniFile.GetFullPath() ) ); + std::unique_ptr conf_portable( OpenFileConfig( portableIniFile.GetFullPath() ) ); conf_portable->DeleteEntry(L"RunWizard"); } else { // Remove the registry entry "RunWizard" conforming to this instance of PCSX2. - ScopedPtr conf_install( OpenInstallSettingsFile() ); + std::unique_ptr conf_install( OpenInstallSettingsFile() ); conf_install->DeleteEntry(L"RunWizard"); } } @@ -237,10 +237,10 @@ wxConfigBase* Pcsx2App::OpenInstallSettingsFile() // the old system (CWD-based ini file mess) in favor of a system that simply stores // most core application-level settings in the registry. - ScopedPtr conf_install; + std::unique_ptr conf_install; #ifdef __WXMSW__ - conf_install = new wxRegConfig(); + conf_install = std::unique_ptr(new wxRegConfig()); #else // FIXME!! Linux / Mac // Where the heck should this information be stored? @@ -255,31 +255,31 @@ wxConfigBase* Pcsx2App::OpenInstallSettingsFile() wxFileName usermodefile( GetAppName() + L"-reg.ini" ); usermodefile.SetPath( usrlocaldir.ToString() ); - conf_install = OpenFileConfig( usermodefile.GetFullPath() ); + conf_install = std::unique_ptr(OpenFileConfig( usermodefile.GetFullPath() )); #endif - return conf_install.DetachPtr(); + return conf_install.release(); } void Pcsx2App::ForceFirstTimeWizardOnNextRun() { - ScopedPtr conf_install; + std::unique_ptr conf_install; - conf_install = TestForPortableInstall(); + conf_install = std::unique_ptr(TestForPortableInstall()); if (!conf_install) - conf_install = OpenInstallSettingsFile(); + conf_install = std::unique_ptr(OpenInstallSettingsFile()); conf_install->Write( L"RunWizard", true ); } void Pcsx2App::EstablishAppUserMode() { - ScopedPtr conf_install; + std::unique_ptr conf_install; - conf_install = TestForPortableInstall(); + conf_install = std::unique_ptr(TestForPortableInstall()); if (!conf_install) - conf_install = OpenInstallSettingsFile(); + conf_install = std::unique_ptr(OpenInstallSettingsFile()); conf_install->SetRecordDefaults(false); @@ -292,7 +292,7 @@ void Pcsx2App::EstablishAppUserMode() bool runWiz; conf_install->Read( L"RunWizard", &runWiz, true ); - App_LoadInstallSettings( conf_install ); + App_LoadInstallSettings( conf_install.get() ); if( !Startup.ForceWizard && !runWiz ) { @@ -303,7 +303,7 @@ void Pcsx2App::EstablishAppUserMode() DoFirstTimeWizard(); // Save user's new settings - App_SaveInstallSettings( conf_install ); + App_SaveInstallSettings( conf_install.get() ); AppConfig_OnChangedSettingsFolder( true ); AppSaveSettings(); diff --git a/pcsx2/gui/ConsoleLogger.cpp b/pcsx2/gui/ConsoleLogger.cpp index d81da96e75..0d2a80ccca 100644 --- a/pcsx2/gui/ConsoleLogger.cpp +++ b/pcsx2/gui/ConsoleLogger.cpp @@ -1174,16 +1174,16 @@ void Pcsx2App::EnableAllLogging() if( emuLog ) { - if( !m_StdoutRedirHandle ) m_StdoutRedirHandle = NewPipeRedir(stdout); - if( !m_StderrRedirHandle ) m_StderrRedirHandle = NewPipeRedir(stderr); + if( !m_StdoutRedirHandle ) m_StdoutRedirHandle = std::unique_ptr(NewPipeRedir(stdout)); + if( !m_StderrRedirHandle ) m_StderrRedirHandle = std::unique_ptr(NewPipeRedir(stderr)); newHandler = logBoxOpen ? (IConsoleWriter*)&ConsoleWriter_WindowAndFile : (IConsoleWriter*)&ConsoleWriter_File; } else { if( logBoxOpen ) { - if( !m_StdoutRedirHandle ) m_StdoutRedirHandle = NewPipeRedir(stdout); - if( !m_StderrRedirHandle ) m_StderrRedirHandle = NewPipeRedir(stderr); + if (!m_StdoutRedirHandle) m_StdoutRedirHandle = std::unique_ptr(NewPipeRedir(stdout)); + if (!m_StderrRedirHandle) m_StderrRedirHandle = std::unique_ptr(NewPipeRedir(stderr)); newHandler = &ConsoleWriter_Window; } else diff --git a/pcsx2/gui/ConsoleLogger.h b/pcsx2/gui/ConsoleLogger.h index 62bd2aefb7..674e401723 100644 --- a/pcsx2/gui/ConsoleLogger.h +++ b/pcsx2/gui/ConsoleLogger.h @@ -100,7 +100,7 @@ class pxLogTextCtrl : public wxTextCtrl, public EventListener_Plugins { protected: - ScopedPtr m_IsPaused; + std::unique_ptr m_IsPaused; bool m_FreezeWrites; public: @@ -213,7 +213,7 @@ protected: // Threaded log spammer, useful for testing console logging performance. // (alternatively you can enable Disasm logging in any recompiler and achieve // a similar effect) - ScopedPtr m_threadlogger; + std::unique_ptr m_threadlogger; public: // ctor & dtor diff --git a/pcsx2/gui/CpuUsageProvider.h b/pcsx2/gui/CpuUsageProvider.h index 18528dcf0e..a52c55be5c 100644 --- a/pcsx2/gui/CpuUsageProvider.h +++ b/pcsx2/gui/CpuUsageProvider.h @@ -16,6 +16,7 @@ #pragma once #include "AppEventListeners.h" +#include class BaseCpuUsageProvider { @@ -35,7 +36,7 @@ public: class CpuUsageProvider : public BaseCpuUsageProvider { protected: - ScopedPtr m_Implementation; + std::unique_ptr m_Implementation; public: CpuUsageProvider(); diff --git a/pcsx2/gui/ExecutorThread.cpp b/pcsx2/gui/ExecutorThread.cpp index 2ab3a07b66..30f326f2d4 100644 --- a/pcsx2/gui/ExecutorThread.cpp +++ b/pcsx2/gui/ExecutorThread.cpp @@ -15,6 +15,7 @@ #include "PrecompiledHeader.h" #include "App.h" +#include using namespace pxSizerFlags; @@ -197,7 +198,7 @@ void pxEvtQueue::ProcessEvents( pxEvtList& list, bool isIdle ) pxEvtList::iterator node; while( node = list.begin(), node != list.end() ) { - ScopedPtr deleteMe(*node); + std::unique_ptr deleteMe(*node); list.erase( node ); if( !m_Quitting || deleteMe->IsCriticalEvent() ) @@ -210,7 +211,7 @@ void pxEvtQueue::ProcessEvents( pxEvtList& list, bool isIdle ) synclock.Release(); - pxEvtLog.Write( this, deleteMe, wxsFormat(L"Executing... [%s]%s", + pxEvtLog.Write( this, deleteMe.get(), wxsFormat(L"Executing... [%s]%s", deleteMe->AllowCancelOnExit() ? L"Cancelable" : L"Noncancelable", isIdle ? L"(Idle)" : wxEmptyString).wc_str() ); @@ -223,7 +224,7 @@ void pxEvtQueue::ProcessEvents( pxEvtList& list, bool isIdle ) } u64 qpc_end = GetCPUTicks(); - pxEvtLog.Write( this, deleteMe, wxsFormat(L"Event completed in %ums", + pxEvtLog.Write( this, deleteMe.get(), wxsFormat(L"Event completed in %ums", (u32)(((qpc_end-m_qpc_Start)*1000) / GetTickFrequency())).wc_str() ); @@ -232,7 +233,7 @@ void pxEvtQueue::ProcessEvents( pxEvtList& list, bool isIdle ) } else { - pxEvtLog.Write( this, deleteMe, L"Skipping Event: %s" ); + pxEvtLog.Write( this, deleteMe.get(), L"Skipping Event: %s" ); deleteMe->PostResult(); } } @@ -263,7 +264,7 @@ void pxEvtQueue::AddPendingEvent( SysExecEvent& evt ) // void pxEvtQueue::PostEvent( SysExecEvent* evt ) { - ScopedPtr sevt( evt ); + std::unique_ptr sevt(evt); if( !sevt ) return; if( m_Quitting ) @@ -276,7 +277,7 @@ void pxEvtQueue::PostEvent( SysExecEvent* evt ) pxEvtLog.Write( this, evt, pxsFmt(L"Posting event! (pending=%d, idle=%d)", m_pendingEvents.size(), m_idleEvents.size()) ); - m_pendingEvents.push_back( sevt.DetachPtr() ); + m_pendingEvents.push_back( sevt.release() ); if( m_pendingEvents.size() == 1) m_wakeup.Post(); } @@ -340,7 +341,7 @@ void pxEvtQueue::ProcessEvent( SysExecEvent* evt ) } else { - ScopedPtr deleteMe( evt ); + std::unique_ptr deleteMe(evt); deleteMe->_DoInvokeEvent(); } } @@ -452,9 +453,9 @@ void WaitingForThreadedTaskDialog::OnTerminateApp_Clicked( wxCommandEvent& evt ) // -------------------------------------------------------------------------------------- // ExecutorThread Implementations // -------------------------------------------------------------------------------------- -ExecutorThread::ExecutorThread( pxEvtQueue* evthandler ) +ExecutorThread::ExecutorThread(pxEvtQueue* evthandler) + : m_EvtHandler(evthandler) { - m_EvtHandler = evthandler; } bool ExecutorThread::IsRunning() const @@ -507,7 +508,7 @@ void ExecutorThread::ProcessEvent( SysExecEvent* evt ) m_EvtHandler->ProcessEvent( evt ); else { - ScopedPtr deleteMe( evt ); + std::unique_ptr deleteMe(evt); deleteMe->_DoInvokeEvent(); } } diff --git a/pcsx2/gui/FrameForGS.cpp b/pcsx2/gui/FrameForGS.cpp index 2928c7089f..e44df5c55f 100644 --- a/pcsx2/gui/FrameForGS.cpp +++ b/pcsx2/gui/FrameForGS.cpp @@ -23,6 +23,7 @@ #include "MSWstuff.h" #include +#include static const KeyAcceleratorCode FULLSCREEN_TOGGLE_ACCELERATOR_GSPANEL=KeyAcceleratorCode( WXK_RETURN ).Alt(); @@ -37,7 +38,7 @@ void GSPanel::InitDefaultAccelerators() typedef KeyAcceleratorCode AAC; - if( !m_Accels ) m_Accels = new AcceleratorDictionary; + if (!m_Accels) m_Accels = std::unique_ptr(new AcceleratorDictionary); m_Accels->Map( AAC( WXK_F1 ), "States_FreezeCurrentSlot" ); m_Accels->Map( AAC( WXK_F3 ), "States_DefrostCurrentSlot"); diff --git a/pcsx2/gui/GSFrame.h b/pcsx2/gui/GSFrame.h index bff1e4bd37..59f664fb73 100644 --- a/pcsx2/gui/GSFrame.h +++ b/pcsx2/gui/GSFrame.h @@ -18,6 +18,7 @@ #include "AppCommon.h" #include "CpuUsageProvider.h" +#include enum LimiterModeType @@ -39,7 +40,7 @@ class GSPanel : public wxWindow typedef wxWindow _parent; protected: - ScopedPtr m_Accels; + std::unique_ptr m_Accels; wxTimer m_HideMouseTimer; bool m_CursorShown; diff --git a/pcsx2/gui/GlobalCommands.cpp b/pcsx2/gui/GlobalCommands.cpp index 389591c11b..f462878d01 100644 --- a/pcsx2/gui/GlobalCommands.cpp +++ b/pcsx2/gui/GlobalCommands.cpp @@ -711,7 +711,7 @@ void AcceleratorDictionary::Map( const KeyAcceleratorCode& _acode, const char *s void Pcsx2App::BuildCommandHash() { - if( !GlobalCommands ) GlobalCommands = new CommandDictionary; + if( !GlobalCommands ) GlobalCommands = std::unique_ptr(new CommandDictionary); const GlobalCommandDescriptor* curcmd = CommandDeclarations; while( curcmd->Invoke != NULL ) @@ -725,7 +725,7 @@ void Pcsx2App::InitDefaultGlobalAccelerators() { typedef KeyAcceleratorCode AAC; - if( !GlobalAccels ) GlobalAccels = new AcceleratorDictionary; + if( !GlobalAccels ) GlobalAccels = std::unique_ptr(new AcceleratorDictionary); // Why do we even have those here? all of them seem to be overridden // by GSPanel::m_Accels ( GSPanel::InitDefaultAccelerators() ) diff --git a/pcsx2/gui/MainMenuClicks.cpp b/pcsx2/gui/MainMenuClicks.cpp index 937c5b7f67..5e2ed8be81 100644 --- a/pcsx2/gui/MainMenuClicks.cpp +++ b/pcsx2/gui/MainMenuClicks.cpp @@ -93,7 +93,7 @@ static void WipeSettings() //wxRmdir( GetSettingsFolder().ToString() ); wxGetApp().GetRecentIsoManager().Clear(); - g_Conf = new AppConfig(); + g_Conf = std::unique_ptr(new AppConfig()); sMainFrame.RemoveCdvdMenu(); sApp.WipeUserModeSettings(); diff --git a/pcsx2/gui/Panels/BiosSelectorPanel.cpp b/pcsx2/gui/Panels/BiosSelectorPanel.cpp index dd8a1a401d..24d9a4b1ce 100644 --- a/pcsx2/gui/Panels/BiosSelectorPanel.cpp +++ b/pcsx2/gui/Panels/BiosSelectorPanel.cpp @@ -22,6 +22,7 @@ #include #include #include +#include using namespace pxSizerFlags; @@ -150,17 +151,17 @@ bool Panels::BiosSelectorPanel::ValidateEnumerationStatus() { bool validated = true; - // Impl Note: ScopedPtr used so that resources get cleaned up if an exception + // Impl Note: unique_ptr used so that resources get cleaned up if an exception // occurs during file enumeration. - ScopedPtr bioslist( new wxArrayString() ); + std::unique_ptr bioslist(new wxArrayString()); if( m_FolderPicker->GetPath().Exists() ) - wxDir::GetAllFiles( m_FolderPicker->GetPath().ToString(), bioslist, L"*.*", wxDIR_FILES ); + wxDir::GetAllFiles(m_FolderPicker->GetPath().ToString(), bioslist.get(), L"*.*", wxDIR_FILES); if( !m_BiosList || (*bioslist != *m_BiosList) ) validated = false; - m_BiosList.SwapPtr( bioslist ); + m_BiosList.swap(bioslist); return validated; } diff --git a/pcsx2/gui/Panels/ConfigurationPanels.h b/pcsx2/gui/Panels/ConfigurationPanels.h index 6994310520..beac5c48a4 100644 --- a/pcsx2/gui/Panels/ConfigurationPanels.h +++ b/pcsx2/gui/Panels/ConfigurationPanels.h @@ -23,6 +23,7 @@ #include #include +#include #include "AppCommon.h" #include "ApplyState.h" @@ -492,9 +493,9 @@ namespace Panels typedef BaseSelectorPanel _parent; protected: - ScopedPtr m_ThemeList; - wxListBox* m_ComboBox; - DirPickerPanel* m_FolderPicker; + std::unique_ptr m_ThemeList; + wxListBox* m_ComboBox; + DirPickerPanel* m_FolderPicker; public: virtual ~ThemeSelectorPanel() throw(); @@ -513,9 +514,9 @@ namespace Panels class BiosSelectorPanel : public BaseSelectorPanel { protected: - ScopedPtr m_BiosList; - wxListBox* m_ComboBox; - DirPickerPanel* m_FolderPicker; + std::unique_ptr m_BiosList; + wxListBox* m_ComboBox; + DirPickerPanel* m_FolderPicker; public: BiosSelectorPanel( wxWindow* parent ); @@ -620,8 +621,8 @@ namespace Panels ComboBoxPanel* m_ComponentBoxes; bool m_Canceled; - ScopedPtr m_FileList; // list of potential plugin files - ScopedPtr m_EnumeratorThread; + std::unique_ptr m_FileList; // list of potential plugin files + std::unique_ptr m_EnumeratorThread; public: virtual ~PluginSelectorPanel() throw(); diff --git a/pcsx2/gui/Panels/GameFixesPanel.cpp b/pcsx2/gui/Panels/GameFixesPanel.cpp index e64bd5f0d2..1093b2cdf2 100644 --- a/pcsx2/gui/Panels/GameFixesPanel.cpp +++ b/pcsx2/gui/Panels/GameFixesPanel.cpp @@ -147,7 +147,7 @@ void Panels::GameFixesPanel::Apply() void Panels::GameFixesPanel::EnableStuff( AppConfig* configToUse ) { - if( !configToUse ) configToUse = g_Conf; + if (!configToUse) configToUse = g_Conf.get(); for (GamefixId i=GamefixId_FIRST; i < pxEnumEnd; ++i) m_checkbox[i]->Enable(m_check_Enable->GetValue() && !configToUse->EnablePresets); diff --git a/pcsx2/gui/Panels/PluginSelectorPanel.cpp b/pcsx2/gui/Panels/PluginSelectorPanel.cpp index 37532ffe22..7f5bf61606 100644 --- a/pcsx2/gui/Panels/PluginSelectorPanel.cpp +++ b/pcsx2/gui/Panels/PluginSelectorPanel.cpp @@ -17,6 +17,7 @@ #include #include +#include #include "App.h" #include "AppSaveStates.h" @@ -256,7 +257,7 @@ void SysExecEvent_ApplyPlugins::InvokeEvent() { ScopedCoreThreadPause paused_core; - ScopedPtr< VmStateBuffer > buffer; + std::unique_ptr buffer; if( SysHasValidState() ) { @@ -268,7 +269,8 @@ void SysExecEvent_ApplyPlugins::InvokeEvent() // FIXME : We only actually have to save plugins here, except the recovery code // in SysCoreThread isn't quite set up yet to handle that (I think...) --air - memSavingState saveme( *(buffer.Reassign(new VmStateBuffer(L"StateBuffer_ApplyNewPlugins"))) ); + buffer.reset(new VmStateBuffer(L"StateBuffer_ApplyNewPlugins")); + memSavingState saveme(buffer.get()); saveme.FreezeAll(); } @@ -546,7 +548,7 @@ void Panels::PluginSelectorPanel::DoRefresh() wxCommandEvent evt( pxEVT_ShowStatusBar ); GetEventHandler()->AddPendingEvent( evt ); - m_EnumeratorThread.Reassign(new EnumThread( *this )); + m_EnumeratorThread.reset(new EnumThread(*this)); if( DisableThreading ) m_EnumeratorThread->DoNextPlugin( 0 ); @@ -563,11 +565,11 @@ bool Panels::PluginSelectorPanel::ValidateEnumerationStatus() // re-enumerate plugins, and if anything changed then we need to wipe // the contents of the combo boxes and re-enumerate everything. - // Impl Note: ScopedPtr used so that resources get cleaned up if an exception + // Impl Note: unique_ptr used so that resources get cleaned up if an exception // occurs during file enumeration. - ScopedPtr pluginlist( new wxArrayString() ); + std::unique_ptr pluginlist(new wxArrayString()); - int pluggers = EnumeratePluginsInFolder( m_ComponentBoxes->GetPluginsPath(), pluginlist ); + int pluggers = EnumeratePluginsInFolder(m_ComponentBoxes->GetPluginsPath(), pluginlist.get()); if( !m_FileList || (*pluginlist != *m_FileList) ) validated = false; @@ -578,7 +580,7 @@ bool Panels::PluginSelectorPanel::ValidateEnumerationStatus() return validated; } - m_FileList.SwapPtr( pluginlist ); + m_FileList.swap(pluginlist); // set the gague length a little shorter than the plugin count. 2 reasons: // * some of the plugins might be duds. @@ -699,7 +701,7 @@ void Panels::PluginSelectorPanel::OnProgress( wxCommandEvent& evt ) // The thread can get canceled and replaced with a new thread, which means all // pending messages should be ignored. - if( m_EnumeratorThread != (EnumThread*)evt.GetClientData() ) return; + if (m_EnumeratorThread.get() != (EnumThread*)evt.GetClientData()) return; const size_t evtidx = evt.GetExtraLong(); diff --git a/pcsx2/gui/Panels/SpeedhacksPanel.cpp b/pcsx2/gui/Panels/SpeedhacksPanel.cpp index 5aa8abf2b0..a726aac43c 100644 --- a/pcsx2/gui/Panels/SpeedhacksPanel.cpp +++ b/pcsx2/gui/Panels/SpeedhacksPanel.cpp @@ -251,7 +251,7 @@ Panels::SpeedHacksPanel::SpeedHacksPanel( wxWindow* parent ) // Doesn't modify values - only locks(gray out)/unlocks as necessary. void Panels::SpeedHacksPanel::EnableStuff( AppConfig* configToUse ) { - if( !configToUse ) configToUse = g_Conf; + if (!configToUse) configToUse = g_Conf.get(); bool hasPreset = configToUse->EnablePresets; bool hacksEnabled = configToUse->EnableSpeedHacks; diff --git a/pcsx2/gui/Panels/ThemeSelectorPanel.cpp b/pcsx2/gui/Panels/ThemeSelectorPanel.cpp index e9044824f6..187ee198a3 100644 --- a/pcsx2/gui/Panels/ThemeSelectorPanel.cpp +++ b/pcsx2/gui/Panels/ThemeSelectorPanel.cpp @@ -21,6 +21,7 @@ #include #include #include +#include using namespace pxSizerFlags; @@ -73,20 +74,20 @@ bool Panels::ThemeSelectorPanel::ValidateEnumerationStatus() { bool validated = true; - // Impl Note: ScopedPtr used so that resources get cleaned up if an exception + // Impl Note: unique_ptr used so that resources get cleaned up if an exception // occurs during file enumeration. - ScopedPtr themelist( new wxArrayString() ); + std::unique_ptr themelist(new wxArrayString()); if( m_FolderPicker->GetPath().Exists() ) { - wxDir::GetAllFiles( m_FolderPicker->GetPath().ToString(), themelist, L"*.zip;*.p2ui", wxDIR_FILES ); - wxDir::GetAllFiles( m_FolderPicker->GetPath().ToString(), themelist, L"*.*", wxDIR_DIRS ); + wxDir::GetAllFiles(m_FolderPicker->GetPath().ToString(), themelist.get(), L"*.zip;*.p2ui", wxDIR_FILES); + wxDir::GetAllFiles(m_FolderPicker->GetPath().ToString(), themelist.get(), L"*.*", wxDIR_DIRS); } if( !m_ThemeList || (*themelist != *m_ThemeList) ) validated = false; - m_ThemeList.SwapPtr( themelist ); + m_ThemeList.swap(themelist); return validated; } diff --git a/pcsx2/gui/RecentIsoList.h b/pcsx2/gui/RecentIsoList.h index e339542370..fd61759cb5 100644 --- a/pcsx2/gui/RecentIsoList.h +++ b/pcsx2/gui/RecentIsoList.h @@ -72,8 +72,8 @@ protected: // -------------------------------------------------------------------------------------- struct RecentIsoList { - ScopedPtr Manager; - ScopedPtr Menu; + std::unique_ptr Manager; + std::unique_ptr Menu; RecentIsoList(int firstIdForMenuItems_or_wxID_ANY); virtual ~RecentIsoList() throw() { } diff --git a/pcsx2/gui/SysState.cpp b/pcsx2/gui/SysState.cpp index 2c43fed888..bb862cd618 100644 --- a/pcsx2/gui/SysState.cpp +++ b/pcsx2/gui/SysState.cpp @@ -25,6 +25,7 @@ #include "Utilities/pxStreams.h" #include +#include // Used to hold the current state backup (fullcopy of PS2 memory and plugin states). //static VmStateBuffer state_buffer( L"Public Savestate Buffer" ); @@ -422,7 +423,7 @@ protected: void InvokeEvent() { // Provisionals for scoped cleanup, in case of exception: - ScopedPtr elist( m_src_list ); + std::unique_ptr elist(m_src_list); wxString tempfile( m_filename + L".tmp" ); @@ -437,7 +438,7 @@ protected: pxYield(4); // Write the version and screenshot: - ScopedPtr out( new pxOutputStream(tempfile, new wxZipOutputStream(woot)) ); + std::unique_ptr out(new pxOutputStream(tempfile, new wxZipOutputStream(woot))); wxZipOutputStream* gzfp = (wxZipOutputStream*)out->GetWxStreamBase(); { @@ -448,7 +449,7 @@ protected: gzfp->CloseEntry(); } - ScopedPtr m_screenshot; + std::unique_ptr m_screenshot; if (m_screenshot) { @@ -460,14 +461,14 @@ protected: } (*new VmStateCompressThread()) - .SetSource(elist) - .SetOutStream(out) + .SetSource(elist.get()) + .SetOutStream(out.get()) .SetFinishedPath(m_filename) .Start(); // No errors? Release cleanup handlers: - elist.DetachPtr(); - out.DetachPtr(); + elist.release(); + out.release(); } void CleanupEvent() @@ -506,12 +507,12 @@ protected: // Ugh. Exception handling made crappy because wxWidgets classes don't support scoped pointers yet. - ScopedPtr woot( new wxFFileInputStream(m_filename) ); + std::unique_ptr woot(new wxFFileInputStream(m_filename)); if (!woot->IsOk()) throw Exception::CannotCreateStream( m_filename ).SetDiagMsg(L"Cannot open file for reading."); - ScopedPtr reader( new pxInputStream(m_filename, new wxZipInputStream(woot)) ); - woot.DetachPtr(); + std::unique_ptr reader(new pxInputStream(m_filename, new wxZipInputStream(woot.get()))); + woot.release(); if (!reader->IsOk()) { @@ -528,14 +529,14 @@ protected: //bool foundScreenshot = false; //bool foundEntry[numSavestateEntries] = false; - ScopedPtr foundInternal; - ScopedPtr foundEntry[NumSavestateEntries]; + std::unique_ptr foundInternal; + std::unique_ptr foundEntry[NumSavestateEntries]; while(true) { Threading::pxTestCancel(); - ScopedPtr entry( gzreader->GetNextEntry() ); + std::unique_ptr entry(gzreader->GetNextEntry()); if (!entry) break; if (entry->GetName().CmpNoCase(EntryFilename_StateVersion) == 0) @@ -549,7 +550,7 @@ protected: if (entry->GetName().CmpNoCase(EntryFilename_InternalStructures) == 0) { DevCon.WriteLn( Color_Green, L" ... found '%s'", EntryFilename_InternalStructures); - foundInternal = entry.DetachPtr(); + foundInternal = std::move(entry); continue; } @@ -565,7 +566,7 @@ protected: if (entry->GetName().CmpNoCase(SavestateEntries[i]->GetFilename()) == 0) { DevCon.WriteLn( Color_Green, L" ... found '%s'", WX_STR(SavestateEntries[i]->GetFilename()) ); - foundEntry[i] = entry.DetachPtr(); + foundEntry[i] = std::move(entry); break; } } @@ -633,12 +634,12 @@ void StateCopy_SaveToFile( const wxString& file ) { UI_DisableStateActions(); - ScopedPtr ziplist (new ArchiveEntryList( new VmStateBuffer( L"Zippable Savestate" ) )); + std::unique_ptr ziplist(new ArchiveEntryList(new VmStateBuffer(L"Zippable Savestate"))); - GetSysExecutorThread().PostEvent(new SysExecEvent_DownloadState ( ziplist )); - GetSysExecutorThread().PostEvent(new SysExecEvent_ZipToDisk ( ziplist, file )); + GetSysExecutorThread().PostEvent(new SysExecEvent_DownloadState(ziplist.get())); + GetSysExecutorThread().PostEvent(new SysExecEvent_ZipToDisk(ziplist.get(), file)); - ziplist.DetachPtr(); + ziplist.release(); } void StateCopy_LoadFromFile( const wxString& file ) diff --git a/pcsx2/gui/i18n.cpp b/pcsx2/gui/i18n.cpp index 96c96071aa..25a5887da8 100644 --- a/pcsx2/gui/i18n.cpp +++ b/pcsx2/gui/i18n.cpp @@ -16,8 +16,8 @@ #include "PrecompiledHeader.h" #include "i18n.h" #include "AppConfig.h" - #include "Utilities/SafeArray.h" +#include // Some of the codes provided by wxWidgets are 'obsolete' -- effectively replaced by more specific // region-qualified language codes. This function can be used to filter them out. @@ -80,9 +80,9 @@ static void i18n_DoPackageCheck( wxLanguage wxLangId, LangPackList& langs, bool& // note: wx preserves the current locale for us, so creating a new locale and deleting // will not affect program status. #if wxMAJOR_VERSION < 3 - ScopedPtr locale( new wxLocale( wxLangId, wxLOCALE_CONV_ENCODING ) ); + std::unique_ptr locale(new wxLocale(wxLangId, wxLOCALE_CONV_ENCODING)); #else - ScopedPtr locale( new wxLocale( wxLangId, 0 ) ); + std::unique_ptr locale(new wxLocale(wxLangId, 0)); #endif // Force the msgIdLanguage param to wxLANGUAGE_UNKNOWN to disable wx's automatic english @@ -304,7 +304,7 @@ bool i18n_SetLanguage( wxLanguage wxLangId, const wxString& langCode ) if (!info) return false; if (wxGetLocale() && (info->Language == wxGetLocale()->GetLanguage())) return true; - ScopedPtr locale( new wxLocale(info->Language) ); + std::unique_ptr locale(new wxLocale(info->Language)); if( !locale->IsOk() ) { @@ -325,7 +325,7 @@ bool i18n_SetLanguage( wxLanguage wxLangId, const wxString& langCode ) // English/US is built in, so no need to load MO/PO files. if( pxIsEnglish(wxLangId) ) { - locale.DetachPtr(); + locale.release(); return true; } @@ -356,7 +356,7 @@ bool i18n_SetLanguage( wxLanguage wxLangId, const wxString& langCode ) return false; } - locale.DetachPtr(); + locale.release(); return true; } diff --git a/pcsx2/gui/pxEventThread.h b/pcsx2/gui/pxEventThread.h index 304021df97..56f4ca973c 100644 --- a/pcsx2/gui/pxEventThread.h +++ b/pcsx2/gui/pxEventThread.h @@ -17,7 +17,7 @@ #include "Utilities/PersistentThread.h" #include "Utilities/pxEvents.h" - +#include // TODO!! Make the system defined in this header system a bit more generic, and then move // it to the Utilities library. @@ -266,8 +266,8 @@ class ExecutorThread : public Threading::pxThread typedef Threading::pxThread _parent; protected: - ScopedPtr m_ExecutorTimer; - ScopedPtr m_EvtHandler; + std::unique_ptr m_ExecutorTimer; + std::unique_ptr m_EvtHandler; public: ExecutorThread( pxEvtQueue* evtandler = NULL ); diff --git a/pcsx2/gui/pxLogTextCtrl.cpp b/pcsx2/gui/pxLogTextCtrl.cpp index f7a2bc9327..6ec310ff23 100644 --- a/pcsx2/gui/pxLogTextCtrl.cpp +++ b/pcsx2/gui/pxLogTextCtrl.cpp @@ -20,6 +20,7 @@ #ifdef __WXMSW__ # include // needed for windows-specific rich text messages to make scrolling not lame #endif +#include void pxLogTextCtrl::DispatchEvent( const CoreThreadStatus& status ) { @@ -65,7 +66,7 @@ void pxLogTextCtrl::OnThumbTrack(wxScrollWinEvent& evt) //Console.Warning( "Thumb Tracking!!!" ); m_FreezeWrites = true; if( !m_IsPaused ) - m_IsPaused = new ScopedCoreThreadPause(); + m_IsPaused = std::unique_ptr(new ScopedCoreThreadPause()); evt.Skip(); } @@ -77,7 +78,7 @@ void pxLogTextCtrl::OnThumbRelease(wxScrollWinEvent& evt) if( m_IsPaused ) { m_IsPaused->AllowResume(); - m_IsPaused.Delete(); + m_IsPaused = nullptr; } evt.Skip(); } From 499fed40f2bfc7957b0ee739ee0e0e8fa6751268 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 27 Jan 2016 17:49:03 +0000 Subject: [PATCH 4/6] pcsx2: Convert ScopedPtr to unique_ptr --- pcsx2/GSState.cpp | 5 +++-- pcsx2/PluginManager.cpp | 6 +++--- pcsx2/Plugins.h | 2 +- pcsx2/PrecompiledHeader.h | 1 - pcsx2/System.cpp | 16 ++++++++-------- pcsx2/System.h | 2 +- pcsx2/ZipTools/ThreadedZipTools.h | 11 +++++------ pcsx2/x86/microVU.cpp | 2 +- pcsx2/x86/microVU.h | 9 +++++---- pcsx2/x86/microVU_Log.inl | 4 ++-- 10 files changed, 29 insertions(+), 29 deletions(-) diff --git a/pcsx2/GSState.cpp b/pcsx2/GSState.cpp index 303bcb51b9..f6c193b7b2 100644 --- a/pcsx2/GSState.cpp +++ b/pcsx2/GSState.cpp @@ -16,6 +16,7 @@ #include "PrecompiledHeader.h" #include +#include #include "GS.h" @@ -24,7 +25,7 @@ // GS Playback int g_SaveGSStream = 0; // save GS stream; 1 - prepare, 2 - save int g_nLeftGSFrames = 0; // when saving, number of frames left -static ScopedPtr g_fGSSave; +static std::unique_ptr g_fGSSave; // fixme - need to take this concept and make it MTGS friendly. #ifdef _STGS_GSSTATE_CODE @@ -77,7 +78,7 @@ __fi void GSVSYNC(void) { Console.WriteLn( L"\t%s", file.c_str() ); SafeArray buf; - g_fGSSave = new memSavingState( buf ); + g_fGSSave = std::unique_ptr(new memSavingState( buf )); g_SaveGSStream = 1; g_nLeftGSFrames = 2; diff --git a/pcsx2/PluginManager.cpp b/pcsx2/PluginManager.cpp index a6cfadab9a..8e0f3d3229 100644 --- a/pcsx2/PluginManager.cpp +++ b/pcsx2/PluginManager.cpp @@ -18,12 +18,12 @@ #include #include +#include #include "GS.h" #include "Gif.h" #include "CDVD/CDVDisoReader.h" -#include "Utilities/ScopedPtr.h" #include "Utilities/pxStreams.h" #include "svnrev.h" @@ -991,7 +991,7 @@ void SysCorePlugins::Load( PluginsEnum_t pid, const wxString& srcfile ) ScopedLock lock( m_mtx_PluginStatus ); pxAssert( (uint)pid < PluginId_Count ); Console.Indent().WriteLn( L"Binding %4s: %s ", WX_STR(tbl_PluginInfo[pid].GetShortname()), WX_STR(srcfile) ); - m_info[pid] = new PluginStatus_t( pid, srcfile ); + m_info[pid] = std::unique_ptr(new PluginStatus_t(pid, srcfile)); } void SysCorePlugins::Load( const wxString (&folders)[PluginId_Count] ) @@ -1056,7 +1056,7 @@ void SysCorePlugins::Unload(PluginsEnum_t pid) { ScopedLock lock( m_mtx_PluginStatus ); pxAssert( (uint)pid < PluginId_Count ); - m_info[pid].Delete(); + m_info[pid] = nullptr; } void SysCorePlugins::Unload() diff --git a/pcsx2/Plugins.h b/pcsx2/Plugins.h index 9177963a8c..4e4a15e82c 100644 --- a/pcsx2/Plugins.h +++ b/pcsx2/Plugins.h @@ -298,7 +298,7 @@ protected: volatile u32 m_mcdOpen; public: // hack until we unsuck plugins... - ScopedPtr m_info[PluginId_AllocCount]; + std::unique_ptr m_info[PluginId_AllocCount]; public: SysCorePlugins(); diff --git a/pcsx2/PrecompiledHeader.h b/pcsx2/PrecompiledHeader.h index c24b609917..a9dc78ab24 100644 --- a/pcsx2/PrecompiledHeader.h +++ b/pcsx2/PrecompiledHeader.h @@ -74,7 +74,6 @@ typedef int BOOL; #include "Utilities/FixedPointTypes.h" #include "Utilities/wxBaseTools.h" -#include "Utilities/ScopedPtr.h" #include "Utilities/Path.h" #include "Utilities/Console.h" #include "Utilities/MemcpyFast.h" diff --git a/pcsx2/System.cpp b/pcsx2/System.cpp index 42572ece47..5b8bad51d3 100644 --- a/pcsx2/System.cpp +++ b/pcsx2/System.cpp @@ -291,8 +291,8 @@ template< typename CpuType > class CpuInitializer { public: - ScopedPtr MyCpu; - ScopedExcept ExThrown; + std::unique_ptr MyCpu; + ScopedExcept ExThrown; CpuInitializer(); virtual ~CpuInitializer() throw(); @@ -302,8 +302,8 @@ public: return !!MyCpu; } - CpuType* GetPtr() { return MyCpu.GetPtr(); } - const CpuType* GetPtr() const { return MyCpu.GetPtr(); } + CpuType* GetPtr() { return MyCpu.get(); } + const CpuType* GetPtr() const { return MyCpu.get(); } operator CpuType*() { return GetPtr(); } operator const CpuType*() const { return GetPtr(); } @@ -318,19 +318,19 @@ template< typename CpuType > CpuInitializer< CpuType >::CpuInitializer() { try { - MyCpu = new CpuType(); + MyCpu = std::unique_ptr(new CpuType()); MyCpu->Reserve(); } catch( Exception::RuntimeError& ex ) { Console.Error( L"CPU provider error:\n\t" + ex.FormatDiagnosticMessage() ); - MyCpu = NULL; + MyCpu = nullptr; ExThrown = ScopedExcept(ex.Clone()); } catch( std::runtime_error& ex ) { Console.Error( L"CPU provider error (STL Exception)\n\tDetails:" + fromUTF8( ex.what() ) ); - MyCpu = NULL; + MyCpu = nullptr; ExThrown = ScopedExcept(new Exception::RuntimeError(ex)); } } @@ -485,7 +485,7 @@ SysCpuProviderPack::SysCpuProviderPack() Console.WriteLn( Color_StrongBlue, "Reserving memory for recompilers..." ); ConsoleIndentScope indent(1); - CpuProviders = new CpuInitializerSet(); + CpuProviders = std::unique_ptr(new CpuInitializerSet()); try { recCpu.Reserve(); diff --git a/pcsx2/System.h b/pcsx2/System.h index 2071527791..4a3fb191a5 100644 --- a/pcsx2/System.h +++ b/pcsx2/System.h @@ -135,7 +135,7 @@ protected: ScopedExcept m_RecExceptionIOP; public: - ScopedPtr CpuProviders; + std::unique_ptr CpuProviders; SysCpuProviderPack(); virtual ~SysCpuProviderPack() throw(); diff --git a/pcsx2/ZipTools/ThreadedZipTools.h b/pcsx2/ZipTools/ThreadedZipTools.h index 51b896c320..d1e20dc1ee 100644 --- a/pcsx2/ZipTools/ThreadedZipTools.h +++ b/pcsx2/ZipTools/ThreadedZipTools.h @@ -79,8 +79,8 @@ class ArchiveEntryList DeclareNoncopyableObject( ArchiveEntryList ); protected: - std::vector m_list; - ScopedPtr m_data; + std::vector m_list; + std::unique_ptr m_data; public: virtual ~ArchiveEntryList() throw() {} @@ -89,22 +89,21 @@ public: ArchiveEntryList( ArchiveDataBuffer* data ) { - m_data = data; } ArchiveEntryList( ArchiveDataBuffer& data ) + : m_data(&data) { - m_data = &data; } const VmStateBuffer* GetBuffer() const { - return m_data; + return m_data.get(); } VmStateBuffer* GetBuffer() { - return m_data; + return m_data.get(); } u8* GetPtr( uint idx ) diff --git a/pcsx2/x86/microVU.cpp b/pcsx2/x86/microVU.cpp index 6acd085c0f..68bb970ef1 100644 --- a/pcsx2/x86/microVU.cpp +++ b/pcsx2/x86/microVU.cpp @@ -67,7 +67,7 @@ void mVUinit(microVU& mVU, uint vuIndex) { if (!mVU.dispCache) throw Exception::OutOfMemory (mVU.index ? L"Micro VU1 Dispatcher" : L"Micro VU0 Dispatcher"); memset(mVU.dispCache, 0xcc, mVUdispCacheSize); - mVU.regAlloc = new microRegAlloc(mVU.index); + mVU.regAlloc.reset(new microRegAlloc(mVU.index)); } // Resets Rec Data diff --git a/pcsx2/x86/microVU.h b/pcsx2/x86/microVU.h index 1529bb39f1..a7bff4225d 100644 --- a/pcsx2/x86/microVU.h +++ b/pcsx2/x86/microVU.h @@ -22,6 +22,7 @@ using namespace x86Emitter; #include #include +#include #include "Common.h" #include "VU.h" #include "MTVU.h" @@ -192,10 +193,10 @@ struct microVU { u32 progMemMask; // VU Micro Memory Size (in u32's) u32 cacheSize; // VU Cache Size - microProgManager prog; // Micro Program Data - microProfiler profiler; // Opcode Profiler - ScopedPtr regAlloc; // Reg Alloc Class - ScopedPtr logFile; // Log File Pointer + microProgManager prog; // Micro Program Data + microProfiler profiler; // Opcode Profiler + std::unique_ptr regAlloc; // Reg Alloc Class + std::unique_ptr logFile; // Log File Pointer RecompiledCodeReserve* cache_reserve; u8* cache; // Dynarec Cache Start (where we will start writing the recompiled code to) diff --git a/pcsx2/x86/microVU_Log.inl b/pcsx2/x86/microVU_Log.inl index 3f193114ce..b8397c1ca8 100644 --- a/pcsx2/x86/microVU_Log.inl +++ b/pcsx2/x86/microVU_Log.inl @@ -48,7 +48,7 @@ void __mVUdumpProgram(microVU& mVU, microProgram& prog) { mVUbranch = 0; const wxString logname(wxsFormat(L"microVU%d prog - %02d.html", mVU.index, prog.idx)); - mVU.logFile = new AsciiFile(Path::Combine(g_Conf->Folders.Logs, logname), L"w"); + mVU.logFile = std::unique_ptr(new AsciiFile(Path::Combine(g_Conf->Folders.Logs, logname), L"w")); mVUlog("\n"); mVUlog("microVU%d MicroProgram Log\n", mVU.index); @@ -126,6 +126,6 @@ void __mVUdumpProgram(microVU& mVU, microProgram& prog) { iPC = bPC; setCode(); - mVU.logFile.Delete(); + mVU.logFile.reset(nullptr); } From a74677acf74599944c58d014f805c94c1589d807 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 27 Jan 2016 17:51:08 +0000 Subject: [PATCH 5/6] utilities: Convert ScopedPtr to unique_ptr --- common/include/Utilities/Dependencies.h | 1 - common/include/Utilities/Threading.h | 1 - common/include/Utilities/pxStreams.h | 17 ++++++++-------- common/include/Utilities/wxGuiTools.h | 4 ++-- common/src/Utilities/pxStreams.cpp | 24 +++++++++++------------ common/src/Utilities/wxAppWithHelpers.cpp | 12 ++++++------ common/src/Utilities/wxGuiTools.cpp | 2 +- 7 files changed, 30 insertions(+), 31 deletions(-) diff --git a/common/include/Utilities/Dependencies.h b/common/include/Utilities/Dependencies.h index 1ad38db121..31bc649149 100644 --- a/common/include/Utilities/Dependencies.h +++ b/common/include/Utilities/Dependencies.h @@ -246,5 +246,4 @@ extern wxString fromAscii( const char* src ); #include "Utilities/Assertions.h" #include "Utilities/Exceptions.h" -#include "Utilities/ScopedPtr.h" #include "Utilities/ScopedAlloc.h" diff --git a/common/include/Utilities/Threading.h b/common/include/Utilities/Threading.h index e21522ae2e..6f2cfcb71f 100644 --- a/common/include/Utilities/Threading.h +++ b/common/include/Utilities/Threading.h @@ -24,7 +24,6 @@ #endif #include "Pcsx2Defs.h" -#include "ScopedPtr.h" #include "TraceLog.h" #undef Yield // release the burden of windows.h global namespace spam. diff --git a/common/include/Utilities/pxStreams.h b/common/include/Utilities/pxStreams.h index 4d99b7eb56..b810c93fc4 100644 --- a/common/include/Utilities/pxStreams.h +++ b/common/include/Utilities/pxStreams.h @@ -16,6 +16,7 @@ #pragma once #include "wx/filefn.h" +#include // -------------------------------------------------------------------------------------- // pxStreamBase @@ -55,19 +56,19 @@ class pxOutputStream : public pxStreamBase DeclareNoncopyableObject(pxOutputStream); protected: - ScopedPtr m_stream_out; + std::unique_ptr m_stream_out; public: - pxOutputStream(const wxString& filename, ScopedPtr& output); + pxOutputStream(const wxString& filename, std::unique_ptr& output); pxOutputStream(const wxString& filename, wxOutputStream* output); virtual ~pxOutputStream() throw() {} virtual void Write( const void* data, size_t size ); - void SetStream( const wxString& filename, ScopedPtr& stream ); + void SetStream( const wxString& filename, std::unique_ptr& stream ); void SetStream( const wxString& filename, wxOutputStream* stream ); - void Close() { m_stream_out.Delete(); } + void Close() { m_stream_out = nullptr; } virtual wxStreamBase* GetWxStreamBase() const; @@ -89,19 +90,19 @@ class pxInputStream : public pxStreamBase DeclareNoncopyableObject(pxInputStream); protected: - ScopedPtr m_stream_in; + std::unique_ptr m_stream_in; public: - pxInputStream(const wxString& filename, ScopedPtr& input); + pxInputStream(const wxString& filename, std::unique_ptr& input); pxInputStream(const wxString& filename, wxInputStream* input); virtual ~pxInputStream() throw() {} virtual void Read( void* dest, size_t size ); - void SetStream( const wxString& filename, ScopedPtr& stream ); + void SetStream( const wxString& filename, std::unique_ptr& stream ); void SetStream( const wxString& filename, wxInputStream* stream ); - void Close() { m_stream_in.Delete(); } + void Close() { m_stream_in = nullptr; } virtual wxStreamBase* GetWxStreamBase() const; diff --git a/common/include/Utilities/wxGuiTools.h b/common/include/Utilities/wxGuiTools.h index e182f56776..39aa1589d1 100644 --- a/common/include/Utilities/wxGuiTools.h +++ b/common/include/Utilities/wxGuiTools.h @@ -28,7 +28,7 @@ #if wxUSE_GUI #include "Dependencies.h" -#include "ScopedPtr.h" +#include #include #include @@ -741,7 +741,7 @@ public: class MoreStockCursors { protected: - ScopedPtr m_arrowWait; + std::unique_ptr m_arrowWait; public: MoreStockCursors() { } diff --git a/common/src/Utilities/pxStreams.cpp b/common/src/Utilities/pxStreams.cpp index cb949072b3..ee9ac3ecf0 100644 --- a/common/src/Utilities/pxStreams.cpp +++ b/common/src/Utilities/pxStreams.cpp @@ -47,9 +47,9 @@ wxFileOffset pxStreamBase::Length() const // Interface for reading data from a gzip stream. // -pxInputStream::pxInputStream(const wxString& filename, ScopedPtr& input) +pxInputStream::pxInputStream(const wxString& filename, std::unique_ptr& input) : pxStreamBase( filename ) - , m_stream_in( input.DetachPtr() ) + , m_stream_in( std::move(input) ) { } @@ -59,7 +59,7 @@ pxInputStream::pxInputStream(const wxString& filename, wxInputStream* input) { } -wxStreamBase* pxInputStream::GetWxStreamBase() const { return m_stream_in.GetPtr(); } +wxStreamBase* pxInputStream::GetWxStreamBase() const { return m_stream_in.get(); } wxFileOffset pxInputStream::Tell() const { @@ -71,16 +71,16 @@ wxFileOffset pxInputStream::Seek( wxFileOffset ofs, wxSeekMode mode ) return m_stream_in->SeekI(ofs, mode); } -void pxInputStream::SetStream( const wxString& filename, ScopedPtr& stream ) +void pxInputStream::SetStream( const wxString& filename, std::unique_ptr& stream ) { m_filename = filename; - m_stream_in = stream.DetachPtr(); + m_stream_in = std::move(stream); } void pxInputStream::SetStream( const wxString& filename, wxInputStream* stream ) { m_filename = filename; - m_stream_in = stream; + m_stream_in = std::unique_ptr(stream); } void pxInputStream::Read( void* dest, size_t size ) @@ -108,9 +108,9 @@ void pxInputStream::Read( void* dest, size_t size ) // -------------------------------------------------------------------------------------- // pxOutputStream // -------------------------------------------------------------------------------------- -pxOutputStream::pxOutputStream(const wxString& filename, ScopedPtr& output) +pxOutputStream::pxOutputStream(const wxString& filename, std::unique_ptr& output) : pxStreamBase( filename ) - , m_stream_out( output.DetachPtr() ) + , m_stream_out( std::move(output) ) { } @@ -121,7 +121,7 @@ pxOutputStream::pxOutputStream(const wxString& filename, wxOutputStream* output) { } -wxStreamBase* pxOutputStream::GetWxStreamBase() const { return m_stream_out.GetPtr(); } +wxStreamBase* pxOutputStream::GetWxStreamBase() const { return m_stream_out.get(); } wxFileOffset pxOutputStream::Tell() const { @@ -133,16 +133,16 @@ wxFileOffset pxOutputStream::Seek( wxFileOffset ofs, wxSeekMode mode ) return m_stream_out->SeekO( ofs, mode ); } -void pxOutputStream::SetStream( const wxString& filename, ScopedPtr& stream ) +void pxOutputStream::SetStream( const wxString& filename, std::unique_ptr& stream ) { m_filename = filename; - m_stream_out = stream.DetachPtr(); + m_stream_out = std::move(stream); } void pxOutputStream::SetStream( const wxString& filename, wxOutputStream* stream ) { m_filename = filename; - m_stream_out = stream; + m_stream_out = std::unique_ptr(stream); } diff --git a/common/src/Utilities/wxAppWithHelpers.cpp b/common/src/Utilities/wxAppWithHelpers.cpp index c231a6a2db..e8f3feb273 100644 --- a/common/src/Utilities/wxAppWithHelpers.cpp +++ b/common/src/Utilities/wxAppWithHelpers.cpp @@ -387,7 +387,7 @@ bool wxAppWithHelpers::ProcessEvent( wxEvent& evt ) bool wxAppWithHelpers::ProcessEvent( wxEvent* evt ) { AffinityAssert_AllowFrom_MainUI(); - ScopedPtr deleteMe( evt ); + std::unique_ptr deleteMe( evt ); return _parent::ProcessEvent( *deleteMe ); } @@ -409,7 +409,7 @@ bool wxAppWithHelpers::ProcessEvent( pxActionEvent* evt ) { if( wxThread::IsMain() ) { - ScopedPtr deleteMe( evt ); + std::unique_ptr deleteMe( evt ); return _parent::ProcessEvent( *deleteMe ); } else @@ -513,7 +513,7 @@ void wxAppWithHelpers::IdleEventDispatcher( const wxChar* action ) while( node = m_IdleEventQueue.begin(), node != m_IdleEventQueue.end() ) { - ScopedPtr deleteMe(*node); + std::unique_ptr deleteMe(*node); m_IdleEventQueue.erase( node ); lock.Release(); @@ -524,8 +524,8 @@ void wxAppWithHelpers::IdleEventDispatcher( const wxChar* action ) // thread to crash. So we disallow deletions when those waits are in action, and continue // to postpone the deletion of the thread until such time that it is safe. - pxThreadLog.Write( ((pxThread*)((wxCommandEvent*)deleteMe.GetPtr())->GetClientData())->GetName(), L"Deletion postponed due to mutex or semaphore dependency." ); - postponed.push_back(deleteMe.DetachPtr()); + pxThreadLog.Write( ((pxThread*)((wxCommandEvent*)deleteMe.get())->GetClientData())->GetName(), L"Deletion postponed due to mutex or semaphore dependency." ); + postponed.push_back(deleteMe.release()); } else { @@ -680,7 +680,7 @@ wxAppTraits* wxAppWithHelpers::CreateTraits() // (thus we have a fairly automatic threaded exception system!) void wxAppWithHelpers::OnDeleteThread( wxCommandEvent& evt ) { - ScopedPtr thr( (pxThread*)evt.GetClientData() ); + std::unique_ptr thr( (pxThread*)evt.GetClientData() ); if( !thr ) { pxThreadLog.Write( L"null", L"OnDeleteThread: NULL thread object received (and ignored)." ); diff --git a/common/src/Utilities/wxGuiTools.cpp b/common/src/Utilities/wxGuiTools.cpp index a142629ddf..073f4672f2 100644 --- a/common/src/Utilities/wxGuiTools.cpp +++ b/common/src/Utilities/wxGuiTools.cpp @@ -562,7 +562,7 @@ void ScopedBusyCursor::SetManualBusyCursor( BusyCursorType busytype ) const wxCursor& MoreStockCursors::GetArrowWait() { if( !m_arrowWait ) - m_arrowWait = new wxCursor( wxCURSOR_ARROWWAIT ); + m_arrowWait = std::unique_ptr(new wxCursor( wxCURSOR_ARROWWAIT )); return *m_arrowWait; } From e92636ab1a00d2f8432bad3c5bd1c8a2e1e8c0d8 Mon Sep 17 00:00:00 2001 From: Jonathan Li Date: Wed, 27 Jan 2016 17:53:13 +0000 Subject: [PATCH 6/6] utilities: Remove ScopedPtr and pxObjPtr implementation Both are now unused. --- common/build/Utilities/utilities.vcxproj | 1 - .../build/Utilities/utilities.vcxproj.filters | 3 - common/include/Utilities/ScopedPtr.h | 231 ------------------ common/src/Utilities/CMakeLists.txt | 1 - 4 files changed, 236 deletions(-) delete mode 100644 common/include/Utilities/ScopedPtr.h diff --git a/common/build/Utilities/utilities.vcxproj b/common/build/Utilities/utilities.vcxproj index c52ff622bd..8c3325d58c 100644 --- a/common/build/Utilities/utilities.vcxproj +++ b/common/build/Utilities/utilities.vcxproj @@ -182,7 +182,6 @@ - diff --git a/common/build/Utilities/utilities.vcxproj.filters b/common/build/Utilities/utilities.vcxproj.filters index e28bf1b2fb..5ba5dbbe9c 100644 --- a/common/build/Utilities/utilities.vcxproj.filters +++ b/common/build/Utilities/utilities.vcxproj.filters @@ -201,9 +201,6 @@ Header Files - - Header Files - Header Files diff --git a/common/include/Utilities/ScopedPtr.h b/common/include/Utilities/ScopedPtr.h deleted file mode 100644 index 0c975b183f..0000000000 --- a/common/include/Utilities/ScopedPtr.h +++ /dev/null @@ -1,231 +0,0 @@ -/* PCSX2 - PS2 Emulator for PCs - * Copyright (C) 2002-2010 PCSX2 Dev Team - * - * PCSX2 is free software: you can redistribute it and/or modify it under the terms - * of the GNU Lesser General Public License as published by the Free Software Found- - * ation, either version 3 of the License, or (at your option) any later version. - * - * PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; - * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR - * PURPOSE. See the GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License along with PCSX2. - * If not, see . - */ - -#pragma once - -#include "Assertions.h" - -// -------------------------------------------------------------------------------------- -// ScopedPtr -// -------------------------------------------------------------------------------------- - -template< typename T > -class ScopedPtr -{ - DeclareNoncopyableObject(ScopedPtr); - -protected: - T* m_ptr; - -public: - typedef T element_type; - - wxEXPLICIT ScopedPtr(T * ptr = NULL) - { - m_ptr = ptr; - } - - ~ScopedPtr() throw() { Delete(); } - - ScopedPtr& Reassign(T * ptr = NULL) - { - if ( ptr != m_ptr ) - { - Delete(); - m_ptr = ptr; - } - return *this; - } - - ScopedPtr& 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_ptr; - m_ptr = NULL; - delete deleteme; - - return *this; - } - - // Removes the pointer from scoped management, but does not delete! - T *DetachPtr() - { - T *ptr = m_ptr; - m_ptr = 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_ptr; - } - - // Swaps two pointers between likened scoped pointer types. This method is useful for - // situations where you need to create a new object with a complex initializer that can - // throw exceptions -- and thusly should be disposed if the initialization fails. Use - // SwapPtr to assign the new object into the persistent ScopedPtr instance, and have - // the old object assigned to the local-scope ScopedPtr instance. - void SwapPtr(ScopedPtr& other) - { - T * const tmp = other.m_ptr; - other.m_ptr = m_ptr; - m_ptr = 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_ptr == NULL; - } - - operator T*() const - { - return m_ptr; - } - - // Equality - bool operator==(T* pT) const throw() - { - return m_ptr == 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. - ScopedPtr& operator=( T* src ) - { - return Reassign( src ); - } - - // Dereference operator, returns a handle to the managed pointer. - // Generates a debug assertion if the object is NULL! - T& operator*() const - { - pxAssert(m_ptr != NULL); - return *m_ptr; - } - - T* operator->() const - { - pxAssert(m_ptr != NULL); - return m_ptr; - } -}; - -// -------------------------------------------------------------------------------------- -// pxObjPtr -- fancified version of wxScopedPtr -// -------------------------------------------------------------------------------------- -// This class is a non-null scoped pointer container. What that means is that the object -// always resets itself to a valid "placebo" function rather than NULL, such that methods -// can be invoked safely without fear of NULL pointer exceptions. This system is useful -// for objects where most or all public methods can fail silently, and still allow program -// execution flow to continue. -// -// It also implements basic scoped pointer behavior: when the pxObjPtr class is deleted, -// it will automatically delete the pointer in its posession, if the pointer is valid. -// -// Notes: -// * This class intentionally does not implement the "release" API, because it doesn't -// really make sense within the context of a non-nullable pointer specification. -// -template< typename T, T& DefaultStaticInst > -class pxObjPtr -{ - DeclareNoncopyableObject(pxObjPtr); - -protected: - T * m_ptr; - -public: - typedef T element_type; - - explicit pxObjPtr(T * ptr = &DefaultStaticInst) : m_ptr(ptr) { } - - bool IsEmpty() const - { - return m_ptr != &DefaultStaticInst; - } - - ~pxObjPtr() - { - if( !IsEmpty() ) delete m_ptr; - m_ptr = NULL; - } - - // test for pointer validity: defining conversion to unspecified_bool_type - // and not more obvious bool to avoid implicit conversions to integer types - typedef T *(pxObjPtr::*unspecified_bool_type)() const; - - operator unspecified_bool_type() const - { - return ( !IsEmpty() ) ? &ScopedPtr::get : NULL; - } - - void reset(T * ptr = &DefaultStaticInst) - { - if ( ptr != m_ptr ) - { - if( !IsEmpty() ) - delete m_ptr; - m_ptr = ptr; - } - } - - T& operator*() const - { - pxAssert(m_ptr != NULL); - return *m_ptr; - } - - T* operator->() const - { - pxAssert(m_ptr != NULL); - return m_ptr; - } - - T* get() const - { - pxAssert(m_ptr != NULL); - return m_ptr; - } - - void swap(pxObjPtr& other) - { - // Neither pointer in either container should ever be NULL... - pxAssert(m_ptr != NULL); - pxAssert(other.m_ptr != NULL); - - T * const tmp = other.m_ptr; - other.m_ptr = m_ptr; - m_ptr = tmp; - } -}; - diff --git a/common/src/Utilities/CMakeLists.txt b/common/src/Utilities/CMakeLists.txt index 0e125e20c1..2bd4503e78 100644 --- a/common/src/Utilities/CMakeLists.txt +++ b/common/src/Utilities/CMakeLists.txt @@ -101,7 +101,6 @@ set(UtilitiesHeaders ../../include/Utilities/RedtapeWindows.h ../../include/Utilities/SafeArray.h ../../include/Utilities/ScopedAlloc.h - ../../include/Utilities/ScopedPtr.h ../../include/Utilities/ScopedPtrMT.h ../../include/Utilities/StringHelpers.h ../../include/Utilities/Threading.h