Remove some naked new amd delete in: various

This commit is contained in:
Paul Licameli 2016-04-08 04:32:11 -04:00 committed by Paul Licameli
parent 186679b3a6
commit 942c62b6f6
23 changed files with 165 additions and 251 deletions

View File

@ -314,7 +314,7 @@ void QuitAudacity(bool bForce)
//print out profile if we have one by deleting it
//temporarilly commented out till it is added to all projects
//delete Profiler::Instance();
//DELETE Profiler::Instance();
//remove our logger
std::unique_ptr<wxLog>{ wxLog::SetActiveTarget(NULL) }; // DELETE
@ -994,8 +994,7 @@ wxString AudacityApp::InitLang( const wxString & lang )
{
wxString result = lang;
if (mLocale)
delete mLocale;
mLocale.reset();
#if defined(__WXMAC__)
// This should be reviewed again during the wx3 conversion.
@ -1021,7 +1020,7 @@ wxString AudacityApp::InitLang( const wxString & lang )
if (!info)
return result;
}
mLocale = new wxLocale(info->Language);
mLocale = std::make_unique<wxLocale>(info->Language);
for(unsigned int i=0; i<audacityPathList.GetCount(); i++)
mLocale->AddCatalogLookupPathPrefix(audacityPathList[i]);
@ -1182,9 +1181,6 @@ bool AudacityApp::OnInit()
m_aliasMissingWarningShouldShow = true;
m_LastMissingBlockFile = NULL;
mChecker = NULL;
mIPCServ = NULL;
#if defined(__WXMAC__)
// Disable window animation
wxSystemOptions::SetOption(wxMAC_WINDOW_PLAIN_TRANSITION, 1);
@ -1330,7 +1326,7 @@ bool AudacityApp::OnInit()
#endif
// TODO - read the number of files to store in history from preferences
mRecentFiles = new FileHistory(ID_RECENT_LAST - ID_RECENT_FIRST + 1, ID_RECENT_CLEAR);
mRecentFiles = std::make_unique<FileHistory>(ID_RECENT_LAST - ID_RECENT_FIRST + 1, ID_RECENT_CLEAR);
mRecentFiles->Load(*gPrefs, wxT("RecentFiles"));
theTheme.EnsureInitialised();
@ -1547,17 +1543,10 @@ bool AudacityApp::OnInit()
void AudacityApp::InitCommandHandler()
{
mCmdHandler = new CommandHandler(*this);
mCmdHandler = std::make_unique<CommandHandler>(*this);
//SetNextHandler(mCmdHandler);
}
void AudacityApp::DeInitCommandHandler()
{
wxASSERT(NULL != mCmdHandler);
delete mCmdHandler;
mCmdHandler = NULL;
}
// AppCommandEvent callback - just pass the event on to the CommandHandler
void AudacityApp::OnReceiveCommand(AppCommandEvent &event)
{
@ -1701,7 +1690,8 @@ bool AudacityApp::InitTempDir()
bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
{
wxString name = wxString::Format(wxT("audacity-lock-%s"), wxGetUserId().c_str());
mChecker = new wxSingleInstanceChecker();
mChecker.reset();
auto checker = std::make_unique<wxSingleInstanceChecker>();
#if defined(__UNIX__)
wxString sockFile(dir + wxT("/.audacity.sock"));
@ -1709,7 +1699,7 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
wxString runningTwoCopiesStr = _("Running two copies of Audacity simultaneously may cause\ndata loss or cause your system to crash.\n\n");
if (!mChecker->Create(name, dir)) {
if (!checker->Create(name, dir)) {
// Error initializing the wxSingleInstanceChecker. We don't know
// whether there is another instance running or not.
@ -1721,12 +1711,10 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
_("Error Locking Temporary Folder"),
wxYES_NO | wxICON_EXCLAMATION,
NULL);
if (action == wxNO) {
delete mChecker;
if (action == wxNO)
return false;
}
}
else if ( mChecker->IsAnotherRunning() ) {
else if ( checker->IsAnotherRunning() ) {
// Parse the command line to ensure correct syntax, but
// ignore options and only use the filenames, if any.
auto parser = ParseCommandLine();
@ -1747,7 +1735,7 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
// where the server may not have been fully initialized.
for (int i = 0; i < 50; i++)
{
wxConnectionBase *conn = client.MakeConnection(wxEmptyString, IPC_APPL, IPC_TOPIC);
std::unique_ptr<wxConnectionBase> conn{ client.MakeConnection(wxEmptyString, IPC_APPL, IPC_TOPIC) };
if (conn)
{
bool ok = false;
@ -1765,8 +1753,6 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
ok = conn->Execute(wxEmptyString);
}
delete conn;
if (ok)
return false;
}
@ -1816,19 +1802,18 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
_("Use the New or Open commands in the currently running Audacity\nprocess to open multiple projects simultaneously.\n");
wxMessageBox(prompt, _("Audacity is already running"),
wxOK | wxICON_ERROR);
delete mChecker;
return false;
}
#if defined(__WXMSW__)
// Create the DDE IPC server
mIPCServ = new IPCServ(IPC_APPL);
mIPCServ = std::make_unique<IPCServ>(IPC_APPL);
#else
int mask = umask(077);
remove(OSFILENAME(sockFile));
wxUNIXaddress addr;
addr.Filename(sockFile);
mIPCServ = new wxSocketServer(addr, wxSOCKET_NOWAIT);
mIPCServ = std::make_unique<wxSocketServer>(addr, wxSOCKET_NOWAIT);
umask(mask);
if (!mIPCServ || !mIPCServ->IsOk())
@ -1841,6 +1826,7 @@ bool AudacityApp::CreateSingleInstanceChecker(const wxString &dir)
mIPCServ->SetNotify(wxSOCKET_CONNECTION_FLAG);
mIPCServ->Notify(true);
#endif
mChecker = std::move(checker);
return true;
}
@ -2021,11 +2007,7 @@ int AudacityApp::OnExit()
}
}
DeInitCommandHandler();
mRecentFiles->Save(*gPrefs, wxT("RecentFiles"));
delete mRecentFiles;
mRecentFiles = NULL;
FinishPreferences();
@ -2040,9 +2022,6 @@ int AudacityApp::OnExit()
// Terminate the PluginManager (must be done before deleting the locale)
PluginManager::Get().Terminate();
if (mLocale)
delete mLocale;
if (mIPCServ)
{
#if defined(__UNIX__)
@ -2052,12 +2031,8 @@ int AudacityApp::OnExit()
remove(OSFILENAME(addr.Filename()));
}
#endif
delete mIPCServ;
}
if (mChecker)
delete mChecker;
return 0;
}

View File

@ -271,7 +271,7 @@ class AudacityApp final : public wxApp {
int flags = wxDIR_FILES);
static bool IsTempDirectoryNameOK( const wxString & Name );
FileHistory *GetRecentFiles() {return mRecentFiles;}
FileHistory *GetRecentFiles() {return mRecentFiles.get();}
void AddFileToHistory(const wxString & name);
bool GetWindowRectAlreadySaved()const {return mWindowRectAlreadySaved;}
void SetWindowRectAlreadySaved(bool alreadySaved) {mWindowRectAlreadySaved = alreadySaved;}
@ -283,12 +283,12 @@ class AudacityApp final : public wxApp {
#endif
private:
CommandHandler *mCmdHandler;
FileHistory *mRecentFiles;
std::unique_ptr<CommandHandler> mCmdHandler;
std::unique_ptr<FileHistory> mRecentFiles;
wxLocale *mLocale;
std::unique_ptr<wxLocale> mLocale;
wxSingleInstanceChecker *mChecker;
std::unique_ptr<wxSingleInstanceChecker> mChecker;
wxTimer mTimer;
@ -298,7 +298,6 @@ class AudacityApp final : public wxApp {
ODLock m_LastMissingBlockFileLock;
void InitCommandHandler();
void DeInitCommandHandler();
bool InitTempDir();
bool CreateSingleInstanceChecker(const wxString &dir);
@ -308,9 +307,9 @@ class AudacityApp final : public wxApp {
bool mWindowRectAlreadySaved;
#if defined(__WXMSW__)
IPCServ *mIPCServ;
std::unique_ptr<IPCServ> mIPCServ;
#else
wxSocketServer *mIPCServ;
std::unique_ptr<wxSocketServer> mIPCServ;
#endif
public:

View File

@ -373,7 +373,7 @@ DeviceChangeHandler::DeviceChangeHandler()
: wxEvtHandler()
{
mTimer.SetOwner(this);
mListener = new DeviceChangeListener();
mListener = std::make_unique<DeviceChangeListener>();
mListener->SetHandler(this);
mListener->Enable(true);
}
@ -381,10 +381,7 @@ DeviceChangeHandler::DeviceChangeHandler()
DeviceChangeHandler::~DeviceChangeHandler()
{
if (mListener)
{
mListener->Enable(false);
delete mListener;
}
}
void DeviceChangeHandler::Enable(bool enable)

View File

@ -16,6 +16,8 @@
#if defined(EXPERIMENTAL_DEVICE_CHANGE_HANDLER)
#include "MemoryX.h"
#if defined(__WXMSW__) || defined(__WXMAC__) || defined(HAVE_LIBUDEV_H)
#define HAVE_DEVICE_CHANGE
#endif
@ -48,7 +50,7 @@ private:
void OnChange(wxCommandEvent & evt);
void OnTimer(wxTimerEvent & evt);
DeviceChangeInterface *mListener;
std::unique_ptr<DeviceChangeInterface> mListener;
wxTimer mTimer;
DECLARE_EVENT_TABLE()

View File

@ -20,21 +20,19 @@
FileIO::FileIO(const wxString & name, FileIOMode mode)
: mName(name),
mMode(mode),
mInputStream(NULL),
mOutputStream(NULL),
mOpen(false)
{
wxString scheme;
if (mMode == FileIO::Input) {
mInputStream = new wxFFileInputStream(mName);
mInputStream = std::make_unique<wxFFileInputStream>(mName);
if (mInputStream == NULL || !mInputStream->IsOk()) {
wxPrintf(wxT("Couldn't get input stream: %s\n"), name.c_str());
return;
}
}
else {
mOutputStream = new wxFFileOutputStream(mName);
mOutputStream = std::make_unique<wxFFileOutputStream>(mName);
if (mOutputStream == NULL || !mOutputStream->IsOk()) {
wxPrintf(wxT("Couldn't get output stream: %s\n"), name.c_str());
return;
@ -56,16 +54,8 @@ bool FileIO::IsOpened()
void FileIO::Close()
{
if (mOutputStream) {
delete mOutputStream;
mOutputStream = NULL;
}
if (mInputStream) {
delete mInputStream;
mInputStream = NULL;
}
mOutputStream.reset();
mInputStream.reset();
mOpen = false;
}

View File

@ -11,6 +11,7 @@
#ifndef __AUDACITY_FILEIO__
#define __AUDACITY_FILEIO__
#include "MemoryX.h"
#include <wx/object.h>
#include <wx/wfstream.h>
@ -37,8 +38,8 @@ class FileIO
private:
wxString mName;
FileIOMode mMode;
wxInputStream *mInputStream;
wxOutputStream *mOutputStream;
std::unique_ptr<wxInputStream> mInputStream;
std::unique_ptr<wxOutputStream> mOutputStream;
bool mOpen;
};

View File

@ -190,8 +190,7 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
: wxDialogWrapper(parent, id, title, pos, wxDefaultSize,
wxDEFAULT_DIALOG_STYLE | wxRESIZE_BORDER | wxMAXIMIZE_BOX),
mData(NULL),
mBitmap(NULL),
mAnalyst(new SpectrumAnalyst())
mAnalyst(std::make_unique<SpectrumAnalyst>())
{
SetName(GetTitle());
@ -239,8 +238,8 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
axisChoices.Add(_("Log frequency"));
mFreqFont = wxFont(fontSize, wxFONTFAMILY_SWISS, wxFONTSTYLE_NORMAL, wxFONTWEIGHT_NORMAL);
mArrowCursor = new wxCursor(wxCURSOR_ARROW);
mCrossCursor = new wxCursor(wxCURSOR_CROSS);
mArrowCursor = std::make_unique<wxCursor>(wxCURSOR_ARROW);
mCrossCursor = std::make_unique<wxCursor>(wxCURSOR_CROSS);
gPrefs->Read(wxT("/FreqWindow/DrawGrid"), &mDrawGrid, true);
@ -515,12 +514,8 @@ FreqWindow::FreqWindow(wxWindow * parent, wxWindowID id,
FreqWindow::~FreqWindow()
{
if (mBitmap)
delete mBitmap;
if (mData)
delete[] mData;
delete mArrowCursor;
delete mCrossCursor;
}
bool FreqWindow::Show(bool show)
@ -622,15 +617,11 @@ void FreqWindow::DrawBackground(wxMemoryDC & dc)
{
Layout();
if (mBitmap)
{
delete mBitmap;
mBitmap = NULL;
}
mBitmap.reset();
mPlotRect = mFreqPlot->GetClientRect();
mBitmap = new wxBitmap(mPlotRect.width, mPlotRect.height);
mBitmap = std::make_unique<wxBitmap>(mPlotRect.width, mPlotRect.height);
dc.SelectObject(*mBitmap);

View File

@ -181,8 +181,8 @@ private:
wxFont mFreqFont;
wxCursor *mArrowCursor;
wxCursor *mCrossCursor;
std::unique_ptr<wxCursor> mArrowCursor;
std::unique_ptr<wxCursor> mCrossCursor;
wxButton *mCloseButton;
wxButton *mExportButton;
@ -208,7 +208,7 @@ private:
float mYMax;
float mYStep;
wxBitmap *mBitmap;
std::unique_ptr<wxBitmap> mBitmap;
int mMouseX;
int mMouseY;

View File

@ -91,13 +91,12 @@ static tpRegScriptServerFunc scriptFn;
Module::Module(const wxString & name)
{
mName = name;
mLib = new wxDynamicLibrary();
mLib = std::make_unique<wxDynamicLibrary>();
mDispatch = NULL;
}
Module::~Module()
{
delete mLib;
}
bool Module::Load()
@ -183,15 +182,18 @@ void * Module::GetSymbol(const wxString &name)
std::unique_ptr<ModuleManager> ModuleManager::mInstance{};
// Provide builtin modules a means to identify themselves
static wxArrayPtrVoid *pBuiltinModuleList = NULL;
using BuiltinModuleList = std::vector<ModuleMain>;
namespace {
BuiltinModuleList &builtinModuleList()
{
static BuiltinModuleList theList;
return theList;
}
}
void RegisterBuiltinModule(ModuleMain moduleMain)
{
if (pBuiltinModuleList == NULL)
{
pBuiltinModuleList = new wxArrayPtrVoid;
}
pBuiltinModuleList->Add((void *)moduleMain);
builtinModuleList().push_back(moduleMain);
return;
}
@ -206,19 +208,8 @@ ModuleManager::ModuleManager()
ModuleManager::~ModuleManager()
{
size_t cnt = mModules.GetCount();
for (size_t ndx = 0; ndx < cnt; ndx++) {
delete (Module *) mModules[ndx];
}
mModules.Clear();
mDynModules.clear();
if (pBuiltinModuleList != NULL)
{
delete pBuiltinModuleList;
}
builtinModuleList().clear();
}
// static
@ -299,10 +290,11 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler)
ModulePrefs::SetModuleStatus( files[i], kModuleFailed );
#endif
Module *module = new Module(files[i]);
if (module->Load()) // it will get rejected if there are version problems
auto umodule = make_movable<Module>(files[i]);
if (umodule->Load()) // it will get rejected if there are version problems
{
Get().mModules.Add(module);
auto module = umodule.get();
Get().mModules.push_back(std::move(umodule));
// We've loaded and initialised OK.
// So look for special case functions:
wxLogNull logNo; // Don't show wxWidgets errors if we can't do these. (Was: Fix bug 544.)
@ -319,10 +311,6 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler)
ModulePrefs::SetModuleStatus( files[i], iModuleStatus);
#endif
}
else {
// No need to save status, as we already set kModuleFailed.
delete module;
}
}
::wxSetWorkingDirectory(saveOldCWD);
@ -338,11 +326,7 @@ void ModuleManager::Initialize(CommandHandler &cmdHandler)
// static
int ModuleManager::Dispatch(ModuleDispatchTypes type)
{
size_t cnt = Get().mModules.GetCount();
for (size_t ndx = 0; ndx < cnt; ndx++) {
Module *module = (Module *)Get().mModules[ndx];
for (const auto &module: mModules) {
module->Dispatch(type);
}
return 0;
@ -413,10 +397,10 @@ void ModuleManager::InitializeBuiltins()
{
PluginManager & pm = PluginManager::Get();
for (size_t i = 0, cnt = pBuiltinModuleList->GetCount(); i < cnt; i++)
for (auto moduleMain : builtinModuleList())
{
ModuleInterfaceHandle module {
((ModuleMain)(*pBuiltinModuleList)[i])(this, NULL), ModuleInterfaceDeleter{}
moduleMain(this, NULL), ModuleInterfaceDeleter{}
};
if (module->Initialize())
@ -484,7 +468,7 @@ void ModuleInterfaceDeleter::operator() (ModuleInterface *pInterface) const
if (iter != libs.end())
libs.erase(iter); // This causes unloading in ~wxDynamicLibrary
delete pInterface;
std::unique_ptr < ModuleInterface > { pInterface }; // DELETE it
}
}

View File

@ -58,7 +58,7 @@ public:
private:
wxString mName;
wxDynamicLibrary *mLib;
std::unique_ptr<wxDynamicLibrary> mLib;
fnModuleDispatch mDispatch;
};
@ -123,7 +123,7 @@ private:
ModuleMap mDynModules;
LibraryMap mLibs;
wxArrayPtrVoid mModules;
std::vector<movable_ptr<Module>> mModules;
};
#endif /* __AUDACITY_MODULEMANAGER_H__ */

View File

@ -1681,11 +1681,6 @@ PluginManager::~PluginManager()
{
// Ensure termination (harmless if already done)
Terminate();
if (mSettings)
{
delete mSettings;
}
}
// ----------------------------------------------------------------------------
@ -1750,20 +1745,19 @@ void PluginManager::Terminate()
void PluginManager::Load()
{
// Create/Open the registry
mRegistry = new wxFileConfig(wxEmptyString, wxEmptyString, FileNames::PluginRegistry());
wxFileConfig registry(wxEmptyString, wxEmptyString, FileNames::PluginRegistry());
// If this group doesn't exist then we have something that's not a registry.
// We should probably warn the user, but it's pretty unlikely that this will happen.
if (!mRegistry->HasGroup(REGROOT))
if (!registry.HasGroup(REGROOT))
{
// Must start over
mRegistry->DeleteAll();
delete mRegistry;
registry.DeleteAll();
return;
}
// Check for a registry version that we can understand
wxString regver = mRegistry->Read(REGVERKEY);
wxString regver = registry.Read(REGVERKEY);
if (regver < REGVERCUR )
{
// This is where we'd put in conversion code when the
@ -1774,25 +1768,23 @@ void PluginManager::Load()
}
// Load all provider plugins first
LoadGroup(PluginTypeModule);
LoadGroup(&registry, PluginTypeModule);
// Now the rest
LoadGroup(PluginTypeEffect);
LoadGroup(PluginTypeExporter);
LoadGroup(PluginTypeImporter);
LoadGroup(&registry, PluginTypeEffect);
LoadGroup(&registry, PluginTypeExporter);
LoadGroup(&registry, PluginTypeImporter);
LoadGroup(PluginTypeStub);
LoadGroup(&registry, PluginTypeStub);
// Not used by 2.1.1 or greater, but must load to allow users to switch between 2.1.0
// and 2.1.1+. This should be removed after a few releases past 2.1.0.
LoadGroup(PluginTypeNone);
delete mRegistry;
LoadGroup(&registry, PluginTypeNone);
return;
}
void PluginManager::LoadGroup(PluginType type)
void PluginManager::LoadGroup(wxFileConfig *pRegistry, PluginType type)
{
wxString strVal;
bool boolVal;
@ -1801,22 +1793,22 @@ void PluginManager::LoadGroup(PluginType type)
wxString group = GetPluginTypeString(type);
wxString cfgPath = REGROOT + group + wxCONFIG_PATH_SEPARATOR;
mRegistry->SetPath(cfgPath);
for (bool cont = mRegistry->GetFirstGroup(groupName, groupIndex);
pRegistry->SetPath(cfgPath);
for (bool cont = pRegistry->GetFirstGroup(groupName, groupIndex);
cont;
mRegistry->SetPath(cfgPath),
cont = mRegistry->GetNextGroup(groupName, groupIndex))
pRegistry->SetPath(cfgPath),
cont = pRegistry->GetNextGroup(groupName, groupIndex))
{
PluginDescriptor plug;
mRegistry->SetPath(groupName);
pRegistry->SetPath(groupName);
groupName = ConvertID(groupName);
// Bypass group if the ID is already in use
if (mPlugins.find(groupName) != mPlugins.end())
{
mRegistry->SetPath(wxT(".."));
pRegistry->SetPath(wxT(".."));
continue;
}
@ -1826,7 +1818,7 @@ void PluginManager::LoadGroup(PluginType type)
plug.SetPluginType(type);
// Get the provider ID and bypass group if not found
if (!mRegistry->Read(KEY_PROVIDERID, &strVal, wxEmptyString))
if (!pRegistry->Read(KEY_PROVIDERID, &strVal, wxEmptyString))
{
// Bypass group if the provider isn't valid
if (!strVal.IsEmpty() && mPlugins.find(strVal) == mPlugins.end())
@ -1837,50 +1829,50 @@ void PluginManager::LoadGroup(PluginType type)
plug.SetProviderID(PluginID(strVal));
// Get the path (optional)
mRegistry->Read(KEY_PATH, &strVal, wxEmptyString);
pRegistry->Read(KEY_PATH, &strVal, wxEmptyString);
plug.SetPath(strVal);
// Get the name and bypass group if not found
if (!mRegistry->Read(KEY_NAME, &strVal))
if (!pRegistry->Read(KEY_NAME, &strVal))
{
continue;
}
plug.SetName(strVal);
// Get the symbol...use name if not found
if (!mRegistry->Read(KEY_SYMBOL, &strVal))
if (!pRegistry->Read(KEY_SYMBOL, &strVal))
{
strVal = plug.GetName();
}
plug.SetSymbol(strVal);
// Get the version and bypass group if not found
if (!mRegistry->Read(KEY_VERSION, &strVal))
if (!pRegistry->Read(KEY_VERSION, &strVal))
{
continue;
}
plug.SetVersion(strVal);
// Get the vendor and bypass group if not found
if (!mRegistry->Read(KEY_VENDOR, &strVal))
if (!pRegistry->Read(KEY_VENDOR, &strVal))
{
continue;
}
plug.SetVendor(strVal);
// Get the description and bypass group if not found
if (!mRegistry->Read(KEY_DESCRIPTION, &strVal))
if (!pRegistry->Read(KEY_DESCRIPTION, &strVal))
{
continue;
}
plug.SetDescription(strVal);
// Is it enabled...default to no if not found
mRegistry->Read(KEY_ENABLED, &boolVal, false);
pRegistry->Read(KEY_ENABLED, &boolVal, false);
plug.SetEnabled(boolVal);
// Is it valid...default to no if not found
mRegistry->Read(KEY_VALID, &boolVal, false);
pRegistry->Read(KEY_VALID, &boolVal, false);
plug.SetValid(boolVal);
switch (type)
@ -1894,7 +1886,7 @@ void PluginManager::LoadGroup(PluginType type)
case PluginTypeEffect:
{
// Get the effect type and bypass group if not found
if (!mRegistry->Read(KEY_EFFECTTYPE, &strVal))
if (!pRegistry->Read(KEY_EFFECTTYPE, &strVal))
{
continue;
}
@ -1925,35 +1917,35 @@ void PluginManager::LoadGroup(PluginType type)
}
// Get the effect family and bypass group if not found
if (!mRegistry->Read(KEY_EFFECTFAMILY, &strVal))
if (!pRegistry->Read(KEY_EFFECTFAMILY, &strVal))
{
continue;
}
plug.SetEffectFamily(strVal);
// Is it a default (above the line) effect and bypass group if not found
if (!mRegistry->Read(KEY_EFFECTDEFAULT, &boolVal))
if (!pRegistry->Read(KEY_EFFECTDEFAULT, &boolVal))
{
continue;
}
plug.SetEffectDefault(boolVal);
// Is it an interactive effect and bypass group if not found
if (!mRegistry->Read(KEY_EFFECTINTERACTIVE, &boolVal))
if (!pRegistry->Read(KEY_EFFECTINTERACTIVE, &boolVal))
{
continue;
}
plug.SetEffectInteractive(boolVal);
// Is it a realtime capable effect and bypass group if not found
if (!mRegistry->Read(KEY_EFFECTREALTIME, &boolVal))
if (!pRegistry->Read(KEY_EFFECTREALTIME, &boolVal))
{
continue;
}
plug.SetEffectRealtime(boolVal);
// Does the effect support automation...bypass group if not found
if (!mRegistry->Read(KEY_EFFECTAUTOMATABLE, &boolVal))
if (!pRegistry->Read(KEY_EFFECTAUTOMATABLE, &boolVal))
{
continue;
}
@ -1964,21 +1956,21 @@ void PluginManager::LoadGroup(PluginType type)
case PluginTypeImporter:
{
// Get the importer identifier and bypass group if not found
if (!mRegistry->Read(KEY_IMPORTERIDENT, &strVal))
if (!pRegistry->Read(KEY_IMPORTERIDENT, &strVal))
{
continue;
}
plug.SetImporterIdentifier(strVal);
// Get the importer filter description and bypass group if not found
if (!mRegistry->Read(KEY_IMPORTERFILTER, &strVal))
if (!pRegistry->Read(KEY_IMPORTERFILTER, &strVal))
{
continue;
}
plug.SetImporterFilterDescription(strVal);
// Get the importer extensions and bypass group if not found
if (!mRegistry->Read(KEY_IMPORTEREXTENSIONS, &strVal))
if (!pRegistry->Read(KEY_IMPORTEREXTENSIONS, &strVal))
{
continue;
}
@ -2021,34 +2013,32 @@ void PluginManager::LoadGroup(PluginType type)
void PluginManager::Save()
{
// Create/Open the registry
mRegistry = new wxFileConfig(wxEmptyString, wxEmptyString, FileNames::PluginRegistry());
wxFileConfig registry(wxEmptyString, wxEmptyString, FileNames::PluginRegistry());
// Clear it out
mRegistry->DeleteAll();
registry.DeleteAll();
// Write the version string
mRegistry->Write(REGVERKEY, REGVERCUR);
registry.Write(REGVERKEY, REGVERCUR);
// Save the individual groups
SaveGroup(PluginTypeEffect);
SaveGroup(PluginTypeExporter);
SaveGroup(PluginTypeImporter);
SaveGroup(PluginTypeStub);
SaveGroup(&registry, PluginTypeEffect);
SaveGroup(&registry, PluginTypeExporter);
SaveGroup(&registry, PluginTypeImporter);
SaveGroup(&registry, PluginTypeStub);
// Not used by 2.1.1 or greater, but must save to allow users to switch between 2.1.0
// and 2.1.1+. This should be removed after a few releases past 2.1.0.
SaveGroup(PluginTypeNone);
SaveGroup(&registry, PluginTypeNone);
// And now the providers
SaveGroup(PluginTypeModule);
SaveGroup(&registry, PluginTypeModule);
// Just to be safe
mRegistry->Flush();
delete mRegistry;
registry.Flush();
}
void PluginManager::SaveGroup(PluginType type)
void PluginManager::SaveGroup(wxFileConfig *pRegistry, PluginType type)
{
wxString group = GetPluginTypeString(type);
for (PluginMap::iterator iter = mPlugins.begin(); iter != mPlugins.end(); ++iter)
@ -2060,17 +2050,17 @@ void PluginManager::SaveGroup(PluginType type)
continue;
}
mRegistry->SetPath(REGROOT + group + wxCONFIG_PATH_SEPARATOR + ConvertID(plug.GetID()));
pRegistry->SetPath(REGROOT + group + wxCONFIG_PATH_SEPARATOR + ConvertID(plug.GetID()));
mRegistry->Write(KEY_PATH, plug.GetPath());
mRegistry->Write(KEY_SYMBOL, plug.GetSymbol());
mRegistry->Write(KEY_NAME, plug.GetName(false));
mRegistry->Write(KEY_VERSION, plug.GetVersion(false));
mRegistry->Write(KEY_VENDOR, plug.GetVendor(false));
mRegistry->Write(KEY_DESCRIPTION, plug.GetDescription(false));
mRegistry->Write(KEY_PROVIDERID, plug.GetProviderID());
mRegistry->Write(KEY_ENABLED, plug.IsEnabled());
mRegistry->Write(KEY_VALID, plug.IsValid());
pRegistry->Write(KEY_PATH, plug.GetPath());
pRegistry->Write(KEY_SYMBOL, plug.GetSymbol());
pRegistry->Write(KEY_NAME, plug.GetName(false));
pRegistry->Write(KEY_VERSION, plug.GetVersion(false));
pRegistry->Write(KEY_VENDOR, plug.GetVendor(false));
pRegistry->Write(KEY_DESCRIPTION, plug.GetDescription(false));
pRegistry->Write(KEY_PROVIDERID, plug.GetProviderID());
pRegistry->Write(KEY_ENABLED, plug.IsEnabled());
pRegistry->Write(KEY_VALID, plug.IsValid());
switch (type)
{
@ -2101,19 +2091,19 @@ void PluginManager::SaveGroup(PluginType type)
{
stype = KEY_EFFECTTYPE_HIDDEN;
}
mRegistry->Write(KEY_EFFECTTYPE, stype);
mRegistry->Write(KEY_EFFECTFAMILY, plug.GetEffectFamily(false));
mRegistry->Write(KEY_EFFECTDEFAULT, plug.IsEffectDefault());
mRegistry->Write(KEY_EFFECTINTERACTIVE, plug.IsEffectInteractive());
mRegistry->Write(KEY_EFFECTREALTIME, plug.IsEffectRealtime());
mRegistry->Write(KEY_EFFECTAUTOMATABLE, plug.IsEffectAutomatable());
pRegistry->Write(KEY_EFFECTTYPE, stype);
pRegistry->Write(KEY_EFFECTFAMILY, plug.GetEffectFamily(false));
pRegistry->Write(KEY_EFFECTDEFAULT, plug.IsEffectDefault());
pRegistry->Write(KEY_EFFECTINTERACTIVE, plug.IsEffectInteractive());
pRegistry->Write(KEY_EFFECTREALTIME, plug.IsEffectRealtime());
pRegistry->Write(KEY_EFFECTAUTOMATABLE, plug.IsEffectAutomatable());
}
break;
case PluginTypeImporter:
{
mRegistry->Write(KEY_IMPORTERIDENT, plug.GetImporterIdentifier());
mRegistry->Write(KEY_IMPORTERFILTER, plug.GetImporterFilterDescription());
pRegistry->Write(KEY_IMPORTERIDENT, plug.GetImporterIdentifier());
pRegistry->Write(KEY_IMPORTERFILTER, plug.GetImporterFilterDescription());
const wxArrayString & extensions = plug.GetImporterExtensions();
wxString strExt;
for (size_t i = 0, cnt = extensions.size(); i < cnt; i++)
@ -2121,7 +2111,7 @@ void PluginManager::SaveGroup(PluginType type)
strExt += extensions[i] + wxT(":");
}
strExt.RemoveLast(1);
mRegistry->Write(KEY_IMPORTEREXTENSIONS, strExt);
pRegistry->Write(KEY_IMPORTEREXTENSIONS, strExt);
}
break;
@ -2517,7 +2507,7 @@ wxFileConfig *PluginManager::GetSettings()
{
if (!mSettings)
{
mSettings = new wxFileConfig(wxEmptyString, wxEmptyString, FileNames::PluginSettings());
mSettings = std::make_unique<wxFileConfig>(wxEmptyString, wxEmptyString, FileNames::PluginSettings());
// Check for a settings version that we can understand
if (mSettings->HasEntry(SETVERKEY))
@ -2540,7 +2530,7 @@ wxFileConfig *PluginManager::GetSettings()
}
}
return mSettings;
return mSettings.get();
}
bool PluginManager::HasGroup(const wxString & group)

View File

@ -273,9 +273,9 @@ private:
~PluginManager();
void Load();
void LoadGroup(PluginType type);
void LoadGroup(wxFileConfig *pRegistry, PluginType type);
void Save();
void SaveGroup(PluginType type);
void SaveGroup(wxFileConfig *pRegistry, PluginType type);
PluginDescriptor & CreatePlugin(const PluginID & id, IdentInterface *ident, PluginType type);
@ -316,8 +316,7 @@ private:
bool IsDirty();
void SetDirty(bool dirty = true);
wxFileConfig *mRegistry;
wxFileConfig *mSettings;
std::unique_ptr<wxFileConfig> mSettings;
bool mDirty;
int mCurrentIndex;

View File

@ -67,6 +67,7 @@
#include "Prefs.h"
std::unique_ptr<wxFileConfig> ugPrefs {};
wxFileConfig *gPrefs = NULL;
int gMenusDirty = 0;
@ -134,9 +135,11 @@ void InitPreferences()
wxFileName configFileName(FileNames::DataDir(), wxT("audacity.cfg"));
gPrefs = new wxFileConfig(appName, wxEmptyString,
configFileName.GetFullPath(),
wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
ugPrefs = std::make_unique<wxFileConfig>
(appName, wxEmptyString,
configFileName.GetFullPath(),
wxEmptyString, wxCONFIG_USE_LOCAL_FILE);
gPrefs = ugPrefs.get();
wxConfigBase::Set(gPrefs);
@ -318,7 +321,7 @@ void FinishPreferences()
{
if (gPrefs) {
wxConfigBase::Set(NULL);
delete gPrefs;
ugPrefs.reset();
gPrefs = NULL;
}
}

View File

@ -20,6 +20,7 @@ but it will probably work fine if you use it on a high level.
*//*******************************************************************/
#include "Audacity.h"
#include "Profiler.h"
#include <stdio.h>
#include <string.h>
@ -54,10 +55,6 @@ Profiler::~Profiler()
fprintf(log,"\n****************************************\n\n\n");
fclose(log);
//DELETE everything.
for(int i=0;i<(int)mTasks.size();i++)
delete mTasks[i];
}
}
@ -83,14 +80,10 @@ void Profiler::End(char* fileName, int lineNum, char* taskDescription)
///Gets the singleton instance
Profiler* Profiler::Instance()
{
static Profiler* pro=NULL;
static Profiler pro;
//this isn't 100% threadsafe but I think Okay for this purpose.
if(!pro)
pro = new Profiler();
return pro;
return &pro;
}
///find a taskProfile for the given task, otherwise create
@ -99,12 +92,12 @@ TaskProfile* Profiler::GetOrCreateTaskProfile(char* fileName, int lineNum)
for(int i=0;i<(int)mTasks.size();i++)
{
if(strcmp(fileName,mTasks[i]->mFileName)==0 && lineNum == mTasks[i]->mLine)
return mTasks[i];
return mTasks[i].get();
}
TaskProfile* tp = new TaskProfile();
mTasks.push_back(tp);
return tp;
auto tp = make_movable<TaskProfile>();
mTasks.push_back(std::move(tp));
return mTasks.back().get();
}
TaskProfile* Profiler::GetTaskProfileByDescription(char* description)
@ -112,7 +105,7 @@ TaskProfile* Profiler::GetTaskProfileByDescription(char* description)
for(int i=0;i<(int)mTasks.size();i++)
{
if(strcmp(description,mTasks[i]->mDescription)==0)
return mTasks[i];
return mTasks[i].get();
}
return NULL;

View File

@ -26,6 +26,7 @@ but it will probably work fine if you use it on a high level.
#ifndef __AUDACITY_PROFILER__
#define __AUDACITY_PROFILER__
#include "MemoryX.h"
#include <vector>
#include <time.h>
#include "ondemand/ODTaskThread.h"
@ -59,7 +60,7 @@ class Profiler
TaskProfile* GetTaskProfileByDescription(char* description);
//List of current Task to do.
std::vector<TaskProfile*> mTasks;
std::vector<movable_ptr<TaskProfile>> mTasks;
//mutex for above variable
ODLock mTasksMutex;

View File

@ -2026,7 +2026,7 @@ ShuttleGui::ShuttleGui(wxWindow * pParent, teShuttleMode ShuttleMode) :
return;
}
mpShuttle = new ShuttlePrefs;
mpShuttle = std::make_unique<ShuttlePrefs>();
// In this case the client is the GUI, so if creating we do want to
// store in the client.
mpShuttle->mbStoreInClient = (mShuttleMode == eIsCreating );
@ -2034,8 +2034,6 @@ ShuttleGui::ShuttleGui(wxWindow * pParent, teShuttleMode ShuttleMode) :
ShuttleGui::~ShuttleGui()
{
if( mpShuttle )
delete mpShuttle;
}
// Now we have Audacity specific shuttle functions.

View File

@ -286,7 +286,7 @@ protected:
wxSizer * pSizerStack[ nMaxNestedSizers ];
wxString mBoxName;
Shuttle * mpShuttle; /*! Controls source/destination of shuttled data. You can
std::unique_ptr<Shuttle> mpShuttle; /*! Controls source/destination of shuttled data. You can
leave this NULL if you are shuttling to variables */
int miNoMatchSelector; //! Used in choices to determine which item to use on no match.

View File

@ -83,7 +83,7 @@ void SplashDialog::Populate( ShuttleGui & S )
S.StartVerticalLay(1);
//v For now, change to AudacityLogoWithName via old-fashioned ways, not Theme.
m_pLogo = new wxBitmap((const char **) AudacityLogoWithName_xpm); //v
m_pLogo = std::make_unique<wxBitmap>((const char **) AudacityLogoWithName_xpm); //v
// JKC: Resize to 50% of size. Later we may use a smaller xpm as
// our source, but this allows us to tweak the size - if we want to.
@ -123,7 +123,6 @@ void SplashDialog::Populate( ShuttleGui & S )
SplashDialog::~SplashDialog()
{
delete m_pLogo;
}
void SplashDialog::OnDontShow( wxCommandEvent & Evt )

View File

@ -11,6 +11,7 @@
#ifndef __AUDACITY_SPLASH_DLG__
#define __AUDACITY_SPLASH_DLG__
#include "MemoryX.h"
#include <wx/dialog.h>
#include "widgets/wxPanelWrapper.h"
@ -38,7 +39,7 @@ private:
void OnDontShow( wxCommandEvent & Evt );
HtmlWindow * mpHtml;
wxBitmap* m_pLogo; //vvv
std::unique_ptr<wxBitmap> m_pLogo; //vvv
static SplashDialog * pSelf;
};

View File

@ -274,12 +274,11 @@ TrackArtist::TrackArtist()
UpdatePrefs();
SetColours();
vruler = new Ruler;
vruler = std::make_unique<Ruler>();
}
TrackArtist::~TrackArtist()
{
delete vruler;
}
void TrackArtist::SetColours()

View File

@ -18,6 +18,7 @@
#ifndef __AUDACITY_TRACKARTIST__
#define __AUDACITY_TRACKARTIST__
#include "MemoryX.h"
#include <wx/brush.h>
#include <wx/pen.h>
#include "Experimental.h"
@ -200,7 +201,7 @@ class AUDACITY_DLL_API TrackArtist {
wxPen muteClippedPen;
wxPen blankSelectedPen;
Ruler *vruler;
std::unique_ptr<Ruler> vruler;
#ifdef EXPERIMENTAL_FFT_Y_GRID
bool fftYGridOld;

View File

@ -55,13 +55,6 @@ EffectManager::~EffectManager()
// wxWidgets has already destroyed the rack since it was derived from wxFrame. So
// no need to DELETE it here.
#endif
EffectMap::iterator iter = mHostEffects.begin();
while (iter != mHostEffects.end())
{
delete iter->second;
++iter;
}
}
// Here solely for the purpose of Nyquist Workbench until
@ -706,13 +699,11 @@ Effect *EffectManager::GetEffect(const PluginID & ID)
// TODO: This is temporary and should be redone when all effects are converted
if (mEffects.find(ID) == mEffects.end())
{
Effect *effect;
// This will instantiate the effect client if it hasn't already been done
EffectIdentInterface *ident = dynamic_cast<EffectIdentInterface *>(PluginManager::Get().GetInstance(ID));
if (ident && ident->IsLegacy())
{
effect = dynamic_cast<Effect *>(ident);
auto effect = dynamic_cast<Effect *>(ident);
if (effect && effect->Startup(NULL))
{
mEffects[ID] = effect;
@ -720,18 +711,17 @@ Effect *EffectManager::GetEffect(const PluginID & ID)
}
}
effect = new Effect();
auto effect = std::make_shared<Effect>(); // TODO: use make_unique and store in std::unordered_map
if (effect)
{
EffectClientInterface *client = dynamic_cast<EffectClientInterface *>(ident);
if (client && effect->Startup(client))
{
mEffects[ID] = effect;
mHostEffects[ID] = effect;
return effect;
auto pEffect = effect.get();
mEffects[ID] = pEffect;
mHostEffects[ID] = std::move(effect);
return pEffect;
}
delete effect;
}
wxMessageBox(wxString::Format(_("Attempting to initialize the following effect failed:\n\n%s\n\nMore information may be available in Help->Show Log"),

View File

@ -35,6 +35,7 @@ effects.
WX_DEFINE_USER_EXPORTED_ARRAY(Effect *, EffectArray, class AUDACITY_DLL_API);
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(Effect *, EffectMap, class AUDACITY_DLL_API);
WX_DECLARE_STRING_HASH_MAP_WITH_DECL(std::shared_ptr<Effect>, EffectOwnerMap, class AUDACITY_DLL_API);
#if defined(EXPERIMENTAL_EFFECTS_RACK)
class EffectRack;
@ -127,7 +128,7 @@ private:
private:
EffectMap mEffects;
EffectMap mHostEffects;
EffectOwnerMap mHostEffects;
int mNumEffects;