Design Pattern Examples
Overview of object-oriented design patterns
Command_Command.h
Go to the documentation of this file.
1
5
6#pragma once
7#ifndef __COMMAND_OBJECTS_H__
8#define __COMMAND_OBJECTS_H__
9
10#include <stdlib.h>
11
12#include "Command_TextObject.h"
13
14
22typedef void (*two_parameter_operation)(Command_TextObject* source, const char* argument1, const char* argument2);
23
30
31
44typedef struct Command
45{
47 const char* commandName;
50 const char* argument1;
51 const char* argument2;
52
54
55
67Command* Command_Create_Two_Parameters(const char* commandName, Command_TextObject* receiver, two_parameter_operation operation, const char* arg1, const char* arg2);
68
78Command* Command_Create_No_Parameters(const char* commandName, Command_TextObject* receiver, no_parameter_operation operation);
79
85void Command_Destroy(Command* commandObject);
86
91void Command_Execute(Command* commandObject);
92
98const char* Command_ToString(Command* commandObject);
99
100
101#endif // __COMMAND_OBJECTS_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 par...
void(* no_parameter_operation)(Command_TextObject *source)
Alias for a function type representing an operation applied to a Command_TextObject that uses no addi...
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(* 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...
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_TextObject structure and associated functions as used in the Command Patte...
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.