diff options
Diffstat (limited to 'expressions.h')
-rw-r--r-- | expressions.h | 79 |
1 files changed, 44 insertions, 35 deletions
diff --git a/expressions.h b/expressions.h index 0f4c9eb..1f1637f 100644 --- a/expressions.h +++ b/expressions.h @@ -7,6 +7,40 @@ template <typename Type> class ValueStack { + class UndoTokenPush : public UndoToken { + ValueStack<Type> *stack; + + Type value; + int index; + + public: + UndoTokenPush(ValueStack<Type> *_stack, + Type _value, int _index = 1) + : stack(_stack), value(_value), index(_index) {} + + void + run(void) + { + stack->push(value, index); + } + }; + + class UndoTokenPop : public UndoToken { + ValueStack<Type> *stack; + + int index; + + public: + UndoTokenPop(ValueStack<Type> *_stack, int _index = 1) + : stack(_stack), index(_index) {} + + void + run(void) + { + stack->pop(index); + } + }; + int size; Type *stack; @@ -38,6 +72,11 @@ public: top++; return peek(index) = value; } + inline void + undo_push(Type value, int index = 1) + { + undo.push(new UndoTokenPush(this, value, index)); + } inline Type pop(int index = 1) @@ -50,6 +89,11 @@ public: return v; } + inline void + undo_pop(int index = 1) + { + undo.push(new UndoTokenPop(this, index)); + } inline Type & peek(int index = 1) @@ -58,41 +102,6 @@ public: } }; -template <typename Type> -class UndoTokenPush : public UndoToken { - ValueStack<Type> *stack; - - Type value; - int index; - -public: - UndoTokenPush(ValueStack<Type> &_stack, Type _value, int _index = 1) - : stack(&_stack), value(_value), index(_index) {} - - void - run(void) - { - stack->push(value, index); - } -}; - -template <typename Type> -class UndoTokenPop : public UndoToken { - ValueStack<Type> *stack; - - int index; - -public: - UndoTokenPop(ValueStack<Type> &_stack, int _index = 1) - : stack(&_stack), index(_index) {} - - void - run(void) - { - stack->pop(index); - } -}; - /* * Arithmetic expression stacks */ |