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

Implementation of the Memento structure's support functions, Memento_Create() and Memento_Destroy(), as used in the Memento Pattern. More...

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

Go to the source code of this file.

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

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

Definition in file Memento_Memento.c.

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