19 if (commandObject != NULL)
36 if (commandObject != NULL)
58 if (commandObject != NULL && commandObject->
receiver != NULL)
76 static char commandAsString[64] = {
'\0'};
78 commandAsString[0] =
'\0';
80 const char*
string = commandAsString;
82 if (commandObject != NULL)
86 int numChars = snprintf(commandAsString,
sizeof(commandAsString),
"%s \"%s\" with \"%s\"", commandObject->
commandName, commandObject->
argument1, commandObject->
argument2);
89 int errorCode = errno;
90 printf(
" Error(%d)! Failed to format command '%s' as a string: %s\n", errorCode, commandObject->
commandName, strerror(errorCode));
98 if (
string[0] ==
'\0')
100 string =
"<NO COMMAND>";
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 par...
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 pa...
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.
void Command_Destroy(Command *commandObject)
Destroy the given command object, releasing it and any associated resources.
Declaration of the Command structure and associated functions as used in the Command Pattern.
void(* no_parameter_operation)(Command_TextObject *source)
Alias for a function type representing an operation applied to a Command_TextObject that uses no addi...
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 paramet...
Container for a string. Need to use a structure to keep the starting text and the current text togeth...
Represents an operation that can be applied to a Command_TextObject. Can hold one of two kinds of ope...
two_parameter_operation operation_two_parameters
Two parameter operation to apply to the receiver.
const char * argument1
The first argument to a two parameter operation.
const char * commandName
Easy-to-read command name.
no_parameter_operation operation_no_parameters
No parameter operation to apply to the receiver.
Command_TextObject * receiver
The receiver of the command.
const char * argument2
The second argument to a two parameter operation.