diff options
author | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-02-14 02:57:54 +0100 |
---|---|---|
committer | Robin Haberkorn <robin.haberkorn@googlemail.com> | 2013-02-14 05:21:25 +0100 |
commit | 17c62e3d58a6f8cc301be10060f772f10ab4466c (patch) | |
tree | d38ed4896b9d9f0d6e596b009248b25ecaeafd08 /src/undo.h | |
parent | 9cd71e16b30e2f0061a6d74421a5357333721a70 (diff) | |
download | sciteco-17c62e3d58a6f8cc301be10060f772f10ab4466c.tar.gz |
undo tokens for changing an object pointer
will care about the eventual deletion of the object
Diffstat (limited to 'src/undo.h')
-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); |