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 
30 namespace Common {
31 
42 class SeekableReadStream;
43 class WriteStream;
44 
58 class INIFile {
59 public:
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 
92 public:
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);
112  bool loadFromStream(SeekableReadStream &stream);
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;
132  void listKeyValues(StringMap &kv);
148 
149 private:
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
bool hasSection(const String &section) const
const SectionKeyList getKeys() const
Definition: ini-file.h:87
bool hasKey(const String &key, const String &section) const
Definition: str.h:59
bool getKey(const String &key, const String &section, String &value) const
const SectionList getSections() const
Definition: ini-file.h:129
Definition: stream.h:77
List< Section > SectionList
Definition: ini-file.h:90
bool loadFromFileOrDataFork(const Path &filename)
Definition: list.h:44
void setDefaultSectionName(const String &name)
Definition: path.h:52
bool saveToSaveFile(const String &filename)
Definition: stream.h:745
List< KeyValue > keys
Definition: ini-file.h:80
String name
Definition: ini-file.h:79
void requireKeyValueDelimiter()
bool saveToFile(const Path &filename)
void removeSection(const String &section)
bool saveToStream(WriteStream &stream)
bool isValidName(const String &name) const
Definition: ini-file.h:60
void renameSection(const String &oldName, const String &newName)
bool loadFromFile(const Path &filename)
void setKey(const String &key, const String &section, const String &value)
Definition: algorithm.h:29
void listKeyValues(StringMap &kv)
String value
Definition: ini-file.h:62
String comment
Definition: ini-file.h:81
bool loadFromSaveFile(const String &filename)
void suppressValuelessLineWarning()
Definition: ini-file.h:58
String key
Definition: ini-file.h:61
bool loadFromStream(SeekableReadStream &stream)
Definition: ini-file.h:78
List< KeyValue > SectionKeyList
Definition: ini-file.h:66
void allowNonEnglishCharacters()
const SectionKeyList getKeys(const String &section) const
void addSection(const String &section)
String comment
Definition: ini-file.h:63
void removeKey(const String &key, const String &section)