From d0b501dd1c0dd84428903cf08730838bb8889bbf Mon Sep 17 00:00:00 2001 From: Bent Bisballe Nyeng Date: Sun, 17 Mar 2019 17:58:53 +0100 Subject: Add version number to config xml (version="1.0" only for now). --- plugin/drumgizmo_plugin.cc | 2 +- src/configparser.cc | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) 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 - "\n" + "\n" " " + settings.drumkit_file.load() + "\n" " " + settings.midimap_file.load() + "\n" " " + 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 #include +static bool assign(std::string& dest, const std::string& val) +{ + dest = val; + return true; +} + +template +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(); -- cgit v1.2.3