Allow cross-thread request invalidators to cope with multiple requests
[ardour.git] / libs / pbd / pbd / properties.h
index 8d2f465ebf217b33eff1d824c091570315c06a27..784282ee9c55d0228411e5e538843af9c9cb0bea 100644 (file)
@@ -40,6 +40,7 @@ class PropertyTemplate : public PropertyBase
 public:
        PropertyTemplate (PropertyDescriptor<T> p, T const& v)
                : PropertyBase (p.property_id)
+               , _have_old (false)
                , _current (v)
        {}
 
@@ -79,12 +80,14 @@ public:
                return _current;
        }
 
-        /** 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 clear_history () {
+               _have_old = false;
+       }
+
        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));
        }
 
@@ -112,6 +115,14 @@ public:
                 owner_state.add_property (property_name(), to_string (_current));
        }
 
+       bool changed () const { return _have_old; }
+       void set_state_from_property (PropertyBase const * p) {
+               T v = dynamic_cast<const PropertyTemplate<T>* > (p)->val ();
+               if (v != _current) {
+                       set (v);
+               }
+       }
+
 protected:
         /** Constructs a PropertyTemplate with a default
             value for _old and _current.
@@ -132,6 +143,7 @@ protected:
        virtual std::string to_string (T const& v) const             = 0;
        virtual T           from_string (std::string const& s) const = 0;
 
+       bool _have_old;
        T _current;
        T _old;
 };
@@ -153,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));
                 }
         }