diff options
author | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-03-17 17:58:53 +0100 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2019-03-17 17:58:53 +0100 |
commit | d0b501dd1c0dd84428903cf08730838bb8889bbf (patch) | |
tree | 9bbbde95fb2e7dc7627320a147a37a30d95cb207 /src | |
parent | 3877ec05e123ce3d904b72f0105b170b2aa74599 (diff) |
Add version number to config xml (version="1.0" only for now).
Diffstat (limited to 'src')
-rw-r--r-- | src/configparser.cc | 40 |
1 files changed, 40 insertions, 0 deletions
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(); |