From e8fcde7654f2d7dce494ebe1ca27abbebc3908b4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20Nusser?= Date: Wed, 23 Mar 2016 15:59:41 +0100 Subject: Make attr a const ref. --- src/configparser.cc | 6 +++--- src/configparser.h | 2 +- src/drumkitparser.cc | 21 ++++++++++----------- src/drumkitparser.h | 2 +- src/instrumentparser.cc | 24 ++++++++++++------------ src/instrumentparser.h | 2 +- src/midimapparser.cc | 4 ++-- src/midimapparser.h | 2 +- src/saxparser.h | 2 +- 9 files changed, 32 insertions(+), 33 deletions(-) diff --git a/src/configparser.cc b/src/configparser.cc index e8a6d12..4bb5c45 100644 --- a/src/configparser.cc +++ b/src/configparser.cc @@ -43,12 +43,12 @@ void ConfigParser::characterData(const std::string& data) } } -void ConfigParser::startTag(const std::string& name, attr_t& attr) +void ConfigParser::startTag(const std::string& name, const attr_t& attr) { if(name == "value" && attr.find("name") != attr.end()) { - values[attr["name"]] = ""; - str = &values[attr["name"]]; + values[attr.at("name")] = ""; + str = &values[attr.at("name")]; } } diff --git a/src/configparser.h b/src/configparser.h index b33af85..ac1b5bb 100644 --- a/src/configparser.h +++ b/src/configparser.h @@ -37,7 +37,7 @@ public: ConfigParser(); void characterData(const std::string& data) override; - void startTag(const std::string& name, attr_t& attr) override; + void startTag(const std::string& name, const attr_t& attr) override; void endTag(const std::string& name) override; std::string value(const std::string& name, const std::string& def = ""); diff --git a/src/drumkitparser.cc b/src/drumkitparser.cc index 7f798a8..510bb53 100644 --- a/src/drumkitparser.cc +++ b/src/drumkitparser.cc @@ -76,19 +76,18 @@ DrumKitParser::~DrumKitParser() } -void DrumKitParser::startTag(const std::string& name, - attr_t& attr) +void DrumKitParser::startTag(const std::string& name, const attr_t& attr) { if(name == "drumkit") { if(attr.find("name") != attr.end()) { - kit._name = attr["name"]; + kit._name = attr.at("name"); } if(attr.find("samplerate") != attr.end()) { - kit._samplerate = std::stoi(attr["samplerate"]); + kit._samplerate = std::stoi(attr.at("samplerate")); } else { @@ -99,14 +98,14 @@ void DrumKitParser::startTag(const std::string& name, if(attr.find("description") != attr.end()) { - kit._description = attr["description"]; + kit._description = attr.at("description"); } if(attr.find("version") != attr.end()) { try { - kit._version = VersionStr(attr["version"]); + kit._version = VersionStr(attr.at("version")); } catch(const char *err) { @@ -134,7 +133,7 @@ void DrumKitParser::startTag(const std::string& name, return; } - Channel c(attr["name"]); + Channel c(attr.at("name")); c.num = kit.channels.size(); kit.channels.push_back(c); } @@ -157,11 +156,11 @@ void DrumKitParser::startTag(const std::string& name, return; } - instr_name = attr["name"]; - instr_file = attr["file"]; + instr_name = attr.at("name"); + instr_file = attr.at("file"); if(attr.find("group") != attr.end()) { - instr_group = attr["group"]; + instr_group = attr.at("group"); } else { @@ -183,7 +182,7 @@ void DrumKitParser::startTag(const std::string& name, return; } - channelmap[attr["in"]] = attr["out"]; + channelmap[attr.at("in")] = attr.at("out"); } } diff --git a/src/drumkitparser.h b/src/drumkitparser.h index 5c97b4e..2344261 100644 --- a/src/drumkitparser.h +++ b/src/drumkitparser.h @@ -38,7 +38,7 @@ public: ~DrumKitParser(); protected: - void startTag(const std::string& name, attr_t& attributes) override; + void startTag(const std::string& name, const attr_t& attributes) override; void endTag(const std::string& name) override; int readData(std::string& data, std::size_t size) override; diff --git a/src/instrumentparser.cc b/src/instrumentparser.cc index 3b849e1..3c34b9f 100644 --- a/src/instrumentparser.cc +++ b/src/instrumentparser.cc @@ -57,24 +57,24 @@ InstrumentParser::~InstrumentParser() } } -void InstrumentParser::startTag(const std::string& name, attr_t& attr) +void InstrumentParser::startTag(const std::string& name, const attr_t& attr) { if(name == "instrument") { if(attr.find("name") != attr.end()) { - instrument._name = attr["name"]; + instrument._name = attr.at("name"); } if(attr.find("description") != attr.end()) { - instrument._description = attr["description"]; + instrument._description = attr.at("description"); } if(attr.find("version") != attr.end()) { try { - instrument.version = VersionStr(attr["version"]); + instrument.version = VersionStr(attr.at("version")); } catch(const char *err) { @@ -109,12 +109,12 @@ void InstrumentParser::startTag(const std::string& name, attr_t& attr) } else { - power = atof_nol(attr["power"].c_str()); + power = atof_nol(attr.at("power").c_str()); DEBUG(instrparser, "Instrument power set to %f\n", power); } // TODO get rid of new or delete it properly - s = new Sample(attr["name"], power); + s = new Sample(attr.at("name"), power); } if(name == "audiofile") @@ -140,7 +140,7 @@ void InstrumentParser::startTag(const std::string& name, attr_t& attr) int filechannel = 1; // default, override with optional attribute if(attr.find("filechannel") != attr.end()) { - filechannel = std::stoi(attr["filechannel"]); + filechannel = std::stoi(attr.at("filechannel")); if(filechannel < 1) { ERR(instrparser,"Invalid value for attribute 'filechannel'.\n"); @@ -150,8 +150,8 @@ void InstrumentParser::startTag(const std::string& name, attr_t& attr) filechannel = filechannel - 1; // 1-based in file, but zero-based internally // TODO do those next two lines correspond with proper deletes? If not fix it. - AudioFile *af = new AudioFile(path + "/" + attr["file"], filechannel); - InstrumentChannel *ch = new InstrumentChannel(attr["channel"]); + AudioFile *af = new AudioFile(path + "/" + attr.at("file"), filechannel); + InstrumentChannel *ch = new InstrumentChannel(attr.at("channel")); channellist.push_back(ch); s->addAudioFile(ch, af); instrument.audiofiles.push_back(af); @@ -176,8 +176,8 @@ void InstrumentParser::startTag(const std::string& name, attr_t& attr) return; } - lower = atof_nol(attr["lower"].c_str()); - upper = atof_nol(attr["upper"].c_str()); + lower = atof_nol(attr.at("lower").c_str()); + upper = atof_nol(attr.at("upper").c_str()); } if(name == "sampleref") @@ -192,7 +192,7 @@ void InstrumentParser::startTag(const std::string& name, attr_t& attr) std::vector::iterator i = instrument.samplelist.begin(); while(i != instrument.samplelist.end()) { - if((*i)->name == attr["name"]) + if((*i)->name == attr.at("name")) { sample = *i; break; diff --git a/src/instrumentparser.h b/src/instrumentparser.h index 15fadef..50e05ef 100644 --- a/src/instrumentparser.h +++ b/src/instrumentparser.h @@ -43,7 +43,7 @@ public: protected: int readData(std::string& data, std::size_t size) override; - virtual void startTag(const std::string& name, attr_t& attr) override; + virtual void startTag(const std::string& name, const attr_t& attr) override; virtual void endTag(const std::string& name) override; private: diff --git a/src/midimapparser.cc b/src/midimapparser.cc index f66d063..e847c58 100644 --- a/src/midimapparser.cc +++ b/src/midimapparser.cc @@ -39,13 +39,13 @@ MidiMapParser::~MidiMapParser() } } -void MidiMapParser::startTag(const std::string& name, attr_t& attr) +void MidiMapParser::startTag(const std::string& name, const attr_t& attr) { if(name == "map") { if(attr.find("note") != attr.end() && attr.find("instr") != attr.end()) { - midimap[std::stoi(attr["note"])] = attr["instr"]; + midimap[std::stoi(attr.at("note"))] = attr.at("instr"); } } } diff --git a/src/midimapparser.h b/src/midimapparser.h index 67a0b4a..1a3dde0 100644 --- a/src/midimapparser.h +++ b/src/midimapparser.h @@ -38,7 +38,7 @@ public: MidiMapParser(const std::string& file); ~MidiMapParser(); - void startTag(const std::string& name, attr_t& attr) override; + void startTag(const std::string& name, const attr_t& attr) override; midimap_t midimap; diff --git a/src/saxparser.h b/src/saxparser.h index 680df1d..8664cb0 100644 --- a/src/saxparser.h +++ b/src/saxparser.h @@ -45,7 +45,7 @@ protected: using attr_t = std::map; virtual void characterData(const std::string& data) {} - virtual void startTag(const std::string& name, attr_t& attr) {} + virtual void startTag(const std::string& name, const attr_t& attr) {} virtual void endTag(const std::string& name) {} virtual void parseError(const std::string& buf, std::size_t len, const std::string& error, std::size_t lineno); -- cgit v1.2.3