diff options
author | Jonas Suhr Christensen <jsc@umbraculum.org> | 2018-06-09 18:26:06 +0200 |
---|---|---|
committer | Bent Bisballe Nyeng <deva@aasimon.org> | 2018-08-12 11:11:40 +0200 |
commit | 3e058d4aa4ca014cefb61219f648925343611433 (patch) | |
tree | d97ea8e1b7ea52b0c442cad60eb097c07e4b2f77 /src | |
parent | e8a3b1ffacb7b0ff42fd86fd532f7a2908c224e9 (diff) |
dgxml fixup
Diffstat (limited to 'src')
-rw-r--r-- | src/dgxmlparser.cc | 36 |
1 files changed, 27 insertions, 9 deletions
diff --git a/src/dgxmlparser.cc b/src/dgxmlparser.cc index 9193101..016ad60 100644 --- a/src/dgxmlparser.cc +++ b/src/dgxmlparser.cc @@ -27,7 +27,9 @@ #include "dgxmlparser.h" #include <unordered_map> + #include <pugixml.hpp> +#include <hugin.hpp> #include "nolocale.h" @@ -43,31 +45,42 @@ bool probeInstrumentFile(const std::string& filename) return parseInstrumentFile(filename, d); } -static bool assign(double& dest, std::string val) +static bool assign(double& dest, const std::string& val) { + //TODO: figure out how to handle error value 0.0 dest = atof_nol(val.c_str()); - return dest > 0; + return true; } -static bool assign(std::string& dest, std::string val) +static bool assign(std::string& dest, const std::string& val) { dest = val; return true; } -static bool assign(size_t& dest, std::string val) +static bool assign(size_t& dest, const std::string& val) { - dest = atoi(val.c_str()); - return dest > 0; + int tmp = atoi(val.c_str()); + if(tmp < 0) return false; + dest = tmp; + return std::to_string(dest) == val; } template<typename T> -static bool attrcpy(T& dest, const pugi::xml_node& src, const std::string attr) +static bool attrcpy(T& dest, const pugi::xml_node& src, const std::string& attr) { const char* val = src.attribute(attr.c_str()).as_string(nullptr); - if(!val) return false; + if(!val) { + ERR("Attribute %s not found in %s, offset %s\n", attr.c_str(), src.path().c_str(), (int) src.offset_debug()); + return false; + } + + if(!assign(dest, std::string(val))) { + ERR("Attribute %s could not be assigned, offset %s\n", attr.c_str(), (int) src.offset_debug()); + return false; + } - return assign(dest, std::string(val)); + return true; } bool parseDrumkitFile(const std::string& filename, DrumkitDOM& dom) @@ -78,6 +91,11 @@ bool parseDrumkitFile(const std::string& filename, DrumkitDOM& dom) pugi::xml_parse_result result = doc.load_file(filename.c_str()); res &= !result.status; + if(!res) { + printf("PugiXml error %d\n", (int) result.offset); + return false; + } + //TODO: handle xml version pugi::xml_node drumkit = doc.child("drumkit"); |