diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/undo.h | 40 |
1 files changed, 40 insertions, 0 deletions
@@ -99,6 +99,31 @@ public: } }; +template <class Type> +class UndoTokenObject : public UndoToken { + Type **ptr; + Type *obj; + +public: + UndoTokenObject(Type *&variable, Type *_obj) + : UndoToken(), ptr(&variable), obj(_obj) {} + + ~UndoTokenObject() + { + if (obj) + delete obj; + } + + void + run(void) + { + if (*ptr) + delete *ptr; + *ptr = obj; + obj = NULL; + } +}; + extern class UndoStack { SLIST_HEAD(Head, UndoToken) head; @@ -143,6 +168,21 @@ public: return push_str(variable, variable); } + template <class Type> + inline Type *& + push_obj(Type *&variable, Type *obj) + { + push(new UndoTokenObject<Type>(variable, obj)); + return variable; + } + + template <class Type> + inline Type *& + push_obj(Type *&variable) + { + return push_obj<Type>(variable, variable); + } + void pop(gint pos); void clear(void); |