summaryrefslogtreecommitdiff
path: root/src/midimapparser.cc
diff options
context:
space:
mode:
authorAndré Nusser <andre.nusser@googlemail.com>2016-03-22 00:40:15 +0100
committerAndré Nusser <andre.nusser@googlemail.com>2016-03-29 22:19:49 +0200
commit0930fdc014bf36fb9e2715b3d14bff5fedf354a9 (patch)
tree9136c06ba9311f164e03156312ed449367acf20a /src/midimapparser.cc
parent866b09992668f97af063dcd77dc5dd0e3a512b94 (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.cc36
1 files changed, 24 insertions, 12 deletions
diff --git a/src/midimapparser.cc b/src/midimapparser.cc
index 8dabb05..2d4563a 100644
--- a/src/midimapparser.cc
+++ b/src/midimapparser.cc
@@ -26,27 +26,39 @@
*/
#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;
+ }
+
+ 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;
}