From 8cd29b9b30400e4275f1a65744cd0b3c2669cc98 Mon Sep 17 00:00:00 2001 From: Robin Haberkorn Date: Tue, 6 Nov 2012 20:42:40 +0100 Subject: initial commit of SciTECO based on THECO --- undo.h | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100644 undo.h (limited to 'undo.h') diff --git a/undo.h b/undo.h new file mode 100644 index 0000000..29ec70f --- /dev/null +++ b/undo.h @@ -0,0 +1,82 @@ +#ifndef __UNDO_H +#define __UNDO_H + +#include + +#include + +#include + +class UndoToken { +public: + SLIST_ENTRY(UndoToken) tokens; + + gint pos; + + UndoToken(); + + virtual void run() = 0; +}; + +class UndoTokenMessage : public UndoToken { + unsigned int iMessage; + uptr_t wParam; + sptr_t lParam; + +public: + UndoTokenMessage(unsigned int _iMessage, + uptr_t _wParam = 0, sptr_t _lParam = 0) + : UndoToken(), iMessage(_iMessage), + wParam(_wParam), lParam(_lParam) {} + + void run(void); +}; + +template +class UndoTokenVariable : public UndoToken { + Type *ptr; + Type value; + +public: + UndoTokenVariable(Type &variable, Type _value) + : UndoToken(), ptr(&variable), value(_value) {} + + void + run(void) + { + *ptr = value; + } +}; + +extern class UndoStack { + SLIST_HEAD(undo_head, UndoToken) head; + +public: + UndoStack() + { + SLIST_INIT(&head); + } + ~UndoStack(); + + void push_msg(unsigned int iMessage, + uptr_t wParam = 0, sptr_t lParam = 0); + + template + void + push_var(Type &variable, Type value) + { + UndoToken *token = new UndoTokenVariable(variable, value); + SLIST_INSERT_HEAD(&head, token, tokens); + } + + template + inline void + push_var(Type &variable) + { + push_var(variable, variable); + } + + void pop(gint pos); +} undo; + +#endif \ No newline at end of file -- cgit v1.2.3