A few small cleanups to the property code.
authorCarl Hetherington <carl@carlh.net>
Wed, 31 Mar 2010 22:17:01 +0000 (22:17 +0000)
committerCarl Hetherington <carl@carlh.net>
Wed, 31 Mar 2010 22:17:01 +0000 (22:17 +0000)
git-svn-id: svn://localhost/ardour2/branches/3.0@6816 d708f5d6-7413-0410-9779-e7cbd77b26cf

libs/ardour/playlist.cc
libs/pbd/pbd/properties.h
libs/pbd/pbd/property_basics.h
libs/pbd/pbd/sequence_property.h

index 35b0aedcd8f25603dcc0d99d348446b6c799f860..3af4d2243014f529ea2c6e06b5cf9c5be230c004 100644 (file)
@@ -133,7 +133,7 @@ RegionListProperty::copy_for_history () const
 void 
 RegionListProperty::diff (PropertyList& before, PropertyList& after) const
 {
-        if (_have_old) {
+        if (changed()) {
                 RegionListProperty* a = copy_for_history ();
                 RegionListProperty* b = copy_for_history ();
 
index 8d2f465ebf217b33eff1d824c091570315c06a27..691ab9c4adf8baa17d32ca75ea2f409789cc430e 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,6 +80,10 @@ public:
                return _current;
        }
 
+       void clear_history () {
+               _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
@@ -112,6 +117,8 @@ public:
                 owner_state.add_property (property_name(), to_string (_current));
        }
 
+       bool changed () const { return _have_old; }
+
 protected:
         /** Constructs a PropertyTemplate with a default
             value for _old and _current.
@@ -132,6 +139,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;
 };
index e818e36e90b087e3f0ad82ad95dc17200758846e..251d71dc66425a3afaf5bbd43553e2fe5d109d22 100644 (file)
@@ -77,13 +77,10 @@ class PropertyBase
 public:
        PropertyBase (PropertyID pid)
                : _property_id (pid)
-               , _have_old (false)
        {}
 
        /** Forget about any old value for this state */
-       virtual void clear_history () {
-               _have_old = false;
-       }
+       virtual void clear_history () = 0;
 
        virtual void add_history_state (XMLNode*)        const = 0;
        virtual void diff (PropertyList&, PropertyList&) const = 0;
@@ -92,10 +89,10 @@ public:
 
        virtual bool set_state_from_owner_state (XMLNode const&) = 0;
        virtual void add_state_to_owner_state (XMLNode&) const   = 0;
+       virtual bool changed() const = 0;
 
        const gchar*property_name () const { return g_quark_to_string (_property_id); }
        PropertyID  property_id () const   { return _property_id; }
-        bool changed() const { return _have_old; }
 
        bool operator==(PropertyID pid) const {
                return _property_id == pid;
@@ -103,13 +100,6 @@ public:
 
 protected:
        PropertyID _property_id;
-       bool       _have_old;
-};
-
-class PropertyFactory 
-{
-  public:
-        static PropertyBase* create (const XMLNode&);
 };
 
 }
index c2ad939b7c0be0826eff188c96928ac42c833e2e..8bbc7c77d281f1fc3959c006f86275a5b8b8e256 100644 (file)
@@ -113,9 +113,12 @@ class SequenceProperty : public PropertyBase
                         owner_state_node.add_child_nocopy ((*i)->get_state ());
                 } 
        }
+
+       bool changed () const {
+               return !_change.added.empty() || !_change.removed.empty();
+       }
        
        void clear_history () {
-               PropertyBase::clear_history();
                _change.added.clear ();
                _change.removed.clear ();
        }
@@ -145,21 +148,18 @@ class SequenceProperty : public PropertyBase
        typename Container::const_reverse_iterator rend() const { return _val.rend(); }
 
        typename Container::iterator insert (typename Container::iterator i, const typename Container::value_type& v) {
-                _have_old = true;
                _change.added.insert (v);
                return _val.insert (i, v);
        }
 
        typename Container::iterator erase (typename Container::iterator i) {
                if (i != _val.end()) {
-                        _have_old = true;
                        _change.removed.insert (*i);
                }
                return _val.erase (i);
        }
 
        typename Container::iterator erase (typename Container::iterator f, typename Container::iterator l) {
-                _have_old = true;
                for (typename Container::const_iterator i = f; i != l; ++i) {
                        _change.removed.insert(*i);
                }
@@ -167,20 +167,17 @@ class SequenceProperty : public PropertyBase
        }
 
        void push_back (const typename Container::value_type& v) {
-                _have_old = true;
                _change.added.insert (v);
                _val.push_back (v);
        }
 
        void push_front (const typename Container::value_type& v) {
-                _have_old = true;
                _change.added.insert (v);
                _val.push_front (v);
        }
 
        void pop_front () {
                 if (!_val.empty()) {
-                        _have_old = true;
                         _change.removed.insert (front());
                 }
                _val.pop_front ();
@@ -188,14 +185,12 @@ class SequenceProperty : public PropertyBase
 
        void pop_back () {
                 if (!_val.empty()) {
-                        _have_old = true;
                         _change.removed.insert (front());
                 }
                _val.pop_back ();
        }
 
        void clear () {
-                _have_old = true;
                _change.removed.insert (_val.begin(), _val.end());
                _val.clear ();
        }
@@ -209,7 +204,6 @@ class SequenceProperty : public PropertyBase
        }
 
        Container& operator= (const Container& other) {
-                _have_old = true;
                 _change.removed.insert (_val.begin(), _val.end());
                 _change.added.insert (other.begin(), other.end());
                return _val = other;