2 Copyright (C) 2010 Paul Davis
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, write to the Free Software
16 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 #include "pbd/stateful_diff_command.h"
21 #include "pbd/property_list.h"
22 #include "pbd/demangle.h"
28 /** Create a new StatefulDiffCommand by examining the changes made to a Stateful
29 * since the last time that clear_changes was called on it.
30 * @param s Stateful object.
33 StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<StatefulDestructible> s)
37 _changes = s->get_changes_as_properties (this);
39 /* if the stateful object that this command refers to goes away,
40 be sure to notify owners of this command.
43 s->DropReferences.connect_same_thread (*this, boost::bind (&Destructible::drop_references, this));
46 StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<StatefulDestructible> s, XMLNode const & n)
50 const XMLNodeList& children (n.children());
52 for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) {
53 if ((*i)->name() == X_("Changes")) {
54 _changes = s->property_factory (**i);
58 assert (_changes != 0);
60 /* if the stateful object that this command refers to goes away,
61 be sure to notify owners of this command.
64 s->DropReferences.connect_same_thread (*this, boost::bind (&Destructible::drop_references, this));
67 StatefulDiffCommand::~StatefulDiffCommand ()
75 StatefulDiffCommand::operator() ()
77 boost::shared_ptr<Stateful> s (_object.lock());
80 s->apply_changes (*_changes);
85 StatefulDiffCommand::undo ()
87 boost::shared_ptr<Stateful> s (_object.lock());
90 PropertyList p = *_changes;
97 StatefulDiffCommand::get_state ()
99 boost::shared_ptr<Stateful> s (_object.lock());
102 /* XXX should we throw? */
103 return * new XMLNode("");
106 XMLNode* node = new XMLNode (X_("StatefulDiffCommand"));
108 node->add_property ("obj-id", s->id().to_s());
109 node->add_property ("type-name", demangled_name (*s.get()));
111 XMLNode* changes = new XMLNode (X_("Changes"));
113 _changes->get_changes_as_xml (changes);
115 node->add_child_nocopy (*changes);
121 StatefulDiffCommand::empty () const
123 return _changes->empty();