Declaration of the Command structure and associated functions as used in the Command Pattern. More...
Go to the source code of this file.
Classes | |
struct | Command |
Represents an operation that can be applied to a Command_TextObject. Can hold one of two kinds of operations, one that takes no additional parameters and one that takes two additional string parameters. More... | |
Macros | |
#define | __COMMAND_OBJECTS_H__ |
Typedefs | |
typedef void(* | two_parameter_operation) (Command_TextObject *source, const char *argument1, const char *argument2) |
Alias for a function type representing an operation applied to a Command_TextObject using two parameters. | |
typedef void(* | no_parameter_operation) (Command_TextObject *source) |
Alias for a function type representing an operation applied to a Command_TextObject that uses no additional arguments. | |
typedef struct Command | Command |
Represents an operation that can be applied to a Command_TextObject. Can hold one of two kinds of operations, one that takes no additional parameters and one that takes two additional string parameters. | |
Functions | |
Command * | Command_Create_Two_Parameters (const char *commandName, Command_TextObject *receiver, two_parameter_operation operation, const char *arg1, const char *arg2) |
Create a new Command object with the given parameters, creating a command that uses two additional parameters. | |
Command * | Command_Create_No_Parameters (const char *commandName, Command_TextObject *receiver, no_parameter_operation operation) |
Create a new Command object with the given parameters, creating a command that uses no additional parameters. | |
void | Command_Destroy (Command *commandObject) |
Destroy the given command object, releasing it and any associated resources. | |
void | Command_Execute (Command *commandObject) |
Execute the given command on the Command_TextObject it knows about. | |
const char * | Command_ToString (Command *commandObject) |
Convert the given command object to a string representation. | |
Declaration of the Command structure and associated functions as used in the Command Pattern.
Definition in file Command_Command.h.
#define __COMMAND_OBJECTS_H__ |
Definition at line 8 of file Command_Command.h.
Represents an operation that can be applied to a Command_TextObject. Can hold one of two kinds of operations, one that takes no additional parameters and one that takes two additional string parameters.
In C, this is implemented with function pointers that implement the actual operations. Each command can have only one of two function pointers set at a time; this is handled in the Command_Create_Two_Parameters() and Command_Create_No_Parameters() functions.
typedef void(* no_parameter_operation) (Command_TextObject *source) |
Alias for a function type representing an operation applied to a Command_TextObject that uses no additional arguments.
source | Command_TextObject to affect |
Definition at line 29 of file Command_Command.h.
typedef void(* two_parameter_operation) (Command_TextObject *source, const char *argument1, const char *argument2) |
Alias for a function type representing an operation applied to a Command_TextObject using two parameters.
source | Command_TextObject to affect |
argument1 | First argument for the operation. |
argument2 | Second argument for the operation. |
Definition at line 22 of file Command_Command.h.
Command * Command_Create_No_Parameters | ( | const char * | commandName, |
Command_TextObject * | receiver, | ||
no_parameter_operation | operation | ||
) |
Create a new Command object with the given parameters, creating a command that uses no additional parameters.
commandName | The name of the command (for display purposes). |
receiver | The target or receiver of the command operation. |
operation | The function to call to perform the command. |
Definition at line 33 of file Command_Command.c.
References Command::commandName, Command::operation_no_parameters, and Command::receiver.
Referenced by Command_ApplyReverseCommand().
Command * Command_Create_Two_Parameters | ( | const char * | commandName, |
Command_TextObject * | receiver, | ||
two_parameter_operation | operation, | ||
const char * | arg1, | ||
const char * | arg2 | ||
) |
Create a new Command object with the given parameters, creating a command that uses two additional parameters.
commandName | The name of the command (for display purposes). |
receiver | The target or receiver of the command operation. |
operation | The function to call to perform the command. |
arg1 | The first argument to pass to the command function. |
arg2 | The second argument to pass to the command function. |
Definition at line 16 of file Command_Command.c.
References Command::argument1, Command::argument2, Command::commandName, Command::operation_two_parameters, and Command::receiver.
Referenced by Command_ApplyReplaceCommand().
void Command_Destroy | ( | Command * | commandObject | ) |
Destroy the given command object, releasing it and any associated resources.
commandObject | The Command object to be destroyed. After this function returns, the pointer is no longer valid |
Definition at line 48 of file Command_Command.c.
Referenced by Command_Undo().
void Command_Execute | ( | Command * | commandObject | ) |
Execute the given command on the Command_TextObject it knows about.
commandObject | The Command object to be executed. |
Definition at line 56 of file Command_Command.c.
References Command::argument1, Command::argument2, Command::operation_no_parameters, Command::operation_two_parameters, and Command::receiver.
Referenced by Command_Save_And_Execute(), and Command_Undo().
const char * Command_ToString | ( | Command * | commandObject | ) |
Convert the given command object to a string representation.
commandObject | The Command to be rendered as a string. |
Definition at line 74 of file Command_Command.c.
References Command::argument1, Command::argument2, Command::commandName, Command::operation_no_parameters, and Command::operation_two_parameters.
Referenced by Command_ApplyReplaceCommand(), Command_ApplyReverseCommand(), and Command_Undo().