mirror of
https://github.com/cookiengineer/audacity
synced 2025-10-15 07:01:18 +02:00
Remove some naked new amd delete in: commands
This commit is contained in:
@@ -39,36 +39,30 @@ CommandDirectory::CommandDirectory()
|
|||||||
{
|
{
|
||||||
// Create the command map.
|
// Create the command map.
|
||||||
// Adding an entry here is the easiest way to register a Command class.
|
// Adding an entry here is the easiest way to register a Command class.
|
||||||
AddCommand(new ScreenshotCommandType());
|
AddCommand(make_movable<ScreenshotCommandType>());
|
||||||
AddCommand(new BatchEvalCommandType());
|
AddCommand(make_movable<BatchEvalCommandType>());
|
||||||
AddCommand(new ExecMenuCommandType());
|
AddCommand(make_movable<ExecMenuCommandType>());
|
||||||
AddCommand(new GetAllMenuCommandsType());
|
AddCommand(make_movable<GetAllMenuCommandsType>());
|
||||||
AddCommand(new MessageCommandType());
|
AddCommand(make_movable<MessageCommandType>());
|
||||||
AddCommand(new GetTrackInfoCommandType());
|
AddCommand(make_movable<GetTrackInfoCommandType>());
|
||||||
AddCommand(new GetProjectInfoCommandType());
|
AddCommand(make_movable<GetProjectInfoCommandType>());
|
||||||
|
|
||||||
AddCommand(new HelpCommandType());
|
AddCommand(make_movable<HelpCommandType>());
|
||||||
AddCommand(new SelectCommandType());
|
AddCommand(make_movable<SelectCommandType>());
|
||||||
AddCommand(new CompareAudioCommandType());
|
AddCommand(make_movable<CompareAudioCommandType>());
|
||||||
AddCommand(new SetTrackInfoCommandType());
|
AddCommand(make_movable<SetTrackInfoCommandType>());
|
||||||
AddCommand(new SetProjectInfoCommandType());
|
AddCommand(make_movable<SetProjectInfoCommandType>());
|
||||||
|
|
||||||
AddCommand(new SetPreferenceCommandType());
|
AddCommand(make_movable<SetPreferenceCommandType>());
|
||||||
AddCommand(new GetPreferenceCommandType());
|
AddCommand(make_movable<GetPreferenceCommandType>());
|
||||||
AddCommand(new ImportCommandType());
|
AddCommand(make_movable<ImportCommandType>());
|
||||||
AddCommand(new ExportCommandType());
|
AddCommand(make_movable<ExportCommandType>());
|
||||||
AddCommand(new OpenProjectCommandType());
|
AddCommand(make_movable<OpenProjectCommandType>());
|
||||||
AddCommand(new SaveProjectCommandType());
|
AddCommand(make_movable<SaveProjectCommandType>());
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandDirectory::~CommandDirectory()
|
CommandDirectory::~CommandDirectory()
|
||||||
{
|
{
|
||||||
// Delete the factories
|
|
||||||
CommandMap::iterator iter;
|
|
||||||
for (iter = mCmdMap.begin(); iter != mCmdMap.end(); ++iter)
|
|
||||||
{
|
|
||||||
delete iter->second;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandType *CommandDirectory::LookUp(const wxString &cmdName) const
|
CommandType *CommandDirectory::LookUp(const wxString &cmdName) const
|
||||||
@@ -78,10 +72,10 @@ CommandType *CommandDirectory::LookUp(const wxString &cmdName) const
|
|||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return iter->second;
|
return iter->second.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandDirectory::AddCommand(CommandType *type)
|
void CommandDirectory::AddCommand(movable_ptr<CommandType> &&type)
|
||||||
{
|
{
|
||||||
wxASSERT(type != NULL);
|
wxASSERT(type != NULL);
|
||||||
wxString cmdName = type->GetName();
|
wxString cmdName = type->GetName();
|
||||||
@@ -89,7 +83,7 @@ void CommandDirectory::AddCommand(CommandType *type)
|
|||||||
, wxT("A command named ") + cmdName
|
, wxT("A command named ") + cmdName
|
||||||
+ wxT(" already exists."));
|
+ wxT(" already exists."));
|
||||||
|
|
||||||
mCmdMap[cmdName] = type;
|
mCmdMap[cmdName] = std::move(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandDirectory *CommandDirectory::Get()
|
CommandDirectory *CommandDirectory::Get()
|
||||||
|
@@ -44,7 +44,7 @@ public:
|
|||||||
CommandType *LookUp(const wxString &cmdName) const;
|
CommandType *LookUp(const wxString &cmdName) const;
|
||||||
|
|
||||||
/// Register a type of command with the directory.
|
/// Register a type of command with the directory.
|
||||||
void AddCommand(CommandType *type);
|
void AddCommand(movable_ptr<CommandType> &&type);
|
||||||
|
|
||||||
/// Get a pointer to the singleton instance
|
/// Get a pointer to the singleton instance
|
||||||
static CommandDirectory *Get();
|
static CommandDirectory *Get();
|
||||||
|
@@ -16,20 +16,21 @@
|
|||||||
|
|
||||||
*//*******************************************************************/
|
*//*******************************************************************/
|
||||||
|
|
||||||
#include <wx/event.h>
|
#include "../Audacity.h"
|
||||||
#include "CommandHandler.h"
|
#include "CommandHandler.h"
|
||||||
|
#include <wx/event.h>
|
||||||
#include "../Project.h"
|
#include "../Project.h"
|
||||||
#include "Command.h"
|
#include "Command.h"
|
||||||
#include "AppCommandEvent.h"
|
#include "AppCommandEvent.h"
|
||||||
#include "ScriptCommandRelay.h"
|
#include "ScriptCommandRelay.h"
|
||||||
|
|
||||||
CommandHandler::CommandHandler(AudacityApp &app)
|
CommandHandler::CommandHandler(AudacityApp &app)
|
||||||
: mCurrentContext(new CommandExecutionContext(&app, GetActiveProject()))
|
: mCurrentContext(std::make_unique<CommandExecutionContext>
|
||||||
|
(&app, GetActiveProject()))
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
CommandHandler::~CommandHandler()
|
CommandHandler::~CommandHandler()
|
||||||
{
|
{
|
||||||
delete mCurrentContext;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void CommandHandler::SetProject(AudacityProject *)
|
void CommandHandler::SetProject(AudacityProject *)
|
||||||
|
@@ -16,6 +16,7 @@
|
|||||||
#ifndef __COMMANDHANDLER__
|
#ifndef __COMMANDHANDLER__
|
||||||
#define __COMMANDHANDLER__
|
#define __COMMANDHANDLER__
|
||||||
|
|
||||||
|
#include "../MemoryX.h"
|
||||||
#include "../AudacityApp.h"
|
#include "../AudacityApp.h"
|
||||||
class AudacityProject;
|
class AudacityProject;
|
||||||
class AppCommandEvent;
|
class AppCommandEvent;
|
||||||
@@ -24,7 +25,7 @@ class CommandExecutionContext;
|
|||||||
class CommandHandler
|
class CommandHandler
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CommandExecutionContext *mCurrentContext;
|
std::unique_ptr<CommandExecutionContext> mCurrentContext;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommandHandler(AudacityApp &app);
|
CommandHandler(AudacityApp &app);
|
||||||
|
@@ -93,8 +93,8 @@ class AUDACITY_DLL_API CommandManager final : public XMLTagHandler
|
|||||||
CommandManager();
|
CommandManager();
|
||||||
virtual ~CommandManager();
|
virtual ~CommandManager();
|
||||||
|
|
||||||
CommandManager(const CommandManager&) = delete;
|
CommandManager(const CommandManager&) PROHIBITED;
|
||||||
CommandManager &operator= (const CommandManager&) = delete;
|
CommandManager &operator= (const CommandManager&) PROHIBITED;
|
||||||
|
|
||||||
void PurgeData();
|
void PurgeData();
|
||||||
|
|
||||||
|
@@ -23,6 +23,7 @@
|
|||||||
class CommandType;
|
class CommandType;
|
||||||
|
|
||||||
// Map from parameter name to the value of the parameter
|
// Map from parameter name to the value of the parameter
|
||||||
|
// to do: use hash
|
||||||
typedef std::map<wxString, wxVariant> ParamValueMap;
|
typedef std::map<wxString, wxVariant> ParamValueMap;
|
||||||
|
|
||||||
// Map from parameter name to a suitable Validator
|
// Map from parameter name to a suitable Validator
|
||||||
@@ -30,6 +31,7 @@ typedef std::map<wxString, wxVariant> ParamValueMap;
|
|||||||
typedef std::map<wxString, movable_ptr<Validator>> ValidatorMap;
|
typedef std::map<wxString, movable_ptr<Validator>> ValidatorMap;
|
||||||
|
|
||||||
// Map from command name to type
|
// Map from command name to type
|
||||||
typedef std::map<wxString, CommandType*> CommandMap;
|
// to do: use hash
|
||||||
|
typedef std::map<wxString, movable_ptr<CommandType>> CommandMap;
|
||||||
|
|
||||||
#endif /* End of include guard: __COMMANDMISC__ */
|
#endif /* End of include guard: __COMMANDMISC__ */
|
||||||
|
@@ -47,7 +47,7 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
/// Sends command progress information to a ProgressDialog
|
/// Sends command progress information to a ProgressDialog
|
||||||
class GUIProgressTarget : public CommandProgressTarget
|
class GUIProgressTarget final : public CommandProgressTarget
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ProgressDialog &mProgress;
|
ProgressDialog &mProgress;
|
||||||
@@ -74,18 +74,17 @@ public:
|
|||||||
class ProgressToMessageTarget final : public CommandProgressTarget
|
class ProgressToMessageTarget final : public CommandProgressTarget
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CommandMessageTarget &mTarget;
|
std::unique_ptr<CommandMessageTarget> mTarget;
|
||||||
public:
|
public:
|
||||||
ProgressToMessageTarget(CommandMessageTarget *target)
|
ProgressToMessageTarget(std::unique_ptr<CommandMessageTarget> &&target)
|
||||||
: mTarget(*target)
|
: mTarget(std::move(target))
|
||||||
{ }
|
{ }
|
||||||
virtual ~ProgressToMessageTarget()
|
virtual ~ProgressToMessageTarget()
|
||||||
{
|
{
|
||||||
// delete &mTarget;
|
|
||||||
}
|
}
|
||||||
void Update(double completed) override
|
void Update(double completed) override
|
||||||
{
|
{
|
||||||
mTarget.Update(wxString::Format(wxT("%.2f%%"), completed*100));
|
mTarget->Update(wxString::Format(wxT("%.2f%%"), completed*100));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -94,7 +93,7 @@ class NullMessageTarget final : public CommandMessageTarget
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
virtual ~NullMessageTarget() {}
|
virtual ~NullMessageTarget() {}
|
||||||
void Update(const wxString &message) override {}
|
void Update(const wxString &) override {}
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Displays messages from a command in a wxMessageBox
|
/// Displays messages from a command in a wxMessageBox
|
||||||
@@ -146,18 +145,17 @@ public:
|
|||||||
class CombinedMessageTarget final : public CommandMessageTarget
|
class CombinedMessageTarget final : public CommandMessageTarget
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
CommandMessageTarget *m1, *m2;
|
std::unique_ptr<CommandMessageTarget> m1, m2;
|
||||||
public:
|
public:
|
||||||
CombinedMessageTarget(CommandMessageTarget *t1, CommandMessageTarget *t2)
|
CombinedMessageTarget(std::unique_ptr<CommandMessageTarget> &&t1,
|
||||||
: m1(t1), m2(t2)
|
std::unique_ptr<CommandMessageTarget> &&t2)
|
||||||
|
: m1(std::move(t1)), m2(std::move(t2))
|
||||||
{
|
{
|
||||||
wxASSERT(t1 != NULL);
|
wxASSERT(m1);
|
||||||
wxASSERT(t2 != NULL);
|
wxASSERT(m2);
|
||||||
}
|
}
|
||||||
~CombinedMessageTarget()
|
~CombinedMessageTarget()
|
||||||
{
|
{
|
||||||
delete m1;
|
|
||||||
delete m2;
|
|
||||||
}
|
}
|
||||||
void Update(const wxString &message) override
|
void Update(const wxString &message) override
|
||||||
{
|
{
|
||||||
@@ -167,7 +165,8 @@ public:
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
// By default, we ignore progress updates but display all other messages directly
|
// By default, we ignore progress updates but display all other messages
|
||||||
|
// directly
|
||||||
class TargetFactory
|
class TargetFactory
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
@@ -24,35 +24,25 @@ Also acts as a factory.
|
|||||||
#include <wx/string.h>
|
#include <wx/string.h>
|
||||||
|
|
||||||
CommandType::CommandType()
|
CommandType::CommandType()
|
||||||
: mName(NULL), mSignature(NULL)
|
: mName{}, mSignature{}
|
||||||
{ }
|
{ }
|
||||||
|
|
||||||
CommandType::~CommandType()
|
CommandType::~CommandType()
|
||||||
{
|
{
|
||||||
if (mName != NULL)
|
|
||||||
{
|
|
||||||
delete mName;
|
|
||||||
}
|
|
||||||
if (mSignature != NULL)
|
|
||||||
{
|
|
||||||
delete mSignature;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
wxString CommandType::GetName()
|
const wxString &CommandType::GetName()
|
||||||
{
|
{
|
||||||
if (mName == NULL)
|
if (mName.empty())
|
||||||
{
|
mName = BuildName();
|
||||||
mName = new wxString(BuildName());
|
return mName;
|
||||||
}
|
|
||||||
return *mName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
CommandSignature &CommandType::GetSignature()
|
CommandSignature &CommandType::GetSignature()
|
||||||
{
|
{
|
||||||
if (mSignature == NULL)
|
if (!mSignature)
|
||||||
{
|
{
|
||||||
mSignature = new CommandSignature();
|
mSignature.create();
|
||||||
BuildSignature(*mSignature);
|
BuildSignature(*mSignature);
|
||||||
}
|
}
|
||||||
return *mSignature;
|
return *mSignature;
|
||||||
|
@@ -17,6 +17,7 @@
|
|||||||
#define __COMMANDTYPE__
|
#define __COMMANDTYPE__
|
||||||
|
|
||||||
#include "CommandMisc.h"
|
#include "CommandMisc.h"
|
||||||
|
#include "CommandSignature.h"
|
||||||
#include "../MemoryX.h"
|
#include "../MemoryX.h"
|
||||||
|
|
||||||
class Command;
|
class Command;
|
||||||
@@ -28,13 +29,13 @@ class wxString;
|
|||||||
class CommandType /* not final */
|
class CommandType /* not final */
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
wxString *mName;
|
wxString mName;
|
||||||
CommandSignature *mSignature;
|
Maybe<CommandSignature> mSignature;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
CommandType();
|
CommandType();
|
||||||
virtual ~CommandType();
|
virtual ~CommandType();
|
||||||
wxString GetName();
|
const wxString &GetName();
|
||||||
CommandSignature &GetSignature();
|
CommandSignature &GetSignature();
|
||||||
wxString Describe();
|
wxString Describe();
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user