-
Notifications
You must be signed in to change notification settings - Fork 4
/
iniedit.h
118 lines (91 loc) · 2.98 KB
/
iniedit.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
#ifndef INIEDIT_H
#define INIEDIT_H
#include <list>
#include <QString>
#include <QMap>
#include <QFile>
#include <QFileInfo>
class Line
{
public:
Line() {}
Line(bool fHasProperty, int iline, QString sName, QString sValue, QString sLine):
fHasProperty(fHasProperty), iline(iline), sName(sName), sValue(sValue), sLine(sLine)
{
fDeleted = false;
}
struct {
bool fHasProperty : 1;
bool fDeleted : 1;
};
int iline;
QString sName;
QString sValue;
QString sLine;
inline int operator==(Line &e) { return (this == &e); }
};
typedef std::list<Line> LineList;
typedef LineList::iterator LineIterator;
typedef LineList::const_iterator ConstLineIterator;
typedef QMap<QString, LineIterator> LineIndex;
class IniEditor;
class Section
{
friend class IniEditor;
public:
Section() {}
Section(IniEditor *pie);
~Section() {}
void setParent(IniEditor *pie);
void setName(QString s) { sName = s; }
void insert(const QString &sPropertyName, LineIterator il);
void remove(const QString &sPropertyName);
const QString value(const QString &sPropertyName) const;
const QString value(const QString &sPropertyName, const QString &sDefault) const;
int intValue(const QString &sPropertyName, int iDefault) const;
double value(const QString &sPropertyName, double dDefault) const;
inline const QString operator[](const QString &sPropertyName) const { return value(sPropertyName); }
void setValue(const QString &sPropertyName, const QString &s);
void setValue(const QString &sPropertyName, const QString &s, const QString &sDefault);
void setValue(const QString &sPropertyName, int i, int iDefault);
void setValue(const QString &sPropertyName, double d, double dDefault, int cdecimals = 4);
void dump() const;
private:
QString sName;
LineIndex li;
LineIterator ilineLast;
IniEditor *pie; // parent
};
typedef QMap<QString, Section> SectionIndex;
class IniEditor
{
friend class Section;
public:
IniEditor() {}
~IniEditor() {}
typedef bool (*ParserCallback)(void *user, QString &sSection, Line &line);
void clear();
void setFilename(const QString &sPathName);
bool copyTo(QDir dir);
inline QString fileName() { return file.fileName(); }
bool read(ParserCallback pc, void *user);
bool write();
QFileDevice::FileError error() { return fe; }
Section §ion(QString s);
void dump() const;
private:
SectionIndex si;
LineList ll;
QFileDevice::FileError fe;
QFile file;
char *szLineParsing;
int ilineParsing;
QString sSectionParsing;
ParserCallback parserCallback;
void *user;
char *parserReader(char *szBuffer, int cbBuffer);
int parserHandler(const char *szSection, const char *szName, const char *szValue);
static char *inihReader(char *szBuffer, int cbBuffer, void *user);
static int inihHandler(void *user, const char *szSection, const char *szName, const char *szValue);
};
#endif // INIEDIT_H