summaryrefslogtreecommitdiff
path: root/libs/pbd/stateful_diff_command.cc
diff options
context:
space:
mode:
authorPaul Davis <paul@linuxaudiosystems.com>2010-02-11 23:10:29 +0000
committerPaul Davis <paul@linuxaudiosystems.com>2010-02-11 23:10:29 +0000
commita1e0dc13df3cdc7033c940f0f3311a2bd47d3b2e (patch)
tree72cf696511c00bb4dfc135f43f8c0ae0498140cf /libs/pbd/stateful_diff_command.cc
parentf938687f8798d094c99cd4308ad6aa1c467e4a97 (diff)
tweak Stateful/StatefulDiffCommand changes so that SessionObject's actually get a name; make StatefulDiffCommand use a weak_ptr, not a raw ptr; use .val() rather than .get() to avoid confusion with boost:: smart ptr method of the same name
git-svn-id: svn://localhost/ardour2/branches/3.0@6678 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd/stateful_diff_command.cc')
-rw-r--r--libs/pbd/stateful_diff_command.cc27
1 files changed, 21 insertions, 6 deletions
diff --git a/libs/pbd/stateful_diff_command.cc b/libs/pbd/stateful_diff_command.cc
index 1332cae4ff..bf092a6594 100644
--- a/libs/pbd/stateful_diff_command.cc
+++ b/libs/pbd/stateful_diff_command.cc
@@ -28,7 +28,7 @@ using namespace PBD;
* @param s Stateful object.
*/
-StatefulDiffCommand::StatefulDiffCommand (Stateful* s)
+StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s)
: _object (s)
{
pair<XMLNode *, XMLNode*> const p = s->diff ();
@@ -36,7 +36,7 @@ StatefulDiffCommand::StatefulDiffCommand (Stateful* s)
_after = p.second;
}
-StatefulDiffCommand::StatefulDiffCommand (Stateful* s, XMLNode const & n)
+StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s, XMLNode const & n)
: _object (s)
{
_before = new XMLNode (*n.children().front());
@@ -53,22 +53,37 @@ StatefulDiffCommand::~StatefulDiffCommand ()
void
StatefulDiffCommand::operator() ()
{
- _object->set_state (*_after, Stateful::current_state_version);
+ boost::shared_ptr<Stateful> s (_object.lock());
+
+ if (s) {
+ s->set_state (*_after, Stateful::current_state_version);
+ }
}
void
StatefulDiffCommand::undo ()
{
- _object->set_state (*_before, Stateful::current_state_version);
+ boost::shared_ptr<Stateful> s (_object.lock());
+
+ if (s) {
+ s->set_state (*_before, Stateful::current_state_version);
+ }
}
XMLNode&
StatefulDiffCommand::get_state ()
{
+ boost::shared_ptr<Stateful> s (_object.lock());
+
+ if (!s) {
+ /* XXX should we throw? */
+ return * new XMLNode("");
+ }
+
XMLNode* node = new XMLNode (X_("StatefulDiffCommand"));
- node->add_property ("obj-id", _object->id().to_s());
- node->add_property ("type-name", typeid(*_object).name());
+ node->add_property ("obj-id", s->id().to_s());
+ node->add_property ("type-name", typeid(*s.get()).name());
node->add_child_copy (*_before);
node->add_child_copy (*_after);