ResidualVM logo ResidualVM website - Forums - Contact us BuildBot - Doxygen - Wiki curved edge

ini-file.h

Go to the documentation of this file.
00001 /* ScummVM - Graphic Adventure Engine
00002  *
00003  * ScummVM is the legal property of its developers, whose names
00004  * are too numerous to list here. Please refer to the COPYRIGHT
00005  * file distributed with this source distribution.
00006  *
00007  * This program is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU General Public License
00009  * as published by the Free Software Foundation; either version 2
00010  * of the License, or (at your option) any later version.
00011  *
00012  * This program is distributed in the hope that it will be useful,
00013  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  * GNU General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU General Public License
00018  * along with this program; if not, write to the Free Software
00019  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
00020  *
00021  */
00022 
00023 #ifndef COMMON_INI_FILE_H
00024 #define COMMON_INI_FILE_H
00025 
00026 #include "common/hash-str.h"
00027 #include "common/list.h"
00028 #include "common/str.h"
00029 
00030 namespace Common {
00031 
00032 class SeekableReadStream;
00033 class WriteStream;
00034 
00048 class INIFile {
00049 public:
00050     struct KeyValue {
00051         String key;
00052         String value;
00053         String comment;
00054     };
00055 
00056     typedef List<KeyValue> SectionKeyList;
00057 
00065     struct Section {
00066         String name;
00067         List<KeyValue> keys;
00068         String comment;
00069 
00070         bool hasKey(const String &key) const;
00071         const KeyValue* getKey(const String &key) const;
00072         void setKey(const String &key, const String &value);
00073         void removeKey(const String &key);
00074         const SectionKeyList getKeys() const { return keys; }
00075     };
00076 
00077     typedef List<Section> SectionList;
00078 
00079 public:
00080     INIFile();
00081     ~INIFile();
00082 
00083     // TODO: Maybe add a copy constructor etc.?
00084 
00091     static bool isValidName(const String &name);
00092 
00094     void    clear();
00095 
00096     bool    loadFromFile(const String &filename);
00097     bool    loadFromSaveFile(const String &filename);
00098     bool    loadFromStream(SeekableReadStream &stream);
00099     bool    saveToFile(const String &filename);
00100     bool    saveToSaveFile(const String &filename);
00101     bool    saveToStream(WriteStream &stream);
00102 
00103     bool    hasSection(const String &section) const;
00104     void    addSection(const String &section);
00105     void    removeSection(const String &section);
00106     void    renameSection(const String &oldName, const String &newName);
00107 
00108     bool    hasKey(const String &key, const String &section) const;
00109     bool    getKey(const String &key, const String &section, String &value) const;
00110     void    setKey(const String &key, const String &section, const String &value);
00111     void    removeKey(const String &key, const String &section);
00112 
00113     const SectionList getSections() const { return _sections; }
00114     const SectionKeyList getKeys(const String &section) const;
00115 
00116     void listKeyValues(StringMap &kv);
00117 
00118 private:
00119     SectionList _sections;
00120 
00121     Section *getSection(const String &section);
00122     const Section *getSection(const String &section) const;
00123 };
00124 
00125 } // End of namespace Common
00126 
00127 #endif


Generated on Sat Sep 14 2019 05:01:04 for ResidualVM by doxygen 1.7.1
curved edge   curved edge