-
Notifications
You must be signed in to change notification settings - Fork 4
/
formathandler.h
243 lines (199 loc) · 4.87 KB
/
formathandler.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
#ifndef FORMATHANDLER_H
#define FORMATHANDLER_H
#include <QFile>
#include <QObject>
#include <QList>
#include <QMultiHash>
#include <QMap>
#define BASE_FORMAT_KEY -1
class BaseProperty;
class BaseValue;
class DatValue
{
public:
DatValue( void ) {
size = 0;
};
~DatValue( void ) {};
quint8 getSize( void ) const {
return size;
};
virtual BaseValue *getBaseValue( void ) {
return NULL;
};
virtual const BaseValue *getBaseValue( void ) const {
return NULL;
};
private:
quint8 size;
friend class FormatHandler;
};
class BaseValue : public DatValue
{
public:
BaseValue( void ) {
name = QString();
tooltip = QString();
};
virtual BaseValue *getBaseValue( void ) {
return this;
};
virtual const BaseValue *getBaseValue( void ) const {
return this;
};
const QString& getName( void ) const {
return name;
};
const QString& getToolTip( void ) const {
return tooltip;
};
private:
QString name;
QString tooltip;
friend class FormatHandler;
};
typedef QMultiHash<quint8, DatValue *> DatValueHash;
class DatProperty
{
public:
DatProperty( void ) {
header = 0xFF;
base = 0xFF;
};
~DatProperty( void ) {
qDeleteAll( valueHash );
valueHash.clear();
};
virtual BaseProperty *getBaseProperty( void ) {
return NULL;
};
virtual const BaseProperty *getBaseProperty( void ) const {
return NULL;
};
quint8 getHeader( void ) const {
return header;
};
quint8 getBase( void ) const {
return base;
};
DatValueHash getValues( void ) const {
return valueHash;
};
inline DatValueHash::const_iterator getValuesBegin() const {
return valueHash.begin();
}
inline DatValueHash::const_iterator getValuesEnd() const {
return valueHash.end();
}
quint32 getValuesSize( void ) const {
return valueHash.size();
};
private:
quint8 header;
quint8 base;
DatValueHash valueHash;
friend class FormatHandler;
};
class BaseProperty : public DatProperty
{
public:
BaseProperty( void ) {
name = QString();
tooltip = QString();
};
const QString& getName( void ) const {
return name;
};
const QString& getToolTip( void ) const {
return tooltip;
};
virtual BaseProperty *getBaseProperty( void ) {
return this;
};
virtual const BaseProperty *getBaseProperty( void ) const {
return this;
};
private:
QString name;
QString tooltip;
friend class FormatHandler;
};
typedef QList<DatProperty *> DatPropertyList;
class DatFormat
{
public:
DatFormat( void ) {
name = QString();
redirect = 0;
version = 0;
signature = 0;
ZDivFactor = true;
};
~DatFormat( void ) {
qDeleteAll( propertyList );
propertyList.clear();
};
const QString& getName( void ) const {
return name;
};
qint32 getVersion( void ) const {
return version;
};
qint32 getRedirect( void ) const {
return redirect;
};
bool hasZFactor( void ) const {
return ZDivFactor;
};
bool hasProperty( quint8 base ) const;
inline DatPropertyList::const_iterator getPropertiesBegin() const {
return propertyList.begin();
}
inline DatPropertyList::const_iterator getPropertiesEnd() const {
return propertyList.end();
}
quint32 getPropertiesSize( void ) const {
return propertyList.size();
};
DatProperty *getPropertyByBase( quint8 base ) const;
DatProperty *getPropertyByHeader( quint8 header ) const;
DatFormat *getBaseFormat( void ) const;
private:
QString name;
qint32 version;
qint32 redirect;
quint32 signature;
bool ZDivFactor;
DatPropertyList propertyList;
friend class FormatHandler;
};
typedef QMap<qint32, DatFormat *> DatFormatMap;
class FormatHandler : public QObject
{
Q_OBJECT
public:
FormatHandler( QObject *parent = 0 );
~FormatHandler( void );
bool loadFile( const QString& );
inline DatFormatMap::const_iterator getFormatsBegin() const {
return m_formats.begin();
}
inline DatFormatMap::const_iterator getFormatsEnd() const {
return m_formats.end();
}
BaseProperty *getBaseProperty( quint8 base ) const;
DatFormat *getBaseFormat( void ) const;
DatFormat *getFormatBySignature( quint32 signature ) const;
DatFormat *getFormatByName( const QString& version ) const;
DatFormat *getFormatByClient( qint32 version ) const;
bool isLoaded( void ) const {
return m_loaded;
};
signals:
void parseError( QString, QFile::FileError );
void documentError( QString, QString, int );
private:
bool m_loaded;
DatFormatMap m_formats;
};
#endif // FORMATHANDLER_H