/
StackFiller.h
61 lines (51 loc) · 1.48 KB
/
StackFiller.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#pragma once
#include "iundo.h"
#include "Stack.h"
namespace undo
{
/**
* greebo: This class acts as some sort of "duplication guard".
* Undoable objects like brushes and patches will save their state
* by calling the save() method - to ensure Undoables don't submit
* their state more than once, the associated UndoStack reference
* is cleared after submission in the save() routine. Further calls
* to save() will not have any effect. The stack reference is set
* by the UndoSystem on start of an undo or redo operation.
*/
class UndoStackFiller final :
public IUndoStateSaver
{
private:
IUndoSystem& _owner;
UndoStack* _stack;
public:
UndoStackFiller(IUndoSystem& owner) :
_owner(owner),
_stack(nullptr)
{}
// Noncopyable
UndoStackFiller(const UndoStackFiller& other) = delete;
UndoStackFiller& operator=(const UndoStackFiller& other) = delete;
void save(IUndoable& undoable)
{
if (_stack != nullptr)
{
// Export the Undoable's memento
_stack->save(undoable);
// Make sure the stack is dissociated after saving
// to make sure further save() calls don't have any effect
_stack = nullptr;
}
}
IUndoSystem& getUndoSystem() override
{
return _owner;
}
// Assign the stack of this class. This usually happens when starting
// an undo or redo operation.
void setStack(UndoStack* stack)
{
_stack = stack;
}
};
} // namespace undo