diff options
author | Eugene Sandulenko | 2006-03-07 02:23:37 +0000 |
---|---|---|
committer | Eugene Sandulenko | 2006-03-07 02:23:37 +0000 |
commit | 4c16b73bd1181f1e7daa5ff206af153ae2ef7b7f (patch) | |
tree | 22521ab000590ae8f718da5cef500dceab5805ee | |
parent | 44f3879f58a1e46e5e5c6639970cf2d3c5bce3ea (diff) | |
download | scummvm-rg350-4c16b73bd1181f1e7daa5ff206af153ae2ef7b7f.tar.gz scummvm-rg350-4c16b73bd1181f1e7daa5ff206af153ae2ef7b7f.tar.bz2 scummvm-rg350-4c16b73bd1181f1e7daa5ff206af153ae2ef7b7f.zip |
o Properly react to end-of-file is loadFromStream()
o Add types SectionList and SectionKeyList
o Implement getKeys() method
svn-id: r21114
-rw-r--r-- | common/config-file.cpp | 8 | ||||
-rw-r--r-- | common/config-file.h | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/common/config-file.cpp b/common/config-file.cpp index f47c81c95f..a5ef6a17ba 100644 --- a/common/config-file.cpp +++ b/common/config-file.cpp @@ -165,7 +165,7 @@ bool ConfigFile::loadFromStream(SeekableReadStream &stream) { if (!section.name.isEmpty()) _sections.push_back(section); - return !stream.ioFailed(); + return (!stream.ioFailed() || stream.eos()); } bool ConfigFile::saveToFile(const String &filename) { @@ -295,6 +295,12 @@ void ConfigFile::setKey(const String &key, const String §ion, const String & } } +const ConfigFile::SectionKeyList ConfigFile::getKeys(const String §ion) const { + const Section *s = getSection(section); + + return s->getKeys(); +} + ConfigFile::Section *ConfigFile::getSection(const String §ion) { for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) { if (!scumm_stricmp(section.c_str(), i->name.c_str())) { diff --git a/common/config-file.h b/common/config-file.h index d0d22630ac..8b8b135232 100644 --- a/common/config-file.h +++ b/common/config-file.h @@ -59,6 +59,8 @@ public: String comment; }; + typedef List<KeyValue> SectionKeyList; + /** A section in a config file. I.e. corresponds to something like this: * [mySection] * key=value @@ -75,8 +77,11 @@ public: const KeyValue* getKey(const String &key) const; void setKey(const String &key, const String &value); void removeKey(const String &key); + const SectionKeyList getKeys() const { return keys; } }; + typedef List<Section> SectionList; + public: ConfigFile(); ~ConfigFile(); @@ -108,12 +113,14 @@ public: void setKey(const String &key, const String §ion, const String &value); void removeKey(const String &key, const String §ion); + const SectionList getSections() const { return _sections; } + const SectionKeyList getKeys(const String §ion) const; void listSections(StringSet &set); void listKeyValues(StringMap &kv); private: - List<Section> _sections; + SectionList _sections; Section *getSection(const String §ion); const Section *getSection(const String §ion) const; |