A few small cleanups to the property code.
git-svn-id: svn://localhost/ardour2/branches/3.0@6816 d708f5d6-7413-0410-9779-e7cbd77b26cf
This commit is contained in:
parent
cc227eb75e
commit
7f8b337d30
|
@ -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 ();
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
|
|
@ -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&);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue
Block a user