From 8c585aa006741b95c1175afcdb01cdd3d8d2d7db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Wed, 23 Mar 2016 18:24:29 +0100 Subject: Do the file related actions in SAXParser. --- src/drumkitparser.cc | 56 +++++++++++++++------------------------------------- 1 file changed, 16 insertions(+), 40 deletions(-) (limited to 'src/drumkitparser.cc') diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc index 2d0262d..595cd41 100644 --- a/src/drumkitparser.cc +++ b/src/drumkitparser.cc @@ -34,17 +34,21 @@ #include "path.h" #include "drumgizmo.h" -DrumKitParser::DrumKitParser(const std::string& file, DrumKit& k) - : kit(k) +DrumKitParser::DrumKitParser(DrumKit& kit) + : kit(kit) , refs(REFSFILE) { - std::string kitfile = file; +} + +int DrumKitParser::parseFile(const std::string& filename) +{ + auto edited_filename(filename); if(refs.load()) { - if(file.size() > 1 && file[0] == '@') + if(filename.size() > 1 && filename[0] == '@') { - kitfile = refs.getValue(file.substr(1)); + edited_filename = refs.getValue(filename.substr(1)); } } else @@ -52,28 +56,14 @@ DrumKitParser::DrumKitParser(const std::string& file, DrumKit& k) ERR(drumkitparser, "Error reading refs.conf"); } - // instr = NULL; - path = getPath(kitfile); - - fd = fopen(kitfile.c_str(), "r"); - - // DEBUG(kitparser, "Parsing drumkit in %s\n", kitfile.c_str()); - - if(!fd) - { - return; - } - - kit._file = file; -} + path = getPath(edited_filename); + auto result = SAXParser::parseFile(filename); -DrumKitParser::~DrumKitParser() -{ - if(fd) - { - fclose(fd); + if (result == 0) { + kit._file = edited_filename; } + return result; } void DrumKitParser::startTag(const std::string& name, const attr_t& attr) @@ -193,8 +183,8 @@ void DrumKitParser::endTag(const std::string& name) Instrument* i = new Instrument(); i->setGroup(instr_group); // Instrument &i = kit.instruments[kit.instruments.size() - 1]; - InstrumentParser parser(path + "/" + instr_file, *i); - parser.parse(); + InstrumentParser parser(*i); + parser.parseFile(path + "/" + instr_file); kit.instruments.push_back(i); // Assign kit channel numbers to instruments channels. @@ -233,17 +223,3 @@ void DrumKitParser::endTag(const std::string& name) channelmap.clear(); } } - -int DrumKitParser::readData(std::string& data, std::size_t size) -{ - if(!fd) - { - return -1; - } - - data.resize(size); - auto nr_of_bytes_read = fread((void*)data.data(), 1, size, fd); - data.resize(nr_of_bytes_read); - return nr_of_bytes_read; - return fread((char*)data.c_str(), 1, size, fd); -} -- cgit v1.2.3