summaryrefslogtreecommitdiff
path: root/libs/pbd/pbd
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2006-08-25 01:07:15 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2006-08-25 01:07:15 +0000
commitce234f363e95c38fc92728e520bf5ba240a89aa7 (patch)
tree96ce8c4734bdd564ec1f2ad0c36bc32f0b108204 /libs/pbd/pbd
parent7e95f29ce95edf01d6d451f96fae03f3d3451ff8 (diff)
use shared_ptr<> for all region handling
git-svn-id: svn://localhost/ardour2/trunk@852 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/pbd')
-rw-r--r--libs/pbd/pbd/command.h3
-rw-r--r--libs/pbd/pbd/memento_command.h39
-rw-r--r--libs/pbd/pbd/statefuldestructible.h13
-rw-r--r--libs/pbd/pbd/undo.h34
4 files changed, 64 insertions, 25 deletions
diff --git a/libs/pbd/pbd/command.h b/libs/pbd/pbd/command.h
index cd9bf0e08a..7c367e7462 100644
--- a/libs/pbd/pbd/command.h
+++ b/libs/pbd/pbd/command.h
@@ -22,8 +22,9 @@
#define __lib_pbd_command_h__
#include <pbd/stateful.h>
+#include <pbd/destructible.h>
-class Command : public Stateful
+class Command : public Stateful, public PBD::Destructible
{
public:
virtual ~Command() {}
diff --git a/libs/pbd/pbd/memento_command.h b/libs/pbd/pbd/memento_command.h
index 3a72fc9841..f257e63233 100644
--- a/libs/pbd/pbd/memento_command.h
+++ b/libs/pbd/pbd/memento_command.h
@@ -21,6 +21,10 @@
#ifndef __lib_pbd_memento_command_h__
#define __lib_pbd_memento_command_h__
+#include <iostream>
+using std::cerr;
+using std::endl;
+
#include <pbd/command.h>
#include <pbd/xml++.h>
#include <sigc++/slot.h>
@@ -34,12 +38,22 @@ template <class obj_T>
class MementoCommand : public Command
{
public:
- MementoCommand(XMLNode &state);
- MementoCommand(obj_T &obj,
+ MementoCommand(obj_T &object,
XMLNode *before,
XMLNode *after
)
- : obj(obj), before(before), after(after) {}
+ : obj(object), before(before), after(after) {
+ obj.GoingAway.connect (sigc::mem_fun (*this, &MementoCommand<obj_T>::object_death));
+ }
+ ~MementoCommand () {
+ GoingAway();
+ if (before) {
+ delete before;
+ }
+ if (after) {
+ delete after;
+ }
+ }
void operator() ()
{
if (after)
@@ -60,20 +74,27 @@ class MementoCommand : public Command
else
name = "MementoRedoCommand";
+
XMLNode *node = new XMLNode(name);
- node->add_property("obj_id", obj.id().to_s());
- node->add_property("type_name", typeid(obj).name());
- if (before)
- node->add_child_copy(*before);
- if (after)
- node->add_child_copy(*after);
+ node->add_property("obj_id", obj.id().to_s());
+ node->add_property("type_name", typeid(obj).name());
+
+ if (before)
+ node->add_child_copy(*before);
+ if (after)
+ node->add_child_copy(*after);
return *node;
}
+
protected:
obj_T &obj;
XMLNode *before, *after;
+
+ void object_death () {
+ delete this;
+ }
};
#endif // __lib_pbd_memento_h__
diff --git a/libs/pbd/pbd/statefuldestructible.h b/libs/pbd/pbd/statefuldestructible.h
new file mode 100644
index 0000000000..e78cc4bdaa
--- /dev/null
+++ b/libs/pbd/pbd/statefuldestructible.h
@@ -0,0 +1,13 @@
+#ifndef __pbd_stateful_destructible_h__
+#define __pbd_stateful_destructible_h__
+
+#include <pbd/stateful.h>
+#include <pbd/destructible.h>
+
+namespace PBD {
+class StatefulDestructible : public Stateful, public Destructible
+{
+};
+}
+
+#endif /* __pbd_stateful_destructible_h__ */
diff --git a/libs/pbd/pbd/undo.h b/libs/pbd/pbd/undo.h
index 724e86aaa0..eecd8ae49d 100644
--- a/libs/pbd/pbd/undo.h
+++ b/libs/pbd/pbd/undo.h
@@ -29,9 +29,6 @@
#include <sys/time.h>
#include <pbd/command.h>
-using std::string;
-using std::list;
-
typedef sigc::slot<void> UndoAction;
class UndoTransaction : public Command
@@ -40,10 +37,11 @@ class UndoTransaction : public Command
UndoTransaction ();
UndoTransaction (const UndoTransaction&);
UndoTransaction& operator= (const UndoTransaction&);
+ ~UndoTransaction ();
void clear ();
- void add_command (Command *const);
+ void add_command (Command* const);
void operator() ();
void undo();
@@ -51,10 +49,10 @@ class UndoTransaction : public Command
XMLNode &get_state();
- void set_name (const string& str) {
+ void set_name (const std::string& str) {
_name = str;
}
- const string& name() const { return _name; }
+ const std::string& name() const { return _name; }
void set_timestamp (struct timeval &t) {
_timestamp = t;
@@ -65,26 +63,28 @@ class UndoTransaction : public Command
}
private:
- list<Command*> actions;
- struct timeval _timestamp;
- string _name;
+ std::list<Command*> actions;
+ struct timeval _timestamp;
+ std::string _name;
+ bool clearing;
+ void remove_command (Command* const);
};
class UndoHistory
{
public:
- UndoHistory() {}
+ UndoHistory();
~UndoHistory() {}
- void add (UndoTransaction ut);
+ void add (UndoTransaction* ut);
void undo (unsigned int n);
void redo (unsigned int n);
unsigned long undo_depth() const { return UndoList.size(); }
unsigned long redo_depth() const { return RedoList.size(); }
- string next_undo() const { return (UndoList.empty() ? string("") : UndoList.back().name()); }
- string next_redo() const { return (RedoList.empty() ? string("") : RedoList.back().name()); }
+ std::string next_undo() const { return (UndoList.empty() ? std::string("") : UndoList.back()->name()); }
+ std::string next_redo() const { return (RedoList.empty() ? std::string("") : RedoList.back()->name()); }
void clear ();
void clear_undo ();
@@ -92,9 +92,13 @@ class UndoHistory
XMLNode &get_state();
void save_state();
+
private:
- list<UndoTransaction> UndoList;
- list<UndoTransaction> RedoList;
+ bool clearing;
+ std::list<UndoTransaction*> UndoList;
+ std::list<UndoTransaction*> RedoList;
+
+ void remove (UndoTransaction*);
};