diff options
author | André Nusser <andre.nusser@googlemail.com> | 2016-03-22 00:40:15 +0100 |
---|---|---|
committer | André Nusser <andre.nusser@googlemail.com> | 2016-03-22 17:16:03 +0100 |
commit | 0728a11284f15100a8f8e0d9da0192019a056d6a (patch) | |
tree | dd430619bc74314ae21941102f1f1f92769d9ddc /src/midimapparser.cc | |
parent | 8e2124ad955b51efb2f539998a369d7ca07cbc73 (diff) |
Parser refactoring.
* Use new style
* Update to C++11
* Use more std::string than char*
Diffstat (limited to 'src/midimapparser.cc')
-rw-r--r-- | src/midimapparser.cc | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/src/midimapparser.cc b/src/midimapparser.cc index e81b871..3c8eed4 100644 --- a/src/midimapparser.cc +++ b/src/midimapparser.cc @@ -26,27 +26,36 @@ */ #include "midimapparser.h" -MidiMapParser::MidiMapParser(std::string file) +MidiMapParser::MidiMapParser(const std::string& file) { - fd = fopen(file.c_str(), "r"); + fd = fopen(file.c_str(), "r"); } MidiMapParser::~MidiMapParser() { - if(fd) fclose(fd); + if(fd) + { + fclose(fd); + } } -void MidiMapParser::startTag(std::string name, attr_t attr) +void MidiMapParser::startTag(const std::string& name, attr_t& attr) { - if(name == "map") { - if(attr.find("note") != attr.end() && attr.find("instr") != attr.end()) { - midimap[atoi(attr["note"].c_str())] = attr["instr"]; - } - } + if(name == "map") + { + if(attr.find("note") != attr.end() && attr.find("instr") != attr.end()) + { + midimap[std::stoi(attr["note"])] = attr["instr"]; + } + } } -int MidiMapParser::readData(char *data, size_t size) +int MidiMapParser::readData(std::string& data, std::size_t size) { - if(!fd) return -1; - return fread(data, 1, size, fd); + if(!fd) + { + return -1; + } + + return fread((char*)data.c_str(), 1, size, fd); } |