Command Class Reference

Back to the index.

Public Member Functions | Static Public Member Functions | List of all members
Command Class Referenceabstract

A Command is a named function, executed by the CommandInterpreter. More...

#include <Command.h>

Inheritance diagram for Command:
ReferenceCountable UnitTestable AddComponentCommand BackwardStepCommand CloseCommand ContinueBackwardsCommand ContinueCommand CopyComponentCommand HelpCommand ListComponentsCommand LoadCommand MoveComponentCommand PauseCommand QuitCommand RemoveComponentCommand ResetCommand SaveCommand StatusCommand StepCommand VersionCommand

Public Member Functions

 Command (const string &name, const string &argumentFormat)
 Constructs a Command. More...
 
virtual ~Command ()=0
 
const string & GetCommandName () const
 Gets the name of the command. More...
 
const string & GetArgumentFormat () const
 Gets the argument format for the command. More...
 
virtual bool Execute (GXemul &gxemul, const vector< string > &arguments)=0
 Executes the command on a given GXemul instance. More...
 
virtual bool MayBeReexecutedWithoutArgs () const
 Returns whether the command can be quickly re-executed using an empty command line. More...
 
virtual string GetShortDescription () const =0
 Returns a short (one-line) description of the command. More...
 
virtual string GetLongDescription () const =0
 Returns a long description/help message for the command. More...
 
- Public Member Functions inherited from ReferenceCountable
 ReferenceCountable ()
 Default constructor, which initializes the reference count to zero. More...
 
 ~ReferenceCountable ()
 

Static Public Member Functions

static void RunUnitTests (int &nSucceeded, int &nFailures)
 
- Static Public Member Functions inherited from UnitTestable
static void RunUnitTests (int &nSucceeded, int &nFailures)
 Runs unit test cases. More...
 

Detailed Description

A Command is a named function, executed by the CommandInterpreter.

To implement a new Command, simply create the corresponding .h file in src/include/commands/ and a .cc file in src/main/commands/ (e.g. by copying from a similar command), and add the name of the command's .o file to src/main/commands/Makefile.skel. (The configure script takes care of adding all commands to the CommandInterpreter, so there is no need to manually "register" the command anywhere.)

Definition at line 48 of file Command.h.

Constructor & Destructor Documentation

◆ Command()

Command::Command ( const string &  name,
const string &  argumentFormat 
)

Constructs a Command.

Parameters
nameThe command's name. This should be a unique lower-case string, consisting only of letters a-z.
argumentFormatA string describing the command's arguments. May be empty, if the command takes no arguments.

Definition at line 32 of file Command.cc.

◆ ~Command()

Command::~Command ( )
pure virtual

Definition at line 39 of file Command.cc.

Member Function Documentation

◆ Execute()

virtual bool Command::Execute ( GXemul gxemul,
const vector< string > &  arguments 
)
pure virtual

Executes the command on a given GXemul instance.

Parameters
gxemulA reference to the GXemul instance.
argumentsA vector of zero or more string arguments.
Returns
true if the command succeeded, false if it failed.

Implemented in ResetCommand, StatusCommand, AddComponentCommand, ContinueCommand, CopyComponentCommand, LoadCommand, MoveComponentCommand, PauseCommand, RemoveComponentCommand, BackwardStepCommand, CloseCommand, ContinueBackwardsCommand, HelpCommand, ListComponentsCommand, QuitCommand, SaveCommand, StepCommand, and VersionCommand.

◆ GetArgumentFormat()

const string& Command::GetArgumentFormat ( ) const
inline

Gets the argument format for the command.

Returns
The argument format for the command.

Definition at line 80 of file Command.h.

Referenced by HelpCommand::Execute().

◆ GetCommandName()

const string& Command::GetCommandName ( ) const
inline

Gets the name of the command.

Returns
The name of the command.

Definition at line 70 of file Command.h.

Referenced by CommandInterpreter::AddCommand(), and HelpCommand::Execute().

◆ GetLongDescription()

virtual string Command::GetLongDescription ( ) const
pure virtual

◆ GetShortDescription()

virtual string Command::GetShortDescription ( ) const
pure virtual

◆ MayBeReexecutedWithoutArgs()

virtual bool Command::MayBeReexecutedWithoutArgs ( ) const
inlinevirtual

Returns whether the command can be quickly re-executed using an empty command line.

Typical examples are: step, cpu disassembly, and memory dump, where re-executing the command without arguments is very natural.

Returns
true if the command may be re-executed without arguments, false otherwise.

Reimplemented in BackwardStepCommand, and StepCommand.

Definition at line 105 of file Command.h.

◆ RunUnitTests()

static void Command::RunUnitTests ( int &  nSucceeded,
int &  nFailures 
)
static

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

Generated on Tue Aug 25 2020 19:25:06 for GXemul by doxygen 1.8.18