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

Declaration of the Memento structure and support functions, Memento_Create() and Memento_Destroy(), 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
 Represents a single memento (snapshot) of the text state before an operation is applied. The operation becomes the name of the memento for display purposes. More...
 

Macros

#define __MEMENTO_MEMENTO_H__
 

Functions

MementoMemento_Create (const char *text, const char *name)
 Create a new instance of the Memento structure, initialized to the given text and name.
 
void Memento_Destroy (Memento *memento)
 Destroy an existing instance of the Memento structure. After this function returns, the pointer to the memento is no longer valid.
 

Detailed Description

Declaration of the Memento structure and support functions, Memento_Create() and Memento_Destroy(), as used in the Memento Pattern.

Definition in file Memento_Memento.h.

Macro Definition Documentation

◆ __MEMENTO_MEMENTO_H__

#define __MEMENTO_MEMENTO_H__

Definition at line 9 of file Memento_Memento.h.

Function Documentation

◆ Memento_Create()

Memento * Memento_Create ( const char *  text,
const char *  name 
)

Create a new instance of the Memento structure, initialized to the given text and name.

Parameters
textThe text to assign the memento. This is the snapshot to be remembered. This is duplicated in the Memento object.
nameThe operation name used to on the parent text object. This is duplicated in the Memento object.
Returns
Returns a pointer to a new Memento object if successful, otherwise, returns NULL.

Definition at line 19 of file Memento_Memento.c.

References Memento::name, STRDUP, and Memento::text.

Referenced by Memento_SaveForUndo().

◆ Memento_Destroy()

void Memento_Destroy ( Memento memento)

Destroy an existing instance of the Memento structure. After this function returns, the pointer to the memento is no longer valid.

Parameters
mementoThe Memento object to destroy.

Definition at line 61 of file Memento_Memento.c.

References Memento::name, and Memento::text.

Referenced by Memento_Undo().