cosmetix
[dyskinesia.git] / src / k8sdbjs / k8sdb.h
blobc1c2e7aad0ce675fd7b125ac3051919190af9cfe
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.
9 */
10 #ifndef K8SDB_H
11 #define K8SDB_H
13 #include <QByteArray>
14 #include <QFile>
15 #include <QHash>
16 #include <QList>
17 #include <QKeySequence>
18 #include <QSet>
19 #include <QString>
20 #include <QStringList>
22 #include "k8json.h"
23 #include "k8ascii85.h"
26 class K8SDB {
27 public:
28 enum CreateMode {
29 OpenExisting=0,
30 OpenAlways=1,
31 WipeAlways=2
34 enum Type {
35 Invalid=0,
36 Boolean=1,
37 Integer=2, //32-bit signed integer
38 String=3,
39 ByteArray=4,
40 KeySequence=5,
41 MaxKeyType
44 K8SDB (const QString &aPathName, CreateMode cMode=OpenExisting);
45 ~K8SDB ();
47 inline bool isOpen () const { return mIsOpen; }
48 inline const QString &pathname () const { return mFileName; }
51 * TypeOverwrite: overwrite existing keys with different type in set()?
52 * default: yes
54 inline bool typeOverwrite () const { return mTypeOverwrite; }
55 inline void setTypeOverwrite (bool tover) { mTypeOverwrite = tover; }
57 bool remove (const QString &name);
59 * remove all keys with names starting from 'name'
61 bool removeAll (const QString &name);
62 bool hasKey (const QString &name) const;
63 Type type (const QString &name) const; // returns Invalid if there is no such key
65 bool set (const QString &name, bool v);
66 inline bool setBool (const QString &name, bool v) { return set(name, v); }
67 bool set (const QString &name, qint32 v);
68 inline bool setInt (const QString &name, qint32 v) { return set(name, v); }
69 bool set (const QString &name, const QString &v);
70 inline bool set (const QString &name, const char *v) { return set(name, QString(v)); }
71 bool set (const QString &name, const QKeySequence &v);
72 bool set (const QString &name, const QByteArray &v);
73 bool set (const QString &name, Type type, const QString &v);
75 bool toBool (const QString &name, bool *ok=0);
76 qint32 toInt (const QString &name, bool *ok=0);
77 QString toString (const QString &name, bool *ok=0);
78 QByteArray toByteArray (const QString &name, bool *ok=0);
79 QKeySequence toKeySequence (const QString &name, bool *ok=0);
81 QString asString (const QString &name, bool *ok=0);
83 QStringList keys () const;
84 QStringList keysPfx (const QString &pfx) const;
86 static const char *typeName (Type type);
88 private:
89 bool readJSON ();
90 bool writeJSON ();
92 private:
93 QString mFileName;
94 CreateMode mMode;
95 bool mTypeOverwrite;
96 bool mIsOpen;
98 QHash<QString, QVariant> mKeys;
103 #endif