Audacity  2.2.2
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:
OldStyleCommand BatchEvalCommand

Public Member Functions

 CommandImplementation (OldStyleCommandType &type)
 
virtual ~CommandImplementation ()
 
IdentInterfaceSymbol GetSymbol () override
 An instance method for getting the command name (for consistency) More...
 
CommandSignatureGetSignature () 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 ()
 
virtual ~OldStyleCommand ()
 

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

OldStyleCommandTypemType
 
ParamValueMap mParams
 
ParamBoolMap mSetParams
 

Detailed Description

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

Definition at line 77 of file Command.h.

Constructor & Destructor Documentation

CommandImplementation::CommandImplementation ( 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 173 of file Command.cpp.

174 : mType(type),
175  mParams(type.GetSignature().GetDefaults()),
176  mSetParams()
177 {
178 }
ParamValueMap mParams
Definition: Command.h:81
ParamValueMap GetDefaults() const
ParamBoolMap mSetParams
Definition: Command.h:82
CommandSignature & GetSignature()
Definition: CommandType.cpp:41
OldStyleCommandType & mType
Definition: Command.h:80
CommandImplementation::~CommandImplementation ( )
virtual

Definition at line 180 of file Command.cpp.

181 {
182 }

Member Function Documentation

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.
bool CommandImplementation::Apply ( const CommandContext context)
overridevirtual

Implements OldStyleCommand.

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

Definition at line 198 of file Command.cpp.

References GetSymbol(), IdentInterfaceSymbol::Internal(), and mParams.

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

199 {
200  // this macro is empty if wxWidgets is not compiled in debug mode
201  wxASSERT_MSG(mParams.find(paramName) != mParams.end(),
202  GetSymbol().Internal()
203  + wxT("command tried to get '")
204  + paramName
205  + wxT("' parameter, but that parameter doesn't exist in the command signature!"));
206 }
ParamValueMap mParams
Definition: Command.h:81
IdentInterfaceSymbol GetSymbol() override
An instance method for getting the command name (for consistency)
Definition: Command.cpp:249
const wxString & Internal() const
bool CommandImplementation::GetBool ( const wxString &  paramName)
protected

Definition at line 216 of file Command.cpp.

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

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

Definition at line 232 of file Command.cpp.

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

233 {
234  CheckParam(paramName);
235  const wxVariant &v = mParams[paramName];
236  TypeCheck(wxT("double"), paramName, v);
237  return v.GetDouble();
238 }
ParamValueMap mParams
Definition: Command.h:81
void TypeCheck(const wxString &typeName, const wxString &paramName, const wxVariant &param)
Definition: Command.cpp:184
void CheckParam(const wxString &paramName)
Definition: Command.cpp:198
long CommandImplementation::GetLong ( const wxString &  paramName)
protected

Definition at line 224 of file Command.cpp.

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

225 {
226  CheckParam(paramName);
227  const wxVariant &v = mParams[paramName];
228  TypeCheck(wxT("double"), paramName, v);
229  return (long)v.GetDouble();
230 }
ParamValueMap mParams
Definition: Command.h:81
void TypeCheck(const wxString &typeName, const wxString &paramName, const wxVariant &param)
Definition: Command.cpp:184
void CheckParam(const wxString &paramName)
Definition: Command.cpp:198
CommandSignature & CommandImplementation::GetSignature ( )
overridevirtual

Get the signature of the command.

Implements OldStyleCommand.

Definition at line 255 of file Command.cpp.

References OldStyleCommandType::GetSignature(), and mType.

256 {
257  return mType.GetSignature();
258 }
CommandSignature & GetSignature()
Definition: CommandType.cpp:41
OldStyleCommandType & mType
Definition: Command.h:80
wxString CommandImplementation::GetString ( const wxString &  paramName)
protected

Definition at line 240 of file Command.cpp.

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

Referenced by BatchEvalCommand::Apply().

241 {
242  CheckParam(paramName);
243  const wxVariant &v = mParams[paramName];
244  TypeCheck(wxT("string"), paramName, v);
245  return v.GetString();
246 }
ParamValueMap mParams
Definition: Command.h:81
void TypeCheck(const wxString &typeName, const wxString &paramName, const wxVariant &param)
Definition: Command.cpp:184
void CheckParam(const wxString &paramName)
Definition: Command.cpp:198
IdentInterfaceSymbol 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.

References OldStyleCommandType::GetSymbol(), and mType.

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

250 {
251  return mType.GetSymbol();
252 }
OldStyleCommandType & mType
Definition: Command.h:80
IdentInterfaceSymbol GetSymbol() override
Definition: CommandType.cpp:34
bool CommandImplementation::HasParam ( const wxString &  paramName)
protected

Definition at line 208 of file Command.cpp.

References mParams, and mSetParams.

209 {
210  // Test for not even in map...
211  if( mParams.count(paramName) < 1)
212  return false;
213  return mSetParams[paramName];
214 }
ParamValueMap mParams
Definition: Command.h:81
ParamBoolMap mSetParams
Definition: Command.h:82
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.

References _(), GetActiveProject(), Validator::GetConverted(), Validator::GetDescription(), OldStyleCommandType::GetSignature(), GetSymbol(), CommandSignature::GetValidator(), mParams, mSetParams, mType, and Validator::Validate().

261 {
262  wxASSERT(!paramValue.IsType(wxT("null")));
263  CommandContext context( * GetActiveProject());
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  return false;
273  }
274 
275  Validator &validator = mType.GetSignature().GetValidator(iter->first);
276  if (!validator.Validate(paramValue))
277  {
278  context.Error( wxString::Format(
279  _("Invalid value for parameter '%s': should be %s"),
280  paramName, validator.GetDescription() ) );
281  return false;
282  }
283  mParams[paramName] = validator.GetConverted();
284  mSetParams[ paramName ] = true;
285 
286  // (debug)
287  // context.Status(wxT("Set parameter ") + paramName + wxT(" to type ") + mParams[paramName].GetType() + wxT(", value ") + mParams[paramName].MakeString());
288 
289  return true;
290 }
ParamValueMap mParams
Definition: Command.h:81
const wxVariant & GetConverted()
Definition: Validators.h:60
IdentInterfaceSymbol GetSymbol() override
An instance method for getting the command name (for consistency)
Definition: Command.cpp:249
CommandContext provides addiitonal information to an 'Apply()' command. It provides the project...
ParamBoolMap mSetParams
Definition: Command.h:82
virtual wxString GetDescription() const
Definition: Validators.h:74
CommandSignature & GetSignature()
Definition: CommandType.cpp:41
OldStyleCommandType & mType
Definition: Command.h:80
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
virtual bool Validate(const wxVariant &v)
Judge whether the passed value satisfies the Validator.
Definition: Validators.h:66
AUDACITY_DLL_API AudacityProject * GetActiveProject()
Definition: Project.cpp:308
Validator & GetValidator(const wxString &paramName)
A Validator is an object which checks whether a wxVariant satisfies a certain criterion. This is a base validator which allows anything.
Definition: Validators.h:48
void CommandImplementation::TypeCheck ( const wxString &  typeName,
const wxString &  paramName,
const wxVariant &  param 
)
protected

Definition at line 184 of file Command.cpp.

References GetSymbol(), and IdentInterfaceSymbol::Internal().

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

187 {
188  // this macro is empty if wxWidgets is not compiled in debug mode
189  wxASSERT_MSG(param.IsType(typeName),
190  GetSymbol().Internal()
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 }
IdentInterfaceSymbol GetSymbol() override
An instance method for getting the command name (for consistency)
Definition: Command.cpp:249
const wxString & Internal() const
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

ParamValueMap CommandImplementation::mParams
private

Definition at line 81 of file Command.h.

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

ParamBoolMap CommandImplementation::mSetParams
private

Definition at line 82 of file Command.h.

Referenced by HasParam(), and SetParameter().

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: