summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBent Bisballe Nyeng <deva@aasimon.org>2019-03-17 17:58:53 +0100
committerBent Bisballe Nyeng <deva@aasimon.org>2019-03-17 17:58:53 +0100
commitd0b501dd1c0dd84428903cf08730838bb8889bbf (patch)
tree9bbbde95fb2e7dc7627320a147a37a30d95cb207
parent3877ec05e123ce3d904b72f0105b170b2aa74599 (diff)
Add version number to config xml (version="1.0" only for now).
-rw-r--r--plugin/drumgizmo_plugin.cc2
-rw-r--r--src/configparser.cc40
2 files changed, 41 insertions, 1 deletions
diff --git a/plugin/drumgizmo_plugin.cc b/plugin/drumgizmo_plugin.cc
index d8130f3..3328f6b 100644
--- a/plugin/drumgizmo_plugin.cc
+++ b/plugin/drumgizmo_plugin.cc
@@ -580,7 +580,7 @@ DrumGizmoPlugin::ConfigStringIO::ConfigStringIO(Settings& settings)
std::string DrumGizmoPlugin::ConfigStringIO::get()
{
return
- "<config>\n"
+ "<config version=\"1.0\">\n"
" <value name=\"drumkitfile\">" + settings.drumkit_file.load() + "</value>\n"
" <value name=\"midimapfile\">" + settings.midimap_file.load() + "</value>\n"
" <value name=\"enable_velocity_modifier\">" +
diff --git a/src/configparser.cc b/src/configparser.cc
index 30b981f..6906236 100644
--- a/src/configparser.cc
+++ b/src/configparser.cc
@@ -29,6 +29,36 @@
#include <hugin.hpp>
#include <pugixml.hpp>
+static bool assign(std::string& dest, const std::string& val)
+{
+ dest = val;
+ return true;
+}
+
+template<typename T>
+static bool attrcpy(T& dest, const pugi::xml_node& src, const std::string& attr, bool opt = false)
+{
+ const char* val = src.attribute(attr.c_str()).as_string(nullptr);
+ if(!val)
+ {
+ if(!opt)
+ {
+ ERR(configparser, "Attribute %s not found in %s, offset %d\n",
+ attr.data(), src.path().data(), (int)src.offset_debug());
+ }
+ return opt;
+ }
+
+ if(!assign(dest, std::string(val)))
+ {
+ ERR(configparser, "Attribute %s could not be assigned, offset %d\n",
+ attr.data(), (int)src.offset_debug());
+ return false;
+ }
+
+ return true;
+}
+
bool ConfigParser::parseString(const std::string& xml)
{
pugi::xml_document doc;
@@ -40,6 +70,16 @@ bool ConfigParser::parseString(const std::string& xml)
}
pugi::xml_node config_node = doc.child("config");
+
+ // Config xml without the version tag defaults to 1.0
+ std::string version = "1.0";
+ attrcpy(version, config_node, "version", true);
+ if(version != "1.0")
+ {
+ ERR(configparser, "Only config v1.0 XML supported.");
+ return false;
+ }
+
for(pugi::xml_node value_node : config_node.children("value"))
{
auto name = value_node.attribute("name").as_string();