Audacity 3.2.0
Public Member Functions | Private Member Functions | Private Attributes | List of all members
CommandBuilder Class Reference

A type of factory for Commands of various sorts. More...

#include <CommandBuilder.h>

Collaboration diagram for CommandBuilder:
[legend]

Public Member Functions

 CommandBuilder (AudacityProject &project, const wxString &cmdString)
 
 CommandBuilder (AudacityProject &project, const wxString &cmdName, const wxString &cmdParams)
 
 ~CommandBuilder ()
 
bool WasValid ()
 
OldStyleCommandPointer GetCommand ()
 
wxString GetResponse ()
 

Private Member Functions

void Failure (const wxString &msg={})
 
void Success (const OldStyleCommandPointer &cmd)
 
void BuildCommand (AudacityProject &project, const wxString &cmdName, const wxString &cmdParams)
 
void BuildCommand (AudacityProject &project, const wxString &cmdString)
 

Private Attributes

bool mValid
 
ResponseTargetPointer mResponse
 
OldStyleCommandPointer mCommand
 
wxString mError
 

Detailed Description

A type of factory for Commands of various sorts.

CommandBuilder has the task of deciding what command is meant by a given command string, and producing a suitable command object. For now, it doesn't actually do any processing - it just passes everything on to the BatchCommand system by constructing BatchCommandEval objects.

Definition at line 32 of file CommandBuilder.h.

Constructor & Destructor Documentation

◆ CommandBuilder() [1/2]

CommandBuilder::CommandBuilder ( AudacityProject project,
const wxString &  cmdString 
)

Definition at line 33 of file CommandBuilder.cpp.

35 : mValid(false)
36{
37 BuildCommand(project, cmdString);
38}
void BuildCommand(AudacityProject &project, const wxString &cmdName, const wxString &cmdParams)

References BuildCommand().

Here is the call graph for this function:

◆ CommandBuilder() [2/2]

CommandBuilder::CommandBuilder ( AudacityProject project,
const wxString &  cmdName,
const wxString &  cmdParams 
)

Definition at line 40 of file CommandBuilder.cpp.

42 : mValid(false)
43{
44 BuildCommand(project, cmdName, params);
45}
EffectDistortionSettings params
Definition: Distortion.cpp:75

References BuildCommand(), and params.

Here is the call graph for this function:

◆ ~CommandBuilder()

CommandBuilder::~CommandBuilder ( )

Definition at line 47 of file CommandBuilder.cpp.

48{
49}

Member Function Documentation

◆ BuildCommand() [1/2]

void CommandBuilder::BuildCommand ( AudacityProject project,
const wxString &  cmdName,
const wxString &  cmdParams 
)
private

Definition at line 85 of file CommandBuilder.cpp.

88{
89 // Stage 1: create a Command object of the right type
90
91 mResponse = std::make_shared< ResponseTarget >();
92 auto output
93 = std::make_unique<CommandOutputTargets>(std::make_unique<NullProgressTarget>(),
95 mResponse);
96
97#ifdef OLD_BATCH_SYSTEM
99
100 if (factory == NULL)
101 {
102 // Fall back to hoping the Batch Command system can handle it
103#endif
104 OldStyleCommandType *type = CommandDirectory::Get()->LookUp(wxT("BatchCommand"));
105 wxASSERT(type != NULL);
106 mCommand = type->Create(project, nullptr);
107 mCommand->SetParameter(wxT("CommandName"), cmdName);
108 mCommand->SetParameter(wxT("ParamString"), cmdParamsArg);
109 auto aCommand = std::make_shared<ApplyAndSendResponse>(mCommand, output);
110 Success(aCommand);
111 return;
112#ifdef OLD_BATCH_SYSTEM
113 }
114
115 CommandSignature &signature = factory->GetSignature();
116 mCommand = factory->Create(nullptr);
117 //mCommand->SetOutput( std::move(output) );
118 // Stage 2: set the parameters
119
120 ShuttleCli shuttle;
121 shuttle.mParams = cmdParamsArg;
122 shuttle.mbStoreInClient = true;
123
124 ParamValueMap::const_iterator iter;
125 ParamValueMap params = signature.GetDefaults();
126
127 // Iterate through the parameters defined by the command
128 for (iter = params.begin(); iter != params.end(); ++iter)
129 {
130 wxString paramString;
131 // IF there is a match in the args actually used
132 if (shuttle.TransferString(iter->first, paramString, wxT("")))
133 {
134 // Then set that parameter.
135 if (!mCommand->SetParameter(iter->first, paramString))
136 {
137 Failure();
138 return;
139 }
140 }
141 }
142
143 // Check for unrecognised parameters
144
145 wxString cmdParams(cmdParamsArg);
146
147 while (!cmdParams.empty())
148 {
149 cmdParams.Trim(true);
150 cmdParams.Trim(false);
151 int splitAt = cmdParams.Find(wxT('='));
152 if (splitAt < 0 && !cmdParams.empty())
153 {
154 Failure(wxT("Parameter string is missing '='"));
155 return;
156 }
157 wxString paramName = cmdParams.Left(splitAt);
158 if (params.find(paramName) == params.end())
159 {
160 Failure(wxT("Unrecognized parameter: '") + paramName + wxT("'"));
161 return;
162 }
163 // Handling of quoted strings is quite limited.
164 // You start and end with a " or a '.
165 // There is no escaping in the string.
166 cmdParams = cmdParams.Mid(splitAt+1);
167 if( cmdParams.empty() )
168 splitAt =-1;
169 else if( cmdParams[0] == '\"' ){
170 cmdParams = cmdParams.Mid(1);
171 splitAt = cmdParams.Find(wxT('\"'))+1;
172 }
173 else if( cmdParams[0] == '\'' ){
174 cmdParams = cmdParams.Mid(1);
175 splitAt = cmdParams.Find(wxT('\''))+1;
176 }
177 else
178 splitAt = cmdParams.Find(wxT(' '))+1;
179 if (splitAt < 1)
180 {
181 splitAt = cmdParams.length();
182 }
183 cmdParams = cmdParams.Mid(splitAt);
184 }
185 auto aCommand = std::make_shared<ApplyAndSendResponse>(mCommand, output);
186 Success(aCommand);
187#endif
188}
wxT("CloseDown"))
std::map< wxString, wxVariant > ParamValueMap
Definition: CommandMisc.h:23
void Failure(const wxString &msg={})
void Success(const OldStyleCommandPointer &cmd)
ResponseTargetPointer mResponse
OldStyleCommandPointer mCommand
OldStyleCommandType * LookUp(const wxString &cmdName) const
static CommandDirectory * Get()
Get a pointer to the singleton instance.
Class that maps parameter names to default values and validators.
ParamValueMap GetDefaults() const
Base class for containing data common to all commands of a given type. Also acts as a factory.
Definition: CommandType.h:45
virtual OldStyleCommandPointer Create(AudacityProject &project, std::unique_ptr< CommandOutputTargets > &&target)=0
Derived from Shuttle, this class exchanges string parameters with a binary representation.
Definition: Shuttle.h:97
wxString mParams
Definition: Shuttle.h:99
virtual bool TransferString(const wxString &Name, wxString &strValue, const wxString &strDefault)
Definition: Shuttle.cpp:215
bool mbStoreInClient
Definition: Shuttle.h:77
static RegisteredToolbarFactory factory

References OldStyleCommandType::Create(), cloud::factory, Failure(), CommandDirectory::Get(), CommandSignature::GetDefaults(), CommandDirectory::LookUp(), Shuttle::mbStoreInClient, mCommand, ShuttleCli::mParams, mResponse, params, Success(), Shuttle::TransferString(), and wxT().

Referenced by BuildCommand(), and CommandBuilder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ BuildCommand() [2/2]

void CommandBuilder::BuildCommand ( AudacityProject project,
const wxString &  cmdString 
)
private

Definition at line 190 of file CommandBuilder.cpp.

192{
193 wxString cmdString(cmdStringArg);
194
195 // Find the command name terminator... If there is more than one word and
196 // no terminator, the command is badly formed
197 cmdString.Trim(true); cmdString.Trim(false);
198 int splitAt = cmdString.Find(wxT(':'));
199 if (splitAt < 0 && cmdString.Find(wxT(' ')) >= 0) {
200 Failure(wxT("Syntax error!\nCommand is missing ':'"));
201 return;
202 }
203
204 wxString cmdName = cmdString.Left(splitAt);
205 wxString cmdParams = cmdString.Mid(splitAt+1);
206 if( splitAt < 0 )
207 cmdParams = "";
208
209 cmdName.Trim(true);
210 cmdParams.Trim(false);
211
212 BuildCommand(project, cmdName, cmdParams);
213}

References BuildCommand(), Failure(), and wxT().

Here is the call graph for this function:

◆ Failure()

void CommandBuilder::Failure ( const wxString &  msg = {})
private

Definition at line 73 of file CommandBuilder.cpp.

74{
75 mError = msg;
76 mValid = false;
77}

References mError, and mValid.

Referenced by BuildCommand().

Here is the caller graph for this function:

◆ GetCommand()

OldStyleCommandPointer CommandBuilder::GetCommand ( )

Definition at line 56 of file CommandBuilder.cpp.

57{
58 wxASSERT(mValid);
59 wxASSERT(mCommand);
60 auto result = mCommand;
61 mCommand.reset();
62 return result;
63}

References mCommand, and mValid.

Referenced by ExecCommand().

Here is the caller graph for this function:

◆ GetResponse()

wxString CommandBuilder::GetResponse ( )

Definition at line 65 of file CommandBuilder.cpp.

66{
67 if (!mValid && !mError.empty()) {
68 return mError + wxT("\n");
69 }
70 return mResponse->GetResponse() + wxT("\n");
71}

References mError, mResponse, mValid, and wxT().

Referenced by ExecCommand().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ Success()

void CommandBuilder::Success ( const OldStyleCommandPointer cmd)
private

Definition at line 79 of file CommandBuilder.cpp.

80{
81 mCommand = cmd;
82 mValid = true;
83}

References mCommand, and mValid.

Referenced by BuildCommand().

Here is the caller graph for this function:

◆ WasValid()

bool CommandBuilder::WasValid ( )

Definition at line 51 of file CommandBuilder.cpp.

52{
53 return mValid;
54}

References mValid.

Referenced by ExecCommand().

Here is the caller graph for this function:

Member Data Documentation

◆ mCommand

OldStyleCommandPointer CommandBuilder::mCommand
private

Definition at line 37 of file CommandBuilder.h.

Referenced by BuildCommand(), GetCommand(), and Success().

◆ mError

wxString CommandBuilder::mError
private

Definition at line 38 of file CommandBuilder.h.

Referenced by Failure(), and GetResponse().

◆ mResponse

ResponseTargetPointer CommandBuilder::mResponse
private

Definition at line 36 of file CommandBuilder.h.

Referenced by BuildCommand(), and GetResponse().

◆ mValid

bool CommandBuilder::mValid
private

Definition at line 35 of file CommandBuilder.h.

Referenced by Failure(), GetCommand(), GetResponse(), Success(), and WasValid().


The documentation for this class was generated from the following files: