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

is derived from OldStyleCommand. It validates and applies the command. CommandImplementation::Apply() is overloaded in classes derived from it. More...

#include <Command.h>

Inheritance diagram for CommandImplementation:
[legend]
Collaboration diagram for CommandImplementation:
[legend]

Public Member Functions

 CommandImplementation (AudacityProject &project, OldStyleCommandType &type)
 
virtual ~CommandImplementation ()
 
ComponentInterfaceSymbol GetSymbol () override
 An instance method for getting the command name (for consistency) More...
 
CommandSignature & GetSignature () override
 Get the signature of the command. More...
 
bool SetParameter (const wxString &paramName, const wxVariant &paramValue) override
 
bool Apply () override
 
bool Apply (const CommandContext &context) override
 
- Public Member Functions inherited from OldStyleCommand
 OldStyleCommand (AudacityProject &project)
 
virtual ~OldStyleCommand ()
 
virtual ComponentInterfaceSymbol GetSymbol ()=0
 
virtual CommandSignature & GetSignature ()=0
 
virtual bool SetParameter (const wxString &paramName, const wxVariant &paramValue)
 
virtual bool Apply ()=0
 
virtual bool Apply (const CommandContext &context)=0
 

Protected Member Functions

void TypeCheck (const wxString &typeName, const wxString &paramName, const wxVariant &param)
 
void CheckParam (const wxString &paramName)
 
bool HasParam (const wxString &paramName)
 
bool GetBool (const wxString &paramName)
 
long GetLong (const wxString &paramName)
 
double GetDouble (const wxString &paramName)
 
wxString GetString (const wxString &paramName)
 

Private Member Functions

bool Valid (const wxString &paramName, const wxVariant &paramValue)
 

Private Attributes

OldStyleCommandType & mType
 
ParamValueMap mParams
 
ParamBoolMap mSetParams
 

Additional Inherited Members

- Public Attributes inherited from OldStyleCommand
AudacityProject & mProject
 

Detailed Description

is derived from OldStyleCommand. It validates and applies the command. CommandImplementation::Apply() is overloaded in classes derived from it.

Definition at line 76 of file Command.h.

Constructor & Destructor Documentation

◆ CommandImplementation()

CommandImplementation::CommandImplementation ( AudacityProject &  project,
OldStyleCommandType &  type 
)

Constructor should not be called directly; only by a factory which ensures name and params are set appropriately for the command.

Definition at line 171 of file Command.cpp.

174 mType(type),
176 mSetParams()
177{
178}
const auto project
ParamValueMap mParams
Definition: Command.h:81
OldStyleCommandType & mType
Definition: Command.h:80
ParamBoolMap mSetParams
Definition: Command.h:82
ParamValueMap GetDefaults() const
Abstract base class for command interface. This is the version created by Dan Horgan....
Definition: Command.h:30
CommandSignature & GetSignature()
Definition: CommandType.cpp:37

◆ ~CommandImplementation()

CommandImplementation::~CommandImplementation ( )
virtual

Definition at line 180 of file Command.cpp.

181{
182}

Member Function Documentation

◆ Apply() [1/2]

bool CommandImplementation::Apply ( )
inlineoverridevirtual

Actually carry out the command. Return true if successful and false otherwise.

Implements OldStyleCommand.

Definition at line 122 of file Command.h.

122{ return false;};// No longer supported.

◆ Apply() [2/2]

bool CommandImplementation::Apply ( const CommandContext &  context)
overridevirtual

Implements OldStyleCommand.

◆ CheckParam()

void CommandImplementation::CheckParam ( const wxString &  paramName)
protected

Definition at line 198 of file Command.cpp.

199{
200 // this macro is empty if wxWidgets is not compiled in debug mode
201 wxASSERT_MSG(mParams.find(paramName) != mParams.end(),
203 + wxT("command tried to get '")
204 + paramName
205 + wxT("' parameter, but that parameter doesn't exist in the command signature!"));
206}
wxT("CloseDown"))
@ Internal
Indicates internal failure from Audacity.
ComponentInterfaceSymbol GetSymbol() override
An instance method for getting the command name (for consistency)
Definition: Command.cpp:249

References GetSymbol(), Internal, mParams, and wxT().

Referenced by GetBool(), GetDouble(), GetLong(), and GetString().

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

◆ GetBool()

bool CommandImplementation::GetBool ( const wxString &  paramName)
protected

Definition at line 216 of file Command.cpp.

217{
218 CheckParam(paramName);
219 const wxVariant &v = mParams[paramName];
220 TypeCheck(wxT("bool"), paramName, v);
221 return v.GetBool();
222}
void CheckParam(const wxString &paramName)
Definition: Command.cpp:198
void TypeCheck(const wxString &typeName, const wxString &paramName, const wxVariant &param)
Definition: Command.cpp:184

References CheckParam(), mParams, TypeCheck(), and wxT().

Here is the call graph for this function:

◆ GetDouble()

double CommandImplementation::GetDouble ( const wxString &  paramName)
protected

Definition at line 232 of file Command.cpp.

233{
234 CheckParam(paramName);
235 const wxVariant &v = mParams[paramName];
236 TypeCheck(wxT("double"), paramName, v);
237 return v.GetDouble();
238}

References CheckParam(), mParams, TypeCheck(), and wxT().

Here is the call graph for this function:

◆ GetLong()

long CommandImplementation::GetLong ( const wxString &  paramName)
protected

Definition at line 224 of file Command.cpp.

225{
226 CheckParam(paramName);
227 const wxVariant &v = mParams[paramName];
228 TypeCheck(wxT("double"), paramName, v);
229 return (long)v.GetDouble();
230}

References CheckParam(), mParams, TypeCheck(), and wxT().

Here is the call graph for this function:

◆ GetSignature()

CommandSignature & CommandImplementation::GetSignature ( )
overridevirtual

Get the signature of the command.

Implements OldStyleCommand.

Definition at line 255 of file Command.cpp.

256{
257 return mType.GetSignature();
258}

References OldStyleCommandType::GetSignature(), and mType.

Here is the call graph for this function:

◆ GetString()

wxString CommandImplementation::GetString ( const wxString &  paramName)
protected

Definition at line 240 of file Command.cpp.

241{
242 CheckParam(paramName);
243 const wxVariant &v = mParams[paramName];
244 TypeCheck(wxT("string"), paramName, v);
245 return v.GetString();
246}

References CheckParam(), mParams, TypeCheck(), and wxT().

Referenced by BatchEvalCommand::Apply().

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

◆ GetSymbol()

ComponentInterfaceSymbol CommandImplementation::GetSymbol ( )
overridevirtual

An instance method for getting the command name (for consistency)

Get the name of the command.

Implements OldStyleCommand.

Definition at line 249 of file Command.cpp.

250{
251 return mType.GetSymbol();
252}
ComponentInterfaceSymbol GetSymbol() const override
Definition: CommandType.cpp:32

References OldStyleCommandType::GetSymbol(), and mType.

Referenced by CheckParam(), SetParameter(), and TypeCheck().

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

◆ HasParam()

bool CommandImplementation::HasParam ( const wxString &  paramName)
protected

Definition at line 208 of file Command.cpp.

209{
210 // Test for not even in map...
211 if( mParams.count(paramName) < 1)
212 return false;
213 return mSetParams[paramName];
214}

References mParams, and mSetParams.

◆ SetParameter()

bool CommandImplementation::SetParameter ( const wxString &  paramName,
const wxVariant &  paramValue 
)
overridevirtual

Attempt to one of the command's parameters to a particular value. (Note: wxVariant is reference counted)

Reimplemented from OldStyleCommand.

Definition at line 260 of file Command.cpp.

261{
262 wxASSERT(!paramValue.IsType(wxT("null")));
263 CommandContext context( mProject );
264 ParamValueMap::iterator iter = mParams.find(paramName);
265 if (iter == mParams.end())
266 {
267 // Translated format, but untranslated command name substituted into it?
268 // Perhaps these formats that don't need translating.
269 context.Error( wxString::Format(
270 _("%s is not a parameter accepted by %s"),
271 paramName, GetSymbol().Internal() ) );
272 // neglect translation for scripting ??
273 return false;
274 }
275
276 Validator &validator = mType.GetSignature().GetValidator(iter->first);
277 if (!validator.Validate(paramValue))
278 {
279 context.Error( wxString::Format(
280 _("Invalid value for parameter '%s': should be %s"),
281 paramName, validator.GetDescription() ) );
282 return false;
283 }
284 mParams[paramName] = validator.GetConverted();
285 mSetParams[ paramName ] = true;
286
287 // (debug)
288 // context.Status(wxT("Set parameter ") + paramName + wxT(" to type ") + mParams[paramName].GetType() + wxT(", value ") + mParams[paramName].MakeString());
289
290 return true;
291}
#define _(s)
Definition: Internat.h:73
CommandContext provides additional information to an 'Apply()' command. It provides the project,...
Validator & GetValidator(const wxString &paramName)
AudacityProject & mProject
Definition: Command.h:32
A Validator is an object which checks whether a wxVariant satisfies a certain criterion....
Definition: Validators.h:54
virtual wxString GetDescription() const
Definition: Validators.h:79
const wxVariant & GetConverted()
Definition: Validators.h:65
virtual bool Validate(const wxVariant &v)
Judge whether the passed value satisfies the Validator.
Definition: Validators.h:71

References _, CommandContext::Error(), Validator::GetConverted(), Validator::GetDescription(), OldStyleCommandType::GetSignature(), GetSymbol(), CommandSignature::GetValidator(), Internal, mParams, OldStyleCommand::mProject, mSetParams, mType, Validator::Validate(), and wxT().

Here is the call graph for this function:

◆ TypeCheck()

void CommandImplementation::TypeCheck ( const wxString &  typeName,
const wxString &  paramName,
const wxVariant &  param 
)
protected

Definition at line 184 of file Command.cpp.

187{
188 // this macro is empty if wxWidgets is not compiled in debug mode
189 wxASSERT_MSG(param.IsType(typeName),
191 + wxT("command tried to get '")
192 + paramName
193 + wxT("' parameter as a ")
194 + typeName
195 + wxT(", but that wasn't enforced by the command signature."));
196}

References GetSymbol(), Internal, and wxT().

Referenced by GetBool(), GetDouble(), GetLong(), and GetString().

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

◆ Valid()

bool CommandImplementation::Valid ( const wxString &  paramName,
const wxVariant &  paramValue 
)
private

Using the command signature, looks up a possible parameter value and checks whether it passes the validator.

Member Data Documentation

◆ mParams

ParamValueMap CommandImplementation::mParams
private

Definition at line 81 of file Command.h.

Referenced by CheckParam(), GetBool(), GetDouble(), GetLong(), GetString(), HasParam(), and SetParameter().

◆ mSetParams

ParamBoolMap CommandImplementation::mSetParams
private

Definition at line 82 of file Command.h.

Referenced by HasParam(), and SetParameter().

◆ mType

OldStyleCommandType& CommandImplementation::mType
private

Definition at line 80 of file Command.h.

Referenced by GetSignature(), GetSymbol(), and SetParameter().


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