aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/undo.h
diff options
context:
space:
mode:
authorRobin Haberkorn <robin.haberkorn@googlemail.com>2013-02-14 02:57:54 +0100
committerRobin Haberkorn <robin.haberkorn@googlemail.com>2013-02-14 05:21:25 +0100
commit17c62e3d58a6f8cc301be10060f772f10ab4466c (patch)
treed38ed4896b9d9f0d6e596b009248b25ecaeafd08 /src/undo.h
parent9cd71e16b30e2f0061a6d74421a5357333721a70 (diff)
downloadsciteco-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.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/src/undo.h b/src/undo.h
index 0fd9809..8d5d5d6 100644
--- a/src/undo.h
+++ b/src/undo.h
@@ -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);