Audacity 3.2.0
Command.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity - A Digital Audio Editor
4 Copyright 1999-2009 Audacity Team
5 File License: wxWidgets
6
7 Dan Horgan
8
9******************************************************************//*******************************************************************/
16
17#ifndef __COMMAND__
18#define __COMMAND__
19
20#include "CommandSignature.h"
22
23class AudacityProject;
24class AudacityApp;
25class CommandContext;
27
28// Abstract base class for command interface.
29class OldStyleCommand /* not final */
30{
31public:
33
35 virtual ~OldStyleCommand() { }
38 virtual bool SetParameter(const wxString &paramName, const wxVariant &paramValue);
39 virtual bool Apply()=0;
40 virtual bool Apply(const CommandContext &context) = 0;
41};
42
43using OldStyleCommandPointer = std::shared_ptr<OldStyleCommand>;
44
47class DecoratedCommand /* not final */ : public OldStyleCommand
48{
49protected:
51public:
53 : OldStyleCommand{ cmd->mProject }, mCommand(cmd)
54 {
55 wxASSERT(cmd != NULL);
56 }
57 virtual ~DecoratedCommand();
60 bool SetParameter(const wxString &paramName, const wxVariant &paramValue) override;
61};
62
63// Decorator command that performs the given command and then outputs a status
64// message according to the result
66{
67public:
69 const OldStyleCommandPointer &cmd, std::unique_ptr<CommandOutputTargets> &target);
70 bool Apply() override;
71 bool Apply(const CommandContext &context) override;// Error to use this.
72 std::unique_ptr<const CommandContext> mCtx;
73
74};
75
76class AUDACITY_DLL_API CommandImplementation /* not final */
77 : public OldStyleCommand
78{
79private:
83
86 bool Valid(const wxString &paramName, const wxVariant &paramValue);
87
88protected:
89 // Convenience methods for allowing subclasses to access parameters
90 void TypeCheck(const wxString &typeName,
91 const wxString &paramName,
92 const wxVariant &param);
93 void CheckParam(const wxString &paramName);
94 bool HasParam( const wxString &paramName);
95 bool GetBool(const wxString &paramName);
96 long GetLong(const wxString &paramName);
97 double GetDouble(const wxString &paramName);
98 wxString GetString(const wxString &paramName);
99
100public:
104
105 virtual ~CommandImplementation();
106
109
111 CommandSignature &GetSignature() override;
112
115 bool SetParameter(const wxString &paramName, const wxVariant &paramValue) override;
116
117 // Subclasses should override the following:
118 // =========================================
119
122 bool Apply() override { return false;};// No longer supported.
123 bool Apply(const CommandContext &context) override;
124};
125
126#endif /* End of include guard: __COMMAND__ */
std::map< wxString, wxVariant > ParamValueMap
Definition: CommandMisc.h:23
std::map< wxString, bool > ParamBoolMap
Definition: CommandMisc.h:28
Declaration of CommandSignature class.
const auto project
ApplyAndSendResponse is a DecoratoredCommand that performs the given command and then outputs a statu...
Definition: Command.h:66
bool Apply(const CommandContext &context) override
ApplyAndSendResponse(const OldStyleCommandPointer &cmd, std::unique_ptr< CommandOutputTargets > &target)
Definition: Command.cpp:122
bool Apply() override
Definition: Command.cpp:137
std::unique_ptr< const CommandContext > mCtx
Definition: Command.h:72
AudacityApp is the 'main' class for Audacity.
Definition: AudacityApp.h:42
The top-level handle to an Audacity project. It serves as a source of events that other objects can b...
Definition: Project.h:90
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
is derived from OldStyleCommand. It validates and applies the command. CommandImplementation::Apply()...
Definition: Command.h:78
bool Apply() override
Definition: Command.h:122
ParamValueMap mParams
Definition: Command.h:81
OldStyleCommandType & mType
Definition: Command.h:80
ParamBoolMap mSetParams
Definition: Command.h:82
bool Valid(const wxString &paramName, const wxVariant &paramValue)
bool Apply(const CommandContext &context) override
CommandOutputTargets a mix of three output classes to output progress indication, status messages and...
Class that maps parameter names to default values and validators.
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
DecoratedCommand is a decorator for command. It forwards functions to the mCommand it holds.
Definition: Command.h:48
CommandSignature & GetSignature() override
Definition: Command.cpp:111
OldStyleCommandPointer mCommand
Definition: Command.h:50
virtual ~DecoratedCommand()
Definition: Command.cpp:102
bool SetParameter(const wxString &paramName, const wxVariant &paramValue) override
Definition: Command.cpp:116
DecoratedCommand(const OldStyleCommandPointer &cmd)
Definition: Command.h:52
ComponentInterfaceSymbol GetSymbol() override
Definition: Command.cpp:106
Abstract base class for command interface. This is the version created by Dan Horgan....
Definition: Command.h:30
OldStyleCommand(AudacityProject &project)
Definition: Command.h:34
virtual bool SetParameter(const wxString &paramName, const wxVariant &paramValue)
Definition: Command.cpp:95
virtual ~OldStyleCommand()
Definition: Command.h:35
virtual CommandSignature & GetSignature()=0
virtual bool Apply()=0
AudacityProject & mProject
Definition: Command.h:32
virtual bool Apply(const CommandContext &context)=0
virtual ComponentInterfaceSymbol GetSymbol()=0
OldStyleCommandPointer is a unique_ptr to an OldStyleCommand.
Base class for containing data common to all commands of a given type. Also acts as a factory.
Definition: CommandType.h:45