comparison plugin/PluginXml.cpp @ 314:70a232b1f12a

* Make XmlExportable::toXml the function that is universally overridden (and pure virtual) instead of toXmlString. Tidies up some classes, notably the model classes, significantly. Closes #1794561.
author Chris Cannam
date Thu, 18 Oct 2007 10:15:07 +0000
parents d4a33cdca86f
children a70dcfed59c1
comparison
equal deleted inserted replaced
313:29485aa03da4 314:70a232b1f12a
21 #include <QDomDocument> 21 #include <QDomDocument>
22 #include <QDomElement> 22 #include <QDomElement>
23 #include <QDomNamedNodeMap> 23 #include <QDomNamedNodeMap>
24 #include <QDomAttr> 24 #include <QDomAttr>
25 25
26 #include <QTextStream>
27
26 #include "vamp-sdk/PluginBase.h" 28 #include "vamp-sdk/PluginBase.h"
27 #include "RealTimePluginInstance.h" 29 #include "RealTimePluginInstance.h"
28 30
29 #include <iostream> 31 #include <iostream>
30 32
51 rv.replace("[[SEMICOLON]]", ";"); 53 rv.replace("[[SEMICOLON]]", ";");
52 rv.replace("[[EQUALS]]", "="); 54 rv.replace("[[EQUALS]]", "=");
53 return rv; 55 return rv;
54 } 56 }
55 57
56 QString 58 void
57 PluginXml::toXmlString(QString indent, QString extraAttributes) const 59 PluginXml::toXml(QTextStream &stream,
58 { 60 QString indent, QString extraAttributes) const
59 QString s; 61 {
60 s += indent; 62 stream << indent;
61 63
62 s += QString("<plugin identifier=\"%1\" name=\"%2\" description=\"%3\" maker=\"%4\" version=\"%5\" copyright=\"%6\" %7 ") 64 stream << QString("<plugin identifier=\"%1\" name=\"%2\" description=\"%3\" maker=\"%4\" version=\"%5\" copyright=\"%6\" %7 ")
63 .arg(encodeEntities(QString(m_plugin->getIdentifier().c_str()))) 65 .arg(encodeEntities(QString(m_plugin->getIdentifier().c_str())))
64 .arg(encodeEntities(QString(m_plugin->getName().c_str()))) 66 .arg(encodeEntities(QString(m_plugin->getName().c_str())))
65 .arg(encodeEntities(QString(m_plugin->getDescription().c_str()))) 67 .arg(encodeEntities(QString(m_plugin->getDescription().c_str())))
66 .arg(encodeEntities(QString(m_plugin->getMaker().c_str()))) 68 .arg(encodeEntities(QString(m_plugin->getMaker().c_str())))
67 .arg(m_plugin->getPluginVersion()) 69 .arg(m_plugin->getPluginVersion())
68 .arg(encodeEntities(QString(m_plugin->getCopyright().c_str()))) 70 .arg(encodeEntities(QString(m_plugin->getCopyright().c_str())))
69 .arg(extraAttributes); 71 .arg(extraAttributes);
70 72
71 if (!m_plugin->getPrograms().empty()) { 73 if (!m_plugin->getPrograms().empty()) {
72 s += QString("program=\"%1\" ") 74 stream << QString("program=\"%1\" ")
73 .arg(encodeEntities(m_plugin->getCurrentProgram().c_str())); 75 .arg(encodeEntities(m_plugin->getCurrentProgram().c_str()));
74 } 76 }
75 77
76 Vamp::PluginBase::ParameterList parameters = 78 Vamp::PluginBase::ParameterList parameters =
77 m_plugin->getParameterDescriptors(); 79 m_plugin->getParameterDescriptors();
78 80
79 for (Vamp::PluginBase::ParameterList::const_iterator i = parameters.begin(); 81 for (Vamp::PluginBase::ParameterList::const_iterator i = parameters.begin();
80 i != parameters.end(); ++i) { 82 i != parameters.end(); ++i) {
81 83
82 // std::cerr << "PluginXml::toXmlString: parameter name \"" 84 // std::cerr << "PluginXml::toXml: parameter name \""
83 // << i->name.c_str() << "\" has value " 85 // << i->name.c_str() << "\" has value "
84 // << m_plugin->getParameter(i->name) << std::endl; 86 // << m_plugin->getParameter(i->name) << std::endl;
85 87
86 s += QString("param-%1=\"%2\" ") 88 stream << QString("param-%1=\"%2\" ")
87 .arg(stripInvalidParameterNameCharacters(QString(i->identifier.c_str()))) 89 .arg(stripInvalidParameterNameCharacters(QString(i->identifier.c_str())))
88 .arg(m_plugin->getParameter(i->identifier)); 90 .arg(m_plugin->getParameter(i->identifier));
89 } 91 }
90 92
91 RealTimePluginInstance *rtpi = 93 RealTimePluginInstance *rtpi =
102 value = encodeConfigurationChars(value); 104 value = encodeConfigurationChars(value);
103 if (config != "") config += ";"; 105 if (config != "") config += ";";
104 config += QString("%1=%2").arg(key).arg(value); 106 config += QString("%1=%2").arg(key).arg(value);
105 } 107 }
106 if (config != "") { 108 if (config != "") {
107 s += QString("configuration=\"%1\" ") 109 stream << QString("configuration=\"%1\" ")
108 .arg(encodeEntities(config)); 110 .arg(encodeEntities(config));
109 } 111 }
110 } 112 }
111 113
112 s += "/>\n"; 114 stream << "/>\n";
113 return s;
114 } 115 }
115 116
116 #define CHECK_ATTRIBUTE(ATTRIBUTE, ACCESSOR) \ 117 #define CHECK_ATTRIBUTE(ATTRIBUTE, ACCESSOR) \
117 QString ATTRIBUTE = attrs.value(#ATTRIBUTE); \ 118 QString ATTRIBUTE = attrs.value(#ATTRIBUTE); \
118 if (ATTRIBUTE != "" && ATTRIBUTE != ACCESSOR().c_str()) { \ 119 if (ATTRIBUTE != "" && ATTRIBUTE != ACCESSOR().c_str()) { \