Utility class implementing a Memento design pattern.
More...
#include <Workspace/Application/LanguageUtils/memento.h>
|
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...
|
|
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.
◆ Memento()
- Parameters
-
data | This 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.
◆ getData()
- 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()
This is a convenience function. It is equivalent to getData().isValid() and will be inlined as that anyway.