Design Pattern Examples
Overview of object-oriented design patterns
Memento_TextObject.h File Reference

Declaration of the Memento_TextObject structure and support functions, Memento_TextObject_Create(), Memento_TextObject_Destroy(), Memento_TextObject_GetText(), Memento_TextObject_SetText(), and Memento_TextObject_ToString(), as used in the Memento Pattern. More...

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  Memento_TextObject
 Container for a string. More...
 

Macros

#define __MEMENTO_TEXTOBJECT_H__
 

Functions

Memento_TextObjectMemento_TextObject_Create (const char *text)
 Create a new instance of the Memento_TextObject structure and initialize it with the given text.
 
void Memento_TextObject_Destroy (Memento_TextObject *textObject)
 Destroy the given Memento_TextObject object and release any used memory. After this function returns, the pointer is no longer valid.
 
char * Memento_TextObject_GetText (Memento_TextObject *textObject)
 Retrieve a pointer to the text contained within the Memento_TextObject. The text can be altered through this pointer or can be replaced entirely using the Memento_TextObject_SetText() function.
 
void Memento_TextObject_SetText (Memento_TextObject *textObject, const char *newText)
 Replace the existing text in the Memento_TextObject object with the given text.
 
const char * Memento_TextObject_ToString (Memento_TextObject *textObject)
 Return a string representation of the Memento_TextObject. In this case, it is just the underlying text.
 

Detailed Description

Macro Definition Documentation

◆ __MEMENTO_TEXTOBJECT_H__

#define __MEMENTO_TEXTOBJECT_H__

Definition at line 11 of file Memento_TextObject.h.

Function Documentation

◆ Memento_TextObject_Create()

Memento_TextObject * Memento_TextObject_Create ( const char *  text)

Create a new instance of the Memento_TextObject structure and initialize it with the given text.

Parameters
textThe text with which to initialize the Memento_TextObject. This is duplicated.
Returns
Returns a pointer to a new Memento_TextObject instance if successful; otherwise, returns NULL (out of memory condition).

Definition at line 21 of file Memento_TextObject.c.

References STRDUP, and Memento_TextObject::text.

Referenced by Memento_Exercise().

◆ Memento_TextObject_Destroy()

void Memento_TextObject_Destroy ( Memento_TextObject textObject)

Destroy the given Memento_TextObject object and release any used memory. After this function returns, the pointer is no longer valid.

Parameters
textObjectThe Memento_TextObject to destroy.

Definition at line 50 of file Memento_TextObject.c.

References Memento_TextObject::text.

Referenced by Memento_Exercise().

◆ Memento_TextObject_GetText()

char * Memento_TextObject_GetText ( Memento_TextObject textObject)

Retrieve a pointer to the text contained within the Memento_TextObject. The text can be altered through this pointer or can be replaced entirely using the Memento_TextObject_SetText() function.

Parameters
textObjectThe Memento_TextObject object from which to get the text.
Returns
Returns the pointer to the text as stored in the Memento_TextObject.

Definition at line 62 of file Memento_TextObject.c.

References Memento_TextObject::text.

Referenced by Memento_Operation_Replace(), Memento_Operation_Reverse(), and Memento_SaveForUndo().

◆ Memento_TextObject_SetText()

void Memento_TextObject_SetText ( Memento_TextObject textObject,
const char *  newText 
)

Replace the existing text in the Memento_TextObject object with the given text.

Parameters
textObjectThe Memento_TextObject from which to get the text.
newTextThe new text to set the Memento_TextObject to. This string is duplicated.

Definition at line 77 of file Memento_TextObject.c.

References STRDUP, and Memento_TextObject::text.

Referenced by Memento_Operation_Replace(), and Memento_Undo().

◆ Memento_TextObject_ToString()

const char * Memento_TextObject_ToString ( Memento_TextObject textObject)

Return a string representation of the Memento_TextObject. In this case, it is just the underlying text.

Parameters
textObjectThe Memento_TextObject from which to create a string.
Returns
Returns a pointer to a string representation of the contents of the Memento_TextObject.

Definition at line 94 of file Memento_TextObject.c.

References Memento_TextObject::text.

Referenced by Memento_ApplyReplaceOperation(), Memento_ApplyReverseOperation(), Memento_Exercise(), and Memento_Undo().