Tempo ramps - correct fix for adding/replacing meters.
[ardour.git] / libs / pbd / xml++.cc
index cc583fe86e14ab78fbcb969be39a994800728c87..80fc88242dc9884dc79b5351a10bcd37830c981c 100644 (file)
@@ -6,7 +6,10 @@
  */
 
 #include <iostream>
+
+#include "pbd/stacktrace.h"
 #include "pbd/xml++.h"
+
 #include <libxml/debugXML.h>
 #include <libxml/xpath.h>
 #include <libxml/xpathInternals.h>
@@ -404,11 +407,36 @@ XMLNode::add_content(const string& c)
        return add_child_copy(XMLNode (string(), c));
 }
 
-XMLProperty*
+XMLProperty const *
+XMLNode::property(const char* n) const
+{
+       string ns(n);
+       map<string,XMLProperty*>::const_iterator iter;
+
+       if ((iter = _propmap.find(ns)) != _propmap.end()) {
+               return iter->second;
+       }
+
+       return 0;
+}
+
+XMLProperty const *
+XMLNode::property(const string& ns) const
+{
+       map<string,XMLProperty*>::const_iterator iter;
+
+       if ((iter = _propmap.find(ns)) != _propmap.end()) {
+               return iter->second;
+       }
+
+       return 0;
+}
+
+XMLProperty *
 XMLNode::property(const char* n)
 {
        string ns(n);
-       unordered_map<string,XMLProperty*>::iterator iter;
+       map<string,XMLProperty*>::iterator iter;
 
        if ((iter = _propmap.find(ns)) != _propmap.end()) {
                return iter->second;
@@ -417,10 +445,10 @@ XMLNode::property(const char* n)
        return 0;
 }
 
-XMLProperty*
+XMLProperty *
 XMLNode::property(const string& ns)
 {
-       unordered_map<string,XMLProperty*>::iterator iter;
+       map<string,XMLProperty*>::iterator iter;
 
        if ((iter = _propmap.find(ns)) != _propmap.end()) {
                return iter->second;
@@ -429,11 +457,22 @@ XMLNode::property(const string& ns)
        return 0;
 }
 
+bool
+XMLNode::has_property_with_value (const string& key, const string& value) const
+{
+       map<string,XMLProperty*>::const_iterator iter = _propmap.find(key);
+       if (iter != _propmap.end()) {
+               const XMLProperty* p = (iter->second);
+               return (p && p->value() == value);
+       }
+       return false;
+}
+
 XMLProperty*
 XMLNode::add_property(const char* n, const string& v)
 {
        string ns(n);
-        unordered_map<string,XMLProperty*>::iterator iter;
+        map<string,XMLProperty*>::iterator iter;
 
         if ((iter = _propmap.find(ns)) != _propmap.end()) {
                 iter->second->set_value (v);
@@ -472,7 +511,10 @@ XMLNode::remove_property(const string& n)
 {
        if (_propmap.find(n) != _propmap.end()) {
                XMLProperty* p = _propmap[n];
-               _proplist.remove (p);
+               XMLPropertyIterator i = std::find(_proplist.begin(), _proplist.end(), p);
+               if (i != _proplist.end ()) {
+                       _proplist.erase (i);
+               }
                delete p;
                _propmap.erase(n);
        }
@@ -492,15 +534,12 @@ void
 XMLNode::remove_nodes(const string& n)
 {
        XMLNodeIterator i = _children.begin();
-       XMLNodeIterator tmp;
-
        while (i != _children.end()) {
-               tmp = i;
-               ++tmp;
                if ((*i)->name() == n) {
-                       _children.erase (i);
+                       i = _children.erase (i);
+               } else {
+                       ++i;
                }
-               i = tmp;
        }
 }
 
@@ -508,16 +547,14 @@ void
 XMLNode::remove_nodes_and_delete(const string& n)
 {
        XMLNodeIterator i = _children.begin();
-       XMLNodeIterator tmp;
 
        while (i != _children.end()) {
-               tmp = i;
-               ++tmp;
                if ((*i)->name() == n) {
                        delete *i;
-                       _children.erase (i);
+                       i = _children.erase (i);
+               } else {
+                       ++i;
                }
-               i = tmp;
        }
 }
 
@@ -525,20 +562,16 @@ void
 XMLNode::remove_nodes_and_delete(const string& propname, const string& val)
 {
        XMLNodeIterator i = _children.begin();
-       XMLNodeIterator tmp;
-       XMLProperty* prop;
+       XMLProperty const * prop;
 
        while (i != _children.end()) {
-               tmp = i;
-               ++tmp;
-
                prop = (*i)->property(propname);
                if (prop && prop->value() == val) {
                        delete *i;
-                       _children.erase(i);
+                       i = _children.erase(i);
+               } else {
+                       ++i;
                }
-
-               i = tmp;
        }
 }