diff options
author | Carl Hetherington <carl@carlh.net> | 2010-04-01 01:07:24 +0000 |
---|---|---|
committer | Carl Hetherington <carl@carlh.net> | 2010-04-01 01:07:24 +0000 |
commit | 50dd880d7e75b49e7c80c79f32165a756839651c (patch) | |
tree | e4908863b98570709844a2ce536a44ee34479ac7 /libs/pbd | |
parent | afc5e3bd0251dbcdbde27036569eb1acab026991 (diff) |
No-op: rename a few variables and add/fix some comments.
git-svn-id: svn://localhost/ardour2/branches/3.0@6818 d708f5d6-7413-0410-9779-e7cbd77b26cf
Diffstat (limited to 'libs/pbd')
-rw-r--r-- | libs/pbd/pbd/properties.h | 14 | ||||
-rw-r--r-- | libs/pbd/pbd/property_basics.h | 25 | ||||
-rw-r--r-- | libs/pbd/pbd/property_list.h | 4 | ||||
-rw-r--r-- | libs/pbd/pbd/sequence_property.h | 35 | ||||
-rw-r--r-- | libs/pbd/pbd/stateful_diff_command.h | 4 | ||||
-rw-r--r-- | libs/pbd/stateful.cc | 4 | ||||
-rw-r--r-- | libs/pbd/stateful_diff_command.cc | 38 |
7 files changed, 87 insertions, 37 deletions
diff --git a/libs/pbd/pbd/properties.h b/libs/pbd/pbd/properties.h index 31197030f9..784282ee9c 100644 --- a/libs/pbd/pbd/properties.h +++ b/libs/pbd/pbd/properties.h @@ -84,12 +84,10 @@ public: _have_old = false; } - /** If this property has been changed since the last clear_history() call - (or its construction), add an (XML) property describing the old value - to the XMLNode @param old and another describing the current value to - the XMLNode @param current. - */ void add_history_state (XMLNode* history_node) const { + /* We can get to the current state of a scalar property like this one simply + by knowing what the new state is. + */ history_node->add_property (property_name(), to_string (_current)); } @@ -167,10 +165,10 @@ public: : PropertyTemplate<T> (q, v) {} - void diff (PropertyList& before, PropertyList& after) const { + void diff (PropertyList& undo, PropertyList& redo) const { if (this->_have_old) { - before.add (new Property<T> (this->property_id(), this->_old)); - after.add (new Property<T> (this->property_id(), this->_current)); + undo.add (new Property<T> (this->property_id(), this->_old)); + redo.add (new Property<T> (this->property_id(), this->_current)); } } diff --git a/libs/pbd/pbd/property_basics.h b/libs/pbd/pbd/property_basics.h index 1baa14ac64..9661180e21 100644 --- a/libs/pbd/pbd/property_basics.h +++ b/libs/pbd/pbd/property_basics.h @@ -28,6 +28,8 @@ namespace PBD { class PropertyList; + +/** A unique identifier for a property of a Stateful object */ typedef GQuark PropertyID; template<typename T> @@ -39,6 +41,7 @@ struct PropertyDescriptor { typedef T value_type; }; +/** A list of IDs of Properties that have changed in some situation or other */ class PropertyChange : public std::set<PropertyID> { public: @@ -82,13 +85,29 @@ public: /** Forget about any old value for this state */ virtual void clear_history () = 0; - virtual void add_history_state (XMLNode*) const = 0; - virtual void diff (PropertyList&, PropertyList&) const = 0; + /** Make XML that allows us to get from some previous state to the current state + * of this property, and add it to @param history_node + */ + virtual void add_history_state (XMLNode* history_node) const = 0; + + /** Add information to two property lists: one that allows + * undo of the changes in this property's state betwen now and + * the last call to clear_history, and one that allows redo + * of those changes. + */ + virtual void diff (PropertyList& undo, PropertyList& redo) const = 0; virtual PropertyBase* maybe_clone_self_if_found_in_history_node (const XMLNode&) const { return 0; } + /** Set state from an XML node previously generated by add_history_state */ virtual bool set_state_from_owner_state (XMLNode const&) = 0; - virtual void add_state_to_owner_state (XMLNode&) const = 0; + + /** Add complete current state in XML form to an existing XML node @param node */ + virtual void add_state_to_owner_state (XMLNode& node) const = 0; + + /** @return true if this property has changed in value since construction or since + * the last call to clear_history(), whichever was more recent. + */ virtual bool changed() const = 0; /** Set the value of this property from another */ diff --git a/libs/pbd/pbd/property_list.h b/libs/pbd/pbd/property_list.h index af9d10b88f..db7d934fc0 100644 --- a/libs/pbd/pbd/property_list.h +++ b/libs/pbd/pbd/property_list.h @@ -27,6 +27,8 @@ class XMLNode; namespace PBD { + +/** A list of properties, mapped using their ID */ class PropertyList : public std::map<PropertyID, PropertyBase*> { public: @@ -37,7 +39,7 @@ public: void add_history_state (XMLNode* before); /** Add a property (of some kind) to the list. Used when - constructing PropertyList's that describe a change/operation. + constructing PropertyLists that describe a change/operation. */ bool add (PropertyBase* prop); diff --git a/libs/pbd/pbd/sequence_property.h b/libs/pbd/pbd/sequence_property.h index d9ef6255d2..875ae622b7 100644 --- a/libs/pbd/pbd/sequence_property.h +++ b/libs/pbd/pbd/sequence_property.h @@ -1,3 +1,22 @@ +/* + Copyright (C) 2010 Paul Davis + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + +*/ + #ifndef __libpbd_sequence_property_h__ #define __libpbd_sequence_property_h__ @@ -15,12 +34,20 @@ #include "i18n.h" namespace PBD { + +/** A base class for properties whose state is a container of other + * things. Its behaviour is `specialised' for this purpose in that + * it holds state changes as additions to and removals from the + * container, which is more efficient than storing entire state after + * any change. + */ template<typename Container> class SequenceProperty : public PropertyBase { public: typedef std::set<typename Container::value_type> ChangeContainer; - + + /** A record of changes made */ struct ChangeRecord { ChangeContainer added; ChangeContainer removed; @@ -36,7 +63,7 @@ class SequenceProperty : public PropertyBase /* reverse the adds/removes so that this property's change member correctly describes how to undo the changes it currently reflects. A derived instance of this type of property will - create a pdiff() pair by copying the property twice, and + create a diff() pair by copying the property twice, and calling this method on the "before" item of the pair. */ @@ -44,6 +71,10 @@ class SequenceProperty : public PropertyBase } void add_history_state (XMLNode* history_node) const { + + /* We could record the whole of the current state here, but its + obviously more efficient just to record what has changed. + */ XMLNode* child = new XMLNode (PBD::capitalize (property_name())); history_node->add_child_nocopy (*child); diff --git a/libs/pbd/pbd/stateful_diff_command.h b/libs/pbd/pbd/stateful_diff_command.h index cab1ae40cf..21245f029a 100644 --- a/libs/pbd/pbd/stateful_diff_command.h +++ b/libs/pbd/pbd/stateful_diff_command.h @@ -47,8 +47,8 @@ public: private: boost::weak_ptr<Stateful> _object; ///< the object in question - PBD::PropertyList* _before; ///< its (partial) state before the command - PBD::PropertyList* _after; ///< its (partial) state after the operation + PBD::PropertyList* _undo; ///< its (partial) state before the command, to allow undo + PBD::PropertyList* _redo; ///< its (partial) state after the operation, to allow redo }; }; diff --git a/libs/pbd/stateful.cc b/libs/pbd/stateful.cc index 36a0d74778..79936c691f 100644 --- a/libs/pbd/stateful.cc +++ b/libs/pbd/stateful.cc @@ -175,7 +175,7 @@ Stateful::diff (PropertyList& before, PropertyList& after) const } /** Set state of some/all _properties from an XML node. - * @param node Node. + * @param owner_state Node. * @return PropertyChanges made. */ PropertyChange @@ -224,7 +224,7 @@ Stateful::set_properties (const PropertyList& property_list) } /** Add property states to an XML node. - * @param node Node. + * @param owner_state Node. */ void Stateful::add_properties (XMLNode& owner_state) diff --git a/libs/pbd/stateful_diff_command.cc b/libs/pbd/stateful_diff_command.cc index bfd9f33440..0468ac3e8a 100644 --- a/libs/pbd/stateful_diff_command.cc +++ b/libs/pbd/stateful_diff_command.cc @@ -34,35 +34,35 @@ using namespace PBD; StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s) : _object (s) - , _before (new PropertyList) - , _after (new PropertyList) + , _undo (new PropertyList) + , _redo (new PropertyList) { - s->diff (*_before, *_after); + s->diff (*_undo, *_redo); } StatefulDiffCommand::StatefulDiffCommand (boost::shared_ptr<Stateful> s, XMLNode const & n) : _object (s) - , _before (0) - , _after (0) + , _undo (0) + , _redo (0) { const XMLNodeList& children (n.children()); for (XMLNodeList::const_iterator i = children.begin(); i != children.end(); ++i) { if ((*i)->name() == X_("Undo")) { - _before = s->property_factory (**i); + _undo = s->property_factory (**i); } else if ((*i)->name() == X_("Do")) { - _after = s->property_factory (**i); + _redo = s->property_factory (**i); } } - assert (_before != 0); - assert (_after != 0); + assert (_undo != 0); + assert (_redo != 0); } StatefulDiffCommand::~StatefulDiffCommand () { - delete _before; - delete _after; + delete _undo; + delete _redo; } void @@ -71,7 +71,7 @@ StatefulDiffCommand::operator() () boost::shared_ptr<Stateful> s (_object.lock()); if (s) { - PropertyChange changed = s->set_properties (*_after); + PropertyChange changed = s->set_properties (*_redo); if (!changed.empty()) { s->PropertyChanged (changed); } @@ -85,7 +85,7 @@ StatefulDiffCommand::undo () if (s) { std::cerr << "Undoing a stateful diff command\n"; - PropertyChange changed = s->set_properties (*_before); + PropertyChange changed = s->set_properties (*_undo); if (!changed.empty()) { std::cerr << "Sending changed\n"; s->PropertyChanged (changed); @@ -108,14 +108,14 @@ StatefulDiffCommand::get_state () node->add_property ("obj-id", s->id().to_s()); node->add_property ("type-name", demangled_name (*s.get())); - XMLNode* before = new XMLNode (X_("Undo")); - XMLNode* after = new XMLNode (X_("Do")); + XMLNode* undo = new XMLNode (X_("Undo")); + XMLNode* redo = new XMLNode (X_("Do")); - _before->add_history_state (before); - _after->add_history_state (after); + _undo->add_history_state (undo); + _redo->add_history_state (redo); - node->add_child_nocopy (*before); - node->add_child_nocopy (*after); + node->add_child_nocopy (*undo); + node->add_child_nocopy (*redo); return *node; } |