ScummVM API documentation
ini-file.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef COMMON_INI_FILE_H
23#define COMMON_INI_FILE_H
24
25#include "common/hash-str.h"
26#include "common/list.h"
27#include "common/path.h"
28#include "common/str.h"
29
30namespace Common {
31
42class SeekableReadStream;
43class WriteStream;
44
58class INIFile {
59public:
60 struct KeyValue {
64 };
65
78 struct Section {
83 bool hasKey(const String &key) const;
84 const KeyValue* getKey(const String &key) const;
85 void setKey(const String &key, const String &value);
86 void removeKey(const String &key);
87 const SectionKeyList getKeys() const { return keys; }
88 };
89
92public:
93 INIFile();
94 ~INIFile() {}
95
96 // TODO: Maybe add a copy constructor etc.?
97
104 bool isValidName(const String &name) const;
105
107 void clear();
108
109 bool loadFromFile(const Path &filename);
110 bool loadFromFileOrDataFork(const Path &filename);
111 bool loadFromSaveFile(const String &filename);
113 bool saveToFile(const Path &filename);
114 bool saveToSaveFile(const String &filename);
115 bool saveToStream(WriteStream &stream);
117 bool hasSection(const String &section) const;
118 void addSection(const String &section);
119 void removeSection(const String &section);
120 void renameSection(const String &oldName, const String &newName);
122 void setDefaultSectionName(const String &name);
124 bool hasKey(const String &key, const String &section) const;
125 bool getKey(const String &key, const String &section, String &value) const;
126 void setKey(const String &key, const String &section, const String &value);
127 void removeKey(const String &key, const String &section);
129 const SectionList getSections() const { return _sections; }
130 const SectionKeyList getKeys(const String &section) const;
148
149private:
150 String _defaultSectionName;
151 SectionList _sections;
152 bool _allowNonEnglishCharacters;
153 bool _suppressValuelessLineWarning;
154 bool _requireKeyValueDelimiter;
155
156 Section *getSection(const String &section);
157 const Section *getSection(const String &section) const;
158 bool isValidChar(char c) const;
159};
160
163} // End of namespace Common
164
165#endif
Definition: ini-file.h:58
void addSection(const String &section)
const SectionKeyList getKeys(const String &section) const
void suppressValuelessLineWarning()
const SectionList getSections() const
Definition: ini-file.h:129
bool loadFromStream(SeekableReadStream &stream)
void allowNonEnglishCharacters()
void requireKeyValueDelimiter()
void setDefaultSectionName(const String &name)
void removeSection(const String &section)
void setKey(const String &key, const String &section, const String &value)
void listKeyValues(StringMap &kv)
List< KeyValue > SectionKeyList
Definition: ini-file.h:66
bool hasKey(const String &key, const String &section) const
void renameSection(const String &oldName, const String &newName)
bool loadFromFileOrDataFork(const Path &filename)
void removeKey(const String &key, const String &section)
List< Section > SectionList
Definition: ini-file.h:90
bool saveToStream(WriteStream &stream)
bool loadFromSaveFile(const String &filename)
bool saveToSaveFile(const String &filename)
bool hasSection(const String &section) const
bool isValidName(const String &name) const
bool loadFromFile(const Path &filename)
bool saveToFile(const Path &filename)
bool getKey(const String &key, const String &section, String &value) const
Definition: list.h:44
Definition: path.h:52
Definition: stream.h:745
Definition: str.h:59
Definition: stream.h:77
Definition: algorithm.h:29
Definition: ini-file.h:60
String value
Definition: ini-file.h:62
String key
Definition: ini-file.h:61
String comment
Definition: ini-file.h:63
Definition: ini-file.h:78
const KeyValue * getKey(const String &key) const
List< KeyValue > keys
Definition: ini-file.h:80
String comment
Definition: ini-file.h:81
void setKey(const String &key, const String &value)
String name
Definition: ini-file.h:79
const SectionKeyList getKeys() const
Definition: ini-file.h:87
void removeKey(const String &key)
bool hasKey(const String &key) const