Workspace 6.21.5
Classes | Public Member Functions | List of all members
Memento Class Reference

Utility class implementing a Memento design pattern. More...

#include <Workspace/Application/LanguageUtils/memento.h>

Classes

class  Data
 Base class for all Memento data subclasses. More...
 
class  NoData
 Trivial class for when no memento data is needed or when memento construction fails. More...
 

Public Member Functions

 Memento (Data &data)
 
DatagetData ()
 
bool isValid () const
 

Detailed Description

The memento reference counts its data so that clients can simply copy-construct a Memento as a local stack object. Mementos can be safely copied. When the last copy is deleted - typically when the last Memento for it goes out of scope - the data will be automatically deleted. Thus, the lifetime of mementos are fully managed by Memento.

Constructor & Destructor Documentation

◆ Memento()

Memento ( Data data)
inline
Parameters
dataThis is the internal data that the memento is holding. It is only assumed to be useful to the caller and will be passed back to the caller through getData().

When the last Memento referencing data is destroyed, the data will be destroyed too. This is one of the main advantages of using the Memento class because it effectively means that it manages the lifetime of the data for you. As long as at least one Memento is holding data, then data will not be deleted.

Member Function Documentation

◆ getData()

Data & getData ( )
inline
Returns
The data passed to the memento's constructor. It is assumed that the caller can safely cast this to the correct data type because getData() should only be called by the same object that created the memento in the first place.

◆ isValid()

bool isValid ( ) const
inline

This is a convenience function. It is equivalent to getData().isValid() and will be inlined as that anyway.