Design Pattern Examples
Overview of object-oriented design patterns
Memento_TextObject Class Reference

Container for a string. Need to use a class that allows the text to be changed while the container (this class) remains constant. This way, operations can be applied to the text and the container's contents change but not the container (strings are immutable in C#; this dances around that problem). More...

#include <Memento.h>

Collaboration diagram for Memento_TextObject:
Collaboration graph

Classes

class  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...
 

Public Member Functions

 Memento_TextObject (std::string text)
 Constructs a text object with an initial string.
 
std::string Text ()
 Gets the text in this TextObject.
 
void SetText (const std::string &value)
 Sets the text in this TextObject.
 
IMemento::shared_ptr_t GetMemento (std::string operationName)
 Returns an IMemento object containing a snapshot of the text stored in this class instance.
 
void RestoreMemento (IMemento::shared_ptr_t memento)
 Sets the text in this class instance to the snapshot stored in the given IMemento object (which is assumed to be from this class).
 
std::string ToString ()
 Converts the Memento_TextObject to a string (makes it easier to use the class in string formatting).
 

Private Attributes

std::string _text
 The text that can change in this Memento_TextObject class.
 

Detailed Description

Container for a string. Need to use a class that allows the text to be changed while the container (this class) remains constant. This way, operations can be applied to the text and the container's contents change but not the container (strings are immutable in C#; this dances around that problem).

Definition at line 53 of file Memento.h.

Constructor & Destructor Documentation

◆ Memento_TextObject()

Memento_TextObject ( std::string  text)
inline

Constructs a text object with an initial string.

Parameters
textThe initial string for the text object.

Definition at line 134 of file Memento.h.

References Memento_TextObject::_text.

Member Function Documentation

◆ GetMemento()

IMemento::shared_ptr_t GetMemento ( std::string  operationName)
inline

Returns an IMemento object containing a snapshot of the text stored in this class instance.

Definition at line 159 of file Memento.h.

References Memento_TextObject::_text.

◆ RestoreMemento()

void RestoreMemento ( IMemento::shared_ptr_t  memento)
inline

Sets the text in this class instance to the snapshot stored in the given IMemento object (which is assumed to be from this class).

Parameters
mementoThe IMemento object to restore to.

Definition at line 170 of file Memento.h.

References Memento_TextObject::_text, and Memento_TextObject::Text().

◆ SetText()

void SetText ( const std::string &  value)
inline

Sets the text in this TextObject.

Definition at line 150 of file Memento.h.

References Memento_TextObject::_text.

◆ Text()

std::string Text ( )
inline

Gets the text in this TextObject.

Definition at line 142 of file Memento.h.

References Memento_TextObject::_text.

Referenced by Memento_TextObject::RestoreMemento().

◆ ToString()

std::string ToString ( )
inline

Converts the Memento_TextObject to a string (makes it easier to use the class in string formatting).

Returns
Returns the text stored in the text object.

Definition at line 184 of file Memento.h.

References Memento_TextObject::_text.

Referenced by DesignPatternExamples_cpp::Memento_Exercise().

Member Data Documentation

◆ _text


The documentation for this class was generated from the following file: