o Properly react to end-of-file is loadFromStream()

o Add types SectionList and SectionKeyList
o Implement getKeys() method

svn-id: r21114
This commit is contained in:
Eugene Sandulenko 2006-03-07 02:23:37 +00:00
parent 44f3879f58
commit 4c16b73bd1
2 changed files with 15 additions and 2 deletions

View File

@ -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 &section, const String &
}
}
const ConfigFile::SectionKeyList ConfigFile::getKeys(const String &section) const {
const Section *s = getSection(section);
return s->getKeys();
}
ConfigFile::Section *ConfigFile::getSection(const String &section) {
for (List<Section>::iterator i = _sections.begin(); i != _sections.end(); ++i) {
if (!scumm_stricmp(section.c_str(), i->name.c_str())) {

View File

@ -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 &section, const String &value);
void removeKey(const String &key, const String &section);
const SectionList getSections() const { return _sections; }
const SectionKeyList getKeys(const String &section) const;
void listSections(StringSet &set);
void listKeyValues(StringMap &kv);
private:
List<Section> _sections;
SectionList _sections;
Section *getSection(const String &section);
const Section *getSection(const String &section) const;