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

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

#include <memory.h>
#include <stdlib.h>
#include <string.h>
#include "helpers/strdup.h"
#include "Command_TextObject.h"
Include dependency graph for Command_TextObject.c:

Go to the source code of this file.

Functions

bool Command_TextObject_Initialize (Command_TextObject *textObject, const char *startingText)
 Initialize a Command_TextObject with the specified text.
 
void Command_TextObject_Clear (Command_TextObject *textObject)
 Clear the contents of the specified Command_TextObject, releasing any allocated resources associated with the Command_TextObject.
 
void Command_TextObject_Reset (Command_TextObject *textObject)
 Resets the Command_TextObject to the starting string.
 
char * Command_TextObject_GetText (Command_TextObject *textObject)
 Gets the text in the specified Command_TextObject.
 
void Command_TextObject_SetText (Command_TextObject *textObject, const char *newText)
 Sets the text in the specified Command_TextObject.
 
const char * Command_TextObject_ToString (Command_TextObject *textObject)
 Converts the Command_TextObject to a string (basically, returns the current text from the Command_TextObject).
 

Detailed Description

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

Definition in file Command_TextObject.c.

Function Documentation

◆ Command_TextObject_Clear()

void Command_TextObject_Clear ( Command_TextObject textObject)

Clear the contents of the specified Command_TextObject, releasing any allocated resources associated with the Command_TextObject.

Parameters
textObjectA Command_TextObject whose contents are to be destroyed.

Definition at line 35 of file Command_TextObject.c.

References Command_TextObject::startingText, and Command_TextObject::text.

Referenced by Command_Exercise(), and Command_TextObject_Initialize().

◆ Command_TextObject_GetText()

char * Command_TextObject_GetText ( Command_TextObject textObject)

Gets the text in the specified Command_TextObject.

Parameters
textObjectThe Command_TextObject from which to get the text.
Returns
Returns a pointer to the mutable text in the Command_TextObject.

Definition at line 60 of file Command_TextObject.c.

References Command_TextObject::text.

Referenced by Command_Operation_Replace(), and Command_Operation_Reverse().

◆ Command_TextObject_Initialize()

bool Command_TextObject_Initialize ( Command_TextObject textObject,
const char *  startingText 
)

Initialize a Command_TextObject with the specified text.

Parameters
textObjectA Command_TextObject to initialize with the given text.
startingTextThe text with which to initialize the object. String is not duplicated.
Returns
Returns true if the initialization was successful; otherwise, returns false (a null pointer was passed in or a out of memory condition occurred.

Definition at line 18 of file Command_TextObject.c.

References Command_TextObject_Clear(), Command_TextObject::startingText, STRDUP, and Command_TextObject::text.

Referenced by Command_Exercise().

◆ Command_TextObject_Reset()

void Command_TextObject_Reset ( Command_TextObject textObject)

Resets the Command_TextObject to the starting string.

Parameters
textObjectThe Command_TextObject to reset.

Definition at line 48 of file Command_TextObject.c.

References Command_TextObject::startingText, STRDUP, and Command_TextObject::text.

Referenced by Command_Undo().

◆ Command_TextObject_SetText()

void Command_TextObject_SetText ( Command_TextObject textObject,
const char *  newText 
)

Sets the text in the specified Command_TextObject.

Parameters
textObjectThe Command_TextObject in which to change the mutable text.
newTextThe text to change to.

Definition at line 75 of file Command_TextObject.c.

References STRDUP, and Command_TextObject::text.

Referenced by Command_Operation_Replace().

◆ Command_TextObject_ToString()

const char * Command_TextObject_ToString ( Command_TextObject textObject)

Converts the Command_TextObject to a string (basically, returns the current text from the Command_TextObject).

Parameters
textObjectThe Command_TextObject from which to get the current text.
Returns
Returns a pointer to the current text. Treat as read-only.

Definition at line 87 of file Command_TextObject.c.

References Command_TextObject::text.

Referenced by Command_ApplyReplaceCommand(), Command_ApplyReverseCommand(), Command_Exercise(), and Command_Undo().