summaryrefslogtreecommitdiff
path: root/libs/pbd/stateful.cc
diff options
context:
space:
mode:
authorCarl Hetherington <carl@carlh.net>2010-02-09 14:44:01 +0000
committerCarl Hetherington <carl@carlh.net>2010-02-09 14:44:01 +0000
commita5c59175eb561cca6b704d6c50ee20290cc9a210 (patch)
treed75c4749252b92ede3131e47091c1298f782dc98 /libs/pbd/stateful.cc
parent76ad2dfea0c53757530483ef3000caf9583441ec (diff)
Modify Stateful to allow undo to be done using differences in state.
git-svn-id: svn://localhost/ardour2/branches/3.0@6664 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/stateful.cc')
-rw-r--r--libs/pbd/stateful.cc31
1 files changed, 31 insertions, 0 deletions
diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc
index 596402576e..9f510b85d4 100644
--- a/libs/pbd/stateful.cc
+++ b/libs/pbd/stateful.cc
@@ -47,6 +47,10 @@ Stateful::~Stateful ()
// means it needs to live on indefinately.
delete _instant_xml;
+
+ for (list<StateBase*>::iterator i = _states.begin(); i != _states.end(); ++i) {
+ delete *i;
+ }
}
void
@@ -149,4 +153,31 @@ Stateful::instant_xml (const string& str, const sys::path& directory_path)
return 0;
}
+/** Forget about any old state for this object */
+void
+Stateful::clear_history ()
+{
+ for (list<StateBase*>::iterator i = _states.begin(); i != _states.end(); ++i) {
+ (*i)->clear_history ();
+ }
+}
+
+/** @return A pair of XMLNodes representing state that has changed since the last time clear_history
+ * was called on this object; the first is the state before, the second the state after.
+ *
+ * It is the caller's responsibility to delete the returned XMLNodes.
+ */
+pair<XMLNode *, XMLNode *>
+Stateful::diff ()
+{
+ XMLNode* old = new XMLNode (_xml_node_name);
+ XMLNode* current = new XMLNode (_xml_node_name);
+
+ for (list<StateBase*>::iterator i = _states.begin(); i != _states.end(); ++i) {
+ (*i)->diff (old, current);
+ }
+
+ return make_pair (old, current);
+}
+
} // namespace PBD