aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-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);