diff options
author | Peter Powell <petpow@saberuk.com> | 2017-07-12 16:41:28 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-07-12 16:41:28 +0100 |
commit | 7851faac62d7a83c94cd5d37e0109b5d0a152bf9 (patch) | |
tree | a5140013cb0e0d8c1a2f484645a32001a4bc808c /src/configparser.cpp | |
parent | 834c94679b7df475e50d87ccb11311e297a78718 (diff) | |
parent | 4b37c612257fa94a790d4698a2660112473599ae (diff) |
Merge pull request #1267 from SaberUK/master+config
Store config values in a map instead of a unique vector of pairs.
Diffstat (limited to 'src/configparser.cpp')
-rw-r--r-- | src/configparser.cpp | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/configparser.cpp b/src/configparser.cpp index 8bf9aaec2..7c03fe58a 100644 --- a/src/configparser.cpp +++ b/src/configparser.cpp @@ -91,7 +91,7 @@ struct Parser unget(ch); } - bool kv(std::vector<KeyVal>* items, std::set<std::string>& seen) + bool kv(ConfigItems* items) { std::string key; nextword(key); @@ -177,10 +177,10 @@ struct Parser value.push_back(ch); } - if (!seen.insert(key).second) + if (items->find(key) != items->end()) throw CoreException("Duplicate key '" + key + "' found"); - items->push_back(KeyVal(key, value)); + (*items)[key] = value; return true; } @@ -199,11 +199,10 @@ struct Parser if (name.empty()) throw CoreException("Empty tag name"); - std::vector<KeyVal>* items; - std::set<std::string> seen; + ConfigItems* items; tag = ConfigTag::create(name, current.filename, current.line, items); - while (kv(items, seen)) + while (kv(items)) { // Do nothing here (silences a GCC warning). } @@ -220,14 +219,14 @@ struct Parser } else if (name == "files") { - for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++) + for(ConfigItems::iterator i = items->begin(); i != items->end(); i++) { stack.DoReadFile(i->first, i->second, flags, false); } } else if (name == "execfiles") { - for(std::vector<KeyVal>::iterator i = items->begin(); i != items->end(); i++) + for(ConfigItems::iterator i = items->begin(); i != items->end(); i++) { stack.DoReadFile(i->first, i->second, flags, true); } @@ -385,7 +384,7 @@ bool ParseStack::ParseFile(const std::string& path, int flags, const std::string bool ConfigTag::readString(const std::string& key, std::string& value, bool allow_lf) { - for(std::vector<KeyVal>::iterator j = items.begin(); j != items.end(); ++j) + for(ConfigItems::iterator j = items.begin(); j != items.end(); ++j) { if(j->first != key) continue; @@ -488,7 +487,7 @@ std::string ConfigTag::getTagLocation() return src_name + ":" + ConvToStr(src_line); } -ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, std::vector<KeyVal>*& Items) +ConfigTag* ConfigTag::create(const std::string& Tag, const std::string& file, int line, ConfigItems*& Items) { ConfigTag* rv = new ConfigTag(Tag, file, line); Items = &rv->items; |