1 /* coded by Ketmar // Vampire Avalon (psyc://ketmar.no-ip.org/~Ketmar)
2 * Understanding is not required. Only obedience.
4 * This program is free software. It comes without any warranty, to
5 * the extent permitted by applicable law. You can redistribute it
6 * and/or modify it under the terms of the Do What The Fuck You Want
7 * To Public License, Version 2, as published by Sam Hocevar. See
8 * http://sam.zoy.org/wtfpl/COPYING for more details.
17 #include <QKeySequence>
20 #include <QStringList>
34 Integer
=2, //32-bit signed integer
41 K8SDB (const QString
&aPathName
, CreateMode cMode
=OpenExisting
);
44 inline bool isOpen () const { return mDB
.isOpen(); }
45 inline QString
pathname () const { return mDB
.fileName(); }
48 * TypeOverwrite: overwrite existing keys with different type in set()?
51 inline bool typeOverwrite () const { return mTypeOverwrite
; }
52 inline void setTypeOverwrite (bool tover
) { mTypeOverwrite
= tover
; }
54 bool remove (const QString
&name
);
56 * remove all keys with names starting from 'name'
58 bool removeAll (const QString
&name
);
59 bool hasKey (const QString
&name
) const;
60 Type
type (const QString
&name
);
62 bool set (const QString
&name
, bool v
);
63 inline bool setBool (const QString
&name
, bool v
) { return set(name
, v
); }
64 bool set (const QString
&name
, qint32 v
);
65 inline bool setInt (const QString
&name
, qint32 v
) { return set(name
, v
); }
66 bool set (const QString
&name
, const QString
&v
);
67 inline bool set (const QString
&name
, const char *v
) { return set(name
, QString(v
)); }
68 bool set (const QString
&name
, const QKeySequence
&v
);
69 bool set (const QString
&name
, const QByteArray
&v
);
70 bool set (const QString
&name
, Type type
, const QString
&v
);
72 bool toBool (const QString
&name
, bool *ok
=0);
73 qint32
toInt (const QString
&name
, bool *ok
=0);
74 QString
toString (const QString
&name
, bool *ok
=0);
75 QByteArray
toByteArray (const QString
&name
, bool *ok
=0);
76 QKeySequence
toKeySequence (const QString
&name
, bool *ok
=0);
78 QString
asString (const QString
&name
, bool *ok
=0);
80 QStringList
keys () const;
81 QStringList
keysPfx (const QString
&pfx
) const;
84 struct tsPageHeader
*keyPagePtr (const QString
&name
);
85 void *keyDataPtr (const QString
&name
);
87 uchar
*updateSettingPtr (const QString
&name
, int dataSize
);
90 * false: can't create key
91 * dup checks must be done prior to calling this method
92 * dataSize have any meaning only for String/KeySequence keys
94 struct tsPageHeader
*addKeyNoData (const QString
&name
, Type type
, int dataSize
);
95 bool freePage (int idx
);
97 void writeInitHeader ();
98 void readInitHeader ();
101 void flushKey (const QString
&name
);
106 struct tsHeader
*mHeader
;
109 QHash
<QString
, qint32
> mKeys
; // key: page index in mPages
110 QList
<qint32
> mPages
; // offset for all the pages
111 QSet
<qint32
> mFreePages
; // indicies for all free pages