Remove Diskstream member playback_distance that can be
[ardour.git] / libs / pbd / xml++.cc
index 9f7ef6007f26510095ba17b77634fce101a4c22c..1b006fd63d4f7677fff92fc5532c4fcb82a53982 100644 (file)
@@ -5,6 +5,7 @@
  * Modified for Ardour and released under the same terms.
  */
 
+#include <iostream>
 #include "pbd/xml++.h"
 #include <libxml/debugXML.h>
 #include <libxml/xpath.h>
@@ -12,6 +13,8 @@
 
 #define XML_VERSION "1.0"
 
+using namespace std;
+
 static XMLNode*           readnode(xmlNodePtr);
 static void               writenode(xmlDocPtr, XMLNode*, xmlNodePtr, int);
 static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string& xpath);
@@ -66,7 +69,7 @@ XMLTree::read_internal(bool validate)
        delete _root;
        _root = 0;
 
-       xmlParserCtxtPtr ctxt; /* the parser context */
+       xmlParserCtxtPtr ctxt = NULL; /* the parser context */
        xmlDocPtr doc; /* the resulting document tree */
 
        xmlKeepBlanksDefault(0);
@@ -93,7 +96,6 @@ XMLTree::read_internal(bool validate)
                if (validate && ctxt->valid == 0) {
                        xmlFreeParserCtxt(ctxt);
                        xmlFreeDoc(doc);
-                       xmlCleanupParser();
                        throw XMLException("Failed to validate document " + _filename);
                }
        }
@@ -105,7 +107,6 @@ XMLTree::read_internal(bool validate)
                xmlFreeParserCtxt(ctxt);
        }
        xmlFreeDoc(doc);
-       xmlCleanupParser();
 
        return true;
 }
@@ -376,8 +377,11 @@ XMLProperty*
 XMLNode::add_property(const char* n, const string& v)
 {
        string ns(n);
-       if (_propmap.find(ns) != _propmap.end()) {
-               remove_property(ns);
+        map<string,XMLProperty*>::iterator iter;
+       
+        if ((iter = _propmap.find(ns)) != _propmap.end()) {
+                iter->second->set_value (v);
+                return iter->second;
        }
 
        XMLProperty* tmp = new XMLProperty(ns, v);
@@ -402,8 +406,8 @@ XMLNode::add_property(const char* n, const char* v)
 XMLProperty*
 XMLNode::add_property(const char* name, const long value)
 {
-       static char str[1024];
-       snprintf(str, 1024, "%ld", value);
+       char str[64];
+       snprintf(str, sizeof(str), "%ld", value);
        return add_property(name, str);
 }
 
@@ -411,7 +415,9 @@ void
 XMLNode::remove_property(const string& n)
 {
        if (_propmap.find(n) != _propmap.end()) {
-               _proplist.remove(_propmap[n]);
+               XMLProperty* p = _propmap[n];
+               _proplist.remove (p);
+               delete p;
                _propmap.erase(n);
        }
 }
@@ -587,3 +593,17 @@ static XMLSharedNodeList* find_impl(xmlXPathContext* ctxt, const string& xpath)
        return nodes;
 }
 
+/** Dump a node, its properties and children to a stream */
+void
+XMLNode::dump (ostream& s, string p) const
+{
+       s << p << _name << " ";
+       for (XMLPropertyList::const_iterator i = _proplist.begin(); i != _proplist.end(); ++i) {
+               s << (*i)->name() << "=" << (*i)->value() << " ";
+       }
+       s << "\n";
+       
+       for (XMLNodeList::const_iterator i = _children.begin(); i != _children.end(); ++i) {
+               (*i)->dump (s, p + "  ");
+       }
+}