-
Notifications
You must be signed in to change notification settings - Fork 0
/
IniFile.h
119 lines (97 loc) · 4.29 KB
/
IniFile.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/**
* SADX Mod Loader
* INI file parser.
*/
#ifndef INIFILE_H
#define INIFILE_H
#include <cstdio>
#include <string>
#include <unordered_map>
class IniFile;
/**
* Individual INI group.
*/
class IniGroup
{
public:
bool hasKey(const std::string& key) const;
bool hasKeyNonEmpty(const std::string& key) const;
const std::unordered_map<std::string, std::string>* data(void) const;
std::string getString(const std::string& key, const std::string& def = std::string()) const;
std::wstring getWString(const std::string& key, const std::wstring& def = std::wstring()) const;
bool getBool(const std::string& key, bool def = false) const;
int getIntRadix(const std::string& key, int radix, int def = 0) const;
int getInt(const std::string& key, int def = 0) const;
float getFloat(const std::string& key, float def = 0) const;
void setString(const std::string& key, const std::string& val);
void setWString(const std::string& key, const std::wstring& val);
void setBool(const std::string& key, bool val);
void setIntRadix(const std::string& key, int radix, int val);
void setInt(const std::string& key, int val);
void setFloat(const std::string& key, float val);
bool removeKey(const std::string& key);
std::unordered_map<std::string, std::string>::iterator begin();
std::unordered_map<std::string, std::string>::const_iterator cbegin() const;
std::unordered_map<std::string, std::string>::iterator end();
std::unordered_map<std::string, std::string>::const_iterator cend() const;
protected:
friend class IniFile;
/**
* INI section data.
* - Key: Key name. (UTF-8)
* - Value: Value. (UTF-8)
*/
std::unordered_map<std::string, std::string> m_data;
};
/**
* INI file.
* Contains multiple INI groups.
*/
class IniFile
{
public:
explicit IniFile(const std::string& filename);
explicit IniFile(const std::wstring& filename);
explicit IniFile(const char* filename);
explicit IniFile(const wchar_t* filename);
explicit IniFile(FILE* f);
~IniFile();
IniGroup* getGroup(const std::string& section);
const IniGroup* getGroup(const std::string& section) const;
IniGroup* createGroup(const std::string& section);
bool hasGroup(const std::string& section) const;
bool hasKey(const std::string& section, const std::string& key) const;
bool hasKeyNonEmpty(const std::string& section, const std::string& key) const;
std::string getString(const std::string& section, const std::string& key, const std::string& def = std::string()) const;
std::wstring getWString(const std::string& section, const std::string& key, const std::wstring& def = std::wstring()) const;
bool getBool(const std::string& section, const std::string& key, bool def = false) const;
int getIntRadix(const std::string& section, const std::string& key, int radix, int def = 0) const;
int getInt(const std::string& section, const std::string& key, int def = 0) const;
float getFloat(const std::string& section, const std::string& key, float def = 0) const;
void setString(const std::string& section, const std::string& key, const std::string& val);
void setWString(const std::string& section, const std::string& key, const std::wstring& val);
void setBool(const std::string& section, const std::string& key, bool val);
void setIntRadix(const std::string& section, const std::string& key, int radix, int val);
void setInt(const std::string& section, const std::string& key, int val);
void setFloat(const std::string& section, const std::string& key, float val);
bool removeGroup(const std::string& group);
bool removeKey(const std::string& section, const std::string& key);
void save(const std::string& filename) const;
void save(const std::wstring& filename) const;
void save(FILE* f) const;
std::unordered_map<std::string, IniGroup*>::iterator begin();
std::unordered_map<std::string, IniGroup*>::const_iterator cbegin() const;
std::unordered_map<std::string, IniGroup*>::iterator end();
std::unordered_map<std::string, IniGroup*>::const_iterator cend() const;
protected:
void load(FILE* f);
void clear(void);
std::string escape(const std::string& str, bool sec, bool key) const;
/**
* INI groups.
* - Key: Section name. (UTF-8)
* - Value: IniGroup.
*/
std::unordered_map<std::string, IniGroup*> m_groups;
};
#endif /* INIFILE_H */