Audacity  2.2.2
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 <wx/app.h>
21 #include "../MemoryX.h"
22 
23 #include "CommandMisc.h"
24 #include "CommandSignature.h"
25 #include "CommandTargets.h"
26 #include "../commands/AudacityCommand.h"
27 
28 class AudacityApp;
29 class CommandContext;
31 
32 // Abstract base class for command interface.
33 class OldStyleCommand /* not final */
34 {
35 public:
37  virtual ~OldStyleCommand() { }
38  virtual IdentInterfaceSymbol GetSymbol() = 0;
39  virtual CommandSignature &GetSignature() = 0;
40  virtual bool SetParameter(const wxString &paramName, const wxVariant &paramValue);
41  virtual bool Apply()=0;
42  virtual bool Apply(const CommandContext &context) = 0;
43 };
44 
45 using OldStyleCommandPointer = std::shared_ptr<OldStyleCommand>;
46 
49 class DecoratedCommand /* not final */ : public OldStyleCommand
50 {
51 protected:
53 public:
55  : mCommand(cmd)
56  {
57  wxASSERT(cmd != NULL);
58  }
59  virtual ~DecoratedCommand();
61  CommandSignature &GetSignature() override;
62  bool SetParameter(const wxString &paramName, const wxVariant &paramValue) override;
63 };
64 
65 // Decorator command that performs the given command and then outputs a status
66 // message according to the result
68 {
69 public:
70  ApplyAndSendResponse(const OldStyleCommandPointer &cmd, std::unique_ptr<CommandOutputTargets> &target);
71  bool Apply() override;
72  bool Apply(const CommandContext &context) override;// Error to use this.
73  std::unique_ptr<CommandContext> mCtx;
74 
75 };
76 
77 class CommandImplementation /* not final */ : public OldStyleCommand
78 {
79 private:
83 
86  bool Valid(const wxString &paramName, const wxVariant &paramValue);
87 
88 protected:
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 
100 public:
104 
105  virtual ~CommandImplementation();
106 
108  IdentInterfaceSymbol GetSymbol() override;
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__ */
ParamValueMap mParams
Definition: Command.h:81
DecoratedCommand(const OldStyleCommandPointer &cmd)
Definition: Command.h:54
CommandOutputTargets a mix of three output classes to output progress indication, status messages and...
std::map< wxString, wxVariant > ParamValueMap
Definition: CommandMisc.h:23
bool SetParameter(const wxString &paramName, const wxVariant &paramValue) override
Definition: Command.cpp:260
virtual ~CommandImplementation()
Definition: Command.cpp:180
virtual ~DecoratedCommand()
Definition: Command.cpp:105
IdentInterfaceSymbol GetSymbol() override
An instance method for getting the command name (for consistency)
Definition: Command.cpp:249
ApplyAndSendResponse(const OldStyleCommandPointer &cmd, std::unique_ptr< CommandOutputTargets > &target)
Definition: Command.cpp:125
Base class for containing data common to all commands of a given type. Also acts as a factory...
Definition: CommandType.h:44
wxString GetString(const wxString &paramName)
Definition: Command.cpp:240
bool Apply() override
Definition: Command.cpp:139
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
CommandSignature & GetSignature() override
Definition: Command.cpp:114
bool Apply() override
Definition: Command.h:122
void TypeCheck(const wxString &typeName, const wxString &paramName, const wxVariant &param)
Definition: Command.cpp:184
std::map< wxString, bool > ParamBoolMap
Definition: CommandMisc.h:28
ParamBoolMap mSetParams
Definition: Command.h:82
double GetDouble(const wxString &paramName)
Definition: Command.cpp:232
bool HasParam(const wxString &paramName)
Definition: Command.cpp:208
is derived from OldStyleCommand. It validates and applies the command. CommandImplementation::Apply()...
Definition: Command.h:77
long GetLong(const wxString &paramName)
Definition: Command.cpp:224
void CheckParam(const wxString &paramName)
Definition: Command.cpp:198
bool Valid(const wxString &paramName, const wxVariant &paramValue)
IdentInterfaceSymbol GetSymbol() override
Definition: Command.cpp:109
virtual CommandSignature & GetSignature()=0
AudacityApp is the 'main' class for Audacity.
Definition: AudacityApp.h:59
OldStyleCommandPointer mCommand
Definition: Command.h:52
virtual ~OldStyleCommand()
Definition: Command.h:37
IdentInterfaceSymbol pairs a persistent string identifier used internally with an optional...
bool SetParameter(const wxString &paramName, const wxVariant &paramValue) override
Definition: Command.cpp:119
OldStyleCommandType & mType
Definition: Command.h:80
std::unique_ptr< CommandContext > mCtx
Definition: Command.h:73
CommandSignature & GetSignature() override
Get the signature of the command.
Definition: Command.cpp:255
DecoratedCommand is a decorator for command. It forwards functions to the mCommand it holds...
Definition: Command.h:49
CommandImplementation(OldStyleCommandType &type)
Definition: Command.cpp:173
ApplyAndSendResponse is a DecoratoredCommand that performs the given command and then outputs a statu...
Definition: Command.h:67
virtual bool Apply()=0
OldStyleCommandPointer is a unique_ptr to an OldStyleCommand.
virtual IdentInterfaceSymbol GetSymbol()=0
virtual bool SetParameter(const wxString &paramName, const wxVariant &paramValue)
Definition: Command.cpp:98
bool GetBool(const wxString &paramName)
Definition: Command.cpp:216
Class that maps parameter names to default values and validators.
Declaration of CommandSignature class.
Abstract base class for command interface. This is the version created by Dan Horgan. It was previously a factory for other command classes. It created a separation between the type of a command and the command itself, which is being removed. These Cmmands were managed by CommandDirectory.
Definition: Command.h:33