tweak transport bar spacing
[ardour.git] / libs / pbd / pbd / properties.h
index fa8e4cf3eb552d541eb7c2bd972fba51cab865bb..d961046760fa866280711d895fb97e65fa88150a 100644 (file)
@@ -33,8 +33,7 @@
 
 namespace PBD {
 
-/** Parent class for classes which represent a single scalar property in a Stateful object 
- */
+/** Parent class for classes which represent a single scalar property in a Stateful object */
 template<class T>
 class PropertyTemplate : public PropertyBase
 {
@@ -58,6 +57,9 @@ public:
                , _current (s._current)
        {}
 
+
+       /* OPERATORS / ACCESSORS */
+
        T & operator=(T const& v) {
                set (v);
                return _current;
@@ -93,16 +95,9 @@ public:
                return _current;
        }
 
-       void clear_changes () {
-               _have_old = false;
-       }
-
-       void get_changes_as_xml (XMLNode* history_node) const {
-               XMLNode* node = history_node->add_child (property_name());
-                node->add_property ("from", to_string (_old));
-                node->add_property ("to", to_string (_current));
-       }
 
+       /* MANAGEMENT OF Stateful State */
+       
        bool set_value (XMLNode const & node) {
 
                XMLProperty const* p = node.property (property_name());
@@ -123,48 +118,67 @@ public:
                 node.add_property (property_name(), to_string (_current));
        }
 
-       bool changed () const { return _have_old; }
        
-       void apply_changes (PropertyBase const * p) {
-               T v = dynamic_cast<const PropertyTemplate<T>* > (p)->val ();
-               if (v != _current) {
-                       set (v);
-               }
+       /* MANAGEMENT OF HISTORY */
+       
+       void clear_changes () {
+               _have_old = false;
        }
 
+       bool changed () const { return _have_old; }
+
        void invert () {
                T const tmp = _current;
                _current = _old;
                _old = tmp;
        }
 
-        void get_changes_as_properties (PropertyList& changes, Command *) const {
-                if (this->_have_old) {
+
+       /* TRANSFERRING HISTORY TO / FROM A StatefulDiffCommand */
+       
+       void get_changes_as_xml (XMLNode* history_node) const {
+               XMLNode* node = history_node->add_child (property_name());
+                node->add_property ("from", to_string (_old));
+                node->add_property ("to", to_string (_current));
+       }
+
+       void get_changes_as_properties (PropertyList& changes, Command *) const {
+               if (this->_have_old) {
                        changes.add (clone ());
-                }
-        }
+               }
+       }
+
+
+       /* VARIOUS */
+
+       void apply_changes (PropertyBase const * p) {
+               T v = dynamic_cast<const PropertyTemplate<T>* > (p)->val ();
+               if (v != _current) {
+                       set (v);
+               }
+       }
 
 protected:
 
        void set (T const& v) {
-                if (v != _current) {
-                        if (!_have_old) {
-                                _old = _current;
-                                _have_old = true;
-                        } else {
-                                if (v == _old) {
-                                        /* value has been reset to the value
-                                           at the start of a history transaction,
-                                           before clear_changes() is called.
-                                           thus there is effectively no apparent
-                                           history for this property.
-                                        */
-                                        _have_old = false;
-                                }
-                        }
-
-                        _current  = v;
-                
+               if (v != _current) {
+                       if (!_have_old) {
+                               _old = _current;
+                               _have_old = true;
+                       } else {
+                               if (v == _old) {
+                                       /* value has been reset to the value
+                                          at the start of a history transaction,
+                                          before clear_changes() is called.
+                                          thus there is effectively no apparent
+                                          history for this property.
+                                       */
+                                       _have_old = false;
+                               }
+                       }
+
+                       _current  = v;
+               } 
        }
 
        virtual std::string to_string (T const& v) const             = 0;
@@ -210,7 +224,7 @@ public:
                return new Property<T> (this->property_id(), this->_old, this->_current);
        }
        
-        Property<T>* clone_from_xml (const XMLNode& node) const {
+       Property<T>* clone_from_xml (const XMLNode& node) const {
                XMLNodeList const & children = node.children ();
                XMLNodeList::const_iterator i = children.begin();
                while (i != children.end() && (*i)->name() != this->property_name()) {
@@ -228,7 +242,7 @@ public:
                }
                        
                return new Property<T> (this->property_id(), from_string (from->value()), from_string (to->value ()));
-        }
+       }
 
        T & operator=(T const& v) {
                this->set (v);
@@ -291,7 +305,7 @@ public:
 
 private:
        std::string to_string (std::string const& v) const {
-               return _current;
+               return v;
        }
 
        std::string from_string (std::string const& s) const {