Design Pattern Examples
Overview of object-oriented design patterns
Command_Command.c File Reference

Implementation of the Command structure and associated functions as used in the Command Pattern. More...

#include <errno.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "Command_Command.h"
Include dependency graph for Command_Command.c:

Go to the source code of this file.

Functions

CommandCommand_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.
 
CommandCommand_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.
 

Detailed Description

Implementation of the Command structure and associated functions as used in the Command Pattern.

Definition in file Command_Command.c.

Function Documentation

◆ Command_Create_No_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.

Parameters
commandNameThe name of the command (for display purposes).
receiverThe target or receiver of the command operation.
operationThe function to call to perform the command.
Returns
Returns a new Command object if successful; returns NULL if out of memory

Definition at line 33 of file Command_Command.c.

References Command::commandName, Command::operation_no_parameters, and Command::receiver.

Referenced by Command_ApplyReverseCommand().

◆ Command_Create_Two_Parameters()

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.

Parameters
commandNameThe name of the command (for display purposes).
receiverThe target or receiver of the command operation.
operationThe function to call to perform the command.
arg1The first argument to pass to the command function.
arg2The second argument to pass to the command function.
Returns
Returns a new Command object if successful; returns NULL if out of memory

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().

◆ Command_Destroy()

void Command_Destroy ( Command commandObject)

Destroy the given command object, releasing it and any associated resources.

Parameters
commandObjectThe 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().

◆ Command_Execute()

void Command_Execute ( Command commandObject)

Execute the given command on the Command_TextObject it knows about.

Parameters
commandObjectThe 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().

◆ Command_ToString()

const char * Command_ToString ( Command commandObject)

Convert the given command object to a string representation.

Parameters
commandObjectThe Command to be rendered as a string.
Returns
A string containing the representation of the command.

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().