Represents the processor that translates the move list into a list of MoveCommand objects then either displays them or executes them. More...
#include <Null_Object.h>
Public Member Functions | |
void | ExecuteMoveList (std::string moveList) |
Parse and execute the given list of move commands, where each command is represents by a single character. | |
void | ShowMoveList (std::string moveList) |
Parse and display the given list of move commands, where each command is represents by a single character. | |
Private Member Functions | |
std::vector< MoveCommand::shared_ptr_t > | _ParseMoves (std::string moveList) |
Helper method to convert a list of single letter commands into a list of MoveCommand objects. | |
void | _ExecuteMoves (const std::vector< MoveCommand::shared_ptr_t > &commands) |
Helper method to execute all the given commands. | |
void | _ShowMoves (const std::vector< MoveCommand::shared_ptr_t > &commands) |
Display the command character and name of the command for each command in the given list of commands. | |
Represents the processor that translates the move list into a list of MoveCommand objects then either displays them or executes them.
This classes uses a parser to convert the single letter characters in a string into a list of actions (instances of the MoveCommand class). This list of actions is then executed to perform the operations.
This process of executing the list of operations is an example of the Command Pattern. This is also an example of the Interpreter Pattern, where the actions are the tokens to be interpreted.
Definition at line 273 of file Null_Object.h.
|
inlineprivate |
Helper method to execute all the given commands.
commands | A list of MoveCommand objects to "execute". |
In this implementation, the MoveCommand object prints the command as "<move xxx> " on the current line. When all commands have been printed, a new line is printed to move to the next line. The "Do Nothing" command doesn't print anything, leaving only the empty <>.
Definition at line 339 of file Null_Object.h.
Referenced by MoveProcessor::ExecuteMoveList().
|
inlineprivate |
Helper method to convert a list of single letter commands into a list of MoveCommand objects.
This method recognizes 'L', 'R', 'U', and 'D' (case-insensitive). All other characters default to the "Do Nothing" (Null Object) command.
moveList | A string containing a list of single letter commands to be parsed. |
Definition at line 289 of file Null_Object.h.
Referenced by MoveProcessor::ExecuteMoveList(), and MoveProcessor::ShowMoveList().
|
inlineprivate |
Display the command character and name of the command for each command in the given list of commands.
commands | The list of MoveCommand objects to display. |
Definition at line 356 of file Null_Object.h.
Referenced by MoveProcessor::ShowMoveList().
|
inline |
Parse and execute the given list of move commands, where each command is represents by a single character.
Recognizes 'U', 'D', 'L', and 'R' (case-insensitive). All other characters are assigned a "Do Nothing" (Null Object) command.
moveList | A string of characters to parse and execute. |
Definition at line 376 of file Null_Object.h.
References MoveProcessor::_ExecuteMoves(), and MoveProcessor::_ParseMoves().
Referenced by DesignPatternExamples_cpp::NullObject_Exercise().
|
inline |
Parse and display the given list of move commands, where each command is represents by a single character.
Recognizes 'U', 'D', 'L', and 'R' (case-insensitive). All other characters are assigned a "Do Nothing" (Null Object) command.
moveList | A string of characters to parse and display. |
Definition at line 391 of file Null_Object.h.
References MoveProcessor::_ParseMoves(), and MoveProcessor::_ShowMoves().
Referenced by DesignPatternExamples_cpp::NullObject_Exercise().