historyState.h Source File

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
historyState.h
Go to the documentation of this file.
1 /* historyState.h
2 */
3 #ifndef _HISTORYSTATE_H
4 #define _HISTORYSTATE_H
5 #include "osl/state/numEffectState.h"
6 #include "osl/stl/vector.h"
7 namespace osl
8 {
9 namespace state
10 {
11 class HistoryState
12 #if OSL_WORDSIZE == 32
13 : public misc::Align16New
14 #endif
15 {
16 NumEffectState initial_state;
17 mutable NumEffectState current;
18 mutable bool dirty;
19 vector<Move> moves;
20 public:
21 HistoryState();
22 explicit HistoryState(const SimpleState& initial);
23 ~HistoryState();
24
25 void setRoot(const SimpleState&);
26 void makeMove(Move move);
27 void unmakeMove();
28
29 void makeMovePass();
30 void unmakeMovePass();
31
32 const NumEffectState& state() const {
33 if (dirty)
34 update();
35 return current;
36 }
37 operator const NumEffectState& () const { return state(); }
38 const NumEffectState& initialState() const { return initial_state; }
39 bool empty() const { return moves.empty(); }
40 const vector<Move>& history() const { return moves; }
41 bool isConsistent() const { return state().isConsistent(); }
42 private:
43 void update() const;
44 };
45 class DoUndoMoveLock
46 {
47 HistoryState& state;
48 public:
49 DoUndoMoveLock(HistoryState& s, Move move) : state(s)
50 {
51 state.makeMove(move);
52 }
53 ~DoUndoMoveLock()
54 {
55 state.unmakeMove();
56 }
57 };
58 }
59 using state::HistoryState;
60 using state::DoUndoMoveLock;
61 }
62
63
64 #endif /* _HISTORYSTATE_H */
65 // ;;; Local Variables:
66 // ;;; mode:c++
67 // ;;; c-basic-offset:2
68 // ;;; End: