/********************************************************************** Audacity - A Digital Audio Editor Copyright 1999-2009 Audacity Team File License: wxWidgets Dan Horgan ******************************************************************//** \file Command.h \brief Contains declaration of Command base class. *//*******************************************************************/ #ifndef __COMMAND__ #define __COMMAND__ #include #include "../MemoryX.h" #include "CommandMisc.h" #include "CommandSignature.h" #include "CommandTargets.h" #include "../commands/AudacityCommand.h" class AudacityApp; class CommandContext; class CommandOutputTargets; // Abstract base class for command interface. class OldStyleCommand /* not final */ { public: OldStyleCommand() {}; virtual ~OldStyleCommand() { } virtual IdentInterfaceSymbol GetSymbol() = 0; virtual CommandSignature &GetSignature() = 0; virtual bool SetParameter(const wxString ¶mName, const wxVariant ¶mValue); virtual bool Apply()=0; virtual bool Apply(const CommandContext &context) = 0; }; using OldStyleCommandPointer = std::shared_ptr; /// Command which wraps another command /// It ISA command and HAS a command. class DecoratedCommand /* not final */ : public OldStyleCommand { protected: OldStyleCommandPointer mCommand; public: DecoratedCommand(const OldStyleCommandPointer &cmd) : mCommand(cmd) { wxASSERT(cmd != NULL); } virtual ~DecoratedCommand(); IdentInterfaceSymbol GetSymbol() override; CommandSignature &GetSignature() override; bool SetParameter(const wxString ¶mName, const wxVariant ¶mValue) override; }; // Decorator command that performs the given command and then outputs a status // message according to the result class ApplyAndSendResponse : public DecoratedCommand { public: ApplyAndSendResponse(const OldStyleCommandPointer &cmd, std::unique_ptr &target); bool Apply() override; bool Apply(const CommandContext &context) override;// Error to use this. std::unique_ptr mCtx; }; class CommandImplementation /* not final */ : public OldStyleCommand { private: OldStyleCommandType &mType; ParamValueMap mParams; ParamBoolMap mSetParams; /// Using the command signature, looks up a possible parameter value and /// checks whether it passes the validator. bool Valid(const wxString ¶mName, const wxVariant ¶mValue); protected: // Convenience methods for allowing subclasses to access parameters void TypeCheck(const wxString &typeName, const wxString ¶mName, const wxVariant ¶m); void CheckParam(const wxString ¶mName); bool HasParam( const wxString ¶mName); bool GetBool(const wxString ¶mName); long GetLong(const wxString ¶mName); double GetDouble(const wxString ¶mName); wxString GetString(const wxString ¶mName); public: /// Constructor should not be called directly; only by a factory which /// ensures name and params are set appropriately for the command. CommandImplementation(OldStyleCommandType &type); virtual ~CommandImplementation(); /// An instance method for getting the command name (for consistency) IdentInterfaceSymbol GetSymbol() override; /// Get the signature of the command CommandSignature &GetSignature() override; /// Attempt to one of the command's parameters to a particular value. /// (Note: wxVariant is reference counted) bool SetParameter(const wxString ¶mName, const wxVariant ¶mValue) override; // Subclasses should override the following: // ========================================= /// Actually carry out the command. Return true if successful and false /// otherwise. bool Apply() override { return false;};// No longer supported. bool Apply(const CommandContext &context) override; }; #endif /* End of include guard: __COMMAND__ */