-
Notifications
You must be signed in to change notification settings - Fork 16
/
undo_state.h
54 lines (44 loc) · 1.14 KB
/
undo_state.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
// Undo Library
// Copyright (C) 2015-2017 David Capello
//
// This file is released under the terms of the MIT license.
// Read LICENSE.txt for more information.
#ifndef UNDO_STATE_H_INCLUDED
#define UNDO_STATE_H_INCLUDED
#pragma once
#include "undo_command.h"
namespace undo {
class UndoCommand;
class UndoHistory;
// Represents a state that can be undone. If we are in this state,
// is because the command was already executed.
class UndoState {
friend class UndoHistory;
public:
UndoState(UndoCommand* cmd)
: m_prev(nullptr)
, m_next(nullptr)
, m_parent(nullptr)
, m_cmd(cmd) {
}
~UndoState() {
if (m_cmd)
m_cmd->dispose();
#ifdef _DEBUG
m_prev = nullptr;
m_next = nullptr;
m_parent = nullptr;
m_cmd = nullptr;
#endif
}
UndoState* prev() const { return m_prev; }
UndoState* next() const { return m_next; }
UndoCommand* cmd() const { return m_cmd; }
private:
UndoState* m_prev;
UndoState* m_next;
UndoState* m_parent; // Parent state, after we undo
UndoCommand* m_cmd;
};
} // namespace undo
#endif // STATE_H_INCLUDED