author | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
---|---|---|
committer | kergoth <kergoth> | 2002-01-25 22:14:26 (UTC) |
commit | 15318cad33835e4e2dc620d033e43cd930676cdd (patch) (unidiff) | |
tree | c2fa0399a2c47fda8e2cd0092c73a809d17f68eb /noncore/apps/tableviewer/db/datacache.h | |
download | opie-15318cad33835e4e2dc620d033e43cd930676cdd.zip opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.gz opie-15318cad33835e4e2dc620d033e43cd930676cdd.tar.bz2 |
Initial revision
Diffstat (limited to 'noncore/apps/tableviewer/db/datacache.h') (more/less context) (show whitespace changes)
-rw-r--r-- | noncore/apps/tableviewer/db/datacache.h | 130 |
1 files changed, 130 insertions, 0 deletions
diff --git a/noncore/apps/tableviewer/db/datacache.h b/noncore/apps/tableviewer/db/datacache.h new file mode 100644 index 0000000..c5dc637 --- a/dev/null +++ b/noncore/apps/tableviewer/db/datacache.h | |||
@@ -0,0 +1,130 @@ | |||
1 | /********************************************************************** | ||
2 | ** Copyright (C) 2000 Trolltech AS. All rights reserved. | ||
3 | ** | ||
4 | ** This file is part of Qtopia Environment. | ||
5 | ** | ||
6 | ** This file may be distributed and/or modified under the terms of the | ||
7 | ** GNU General Public License version 2 as published by the Free Software | ||
8 | ** Foundation and appearing in the file LICENSE.GPL included in the | ||
9 | ** packaging of this file. | ||
10 | ** | ||
11 | ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE | ||
12 | ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||
13 | ** | ||
14 | ** See http://www.trolltech.com/gpl/ for GPL licensing information. | ||
15 | ** | ||
16 | ** Contact info@trolltech.com if any conditions of this licensing are | ||
17 | ** not clear to you. | ||
18 | ** | ||
19 | **********************************************************************/ | ||
20 | |||
21 | /* | ||
22 | * This file is used to load the xml files that represent the database. | ||
23 | * The main requirment for said file is each data entry must contain a key, | ||
24 | * otherwise any other data headings are allowed. | ||
25 | */ | ||
26 | |||
27 | #ifndef __DATACACHE_H__ | ||
28 | #define __DATACACHE_H__ | ||
29 | |||
30 | #include <qstring.h> | ||
31 | #include <qvector.h> | ||
32 | #include "common.h" | ||
33 | |||
34 | class DBStore; | ||
35 | |||
36 | /*! Abstract class that defines how database stuff can be accessed */ | ||
37 | class DBAccess { | ||
38 | public: | ||
39 | |||
40 | // DBAccess(DBStore *d) { dstore = d; } | ||
41 | virtual ~DBAccess() {} | ||
42 | |||
43 | virtual QString type() { | ||
44 | return QString(); | ||
45 | } | ||
46 | |||
47 | virtual bool openSource(QIODevice *) { | ||
48 | qWarning("DBAccess::openSource not yet implemented"); | ||
49 | return false; | ||
50 | } | ||
51 | |||
52 | virtual bool saveSource(QIODevice *) { | ||
53 | qWarning("DBAccess::saveSource(QString) not yet implemented"); | ||
54 | return false; | ||
55 | } | ||
56 | |||
57 | protected: | ||
58 | DBStore *dstore; | ||
59 | QString source_name; | ||
60 | }; | ||
61 | |||
62 | class DBStore { | ||
63 | public: | ||
64 | DBStore(); | ||
65 | ~DBStore(); | ||
66 | |||
67 | bool openSource(QIODevice *, const QString &source); | ||
68 | bool saveSource(QIODevice *, const QString &source); | ||
69 | |||
70 | // Add an item | ||
71 | void addItem(DataElem *); | ||
72 | void addItemInternal(DataElem *); | ||
73 | void removeItem(DataElem *); | ||
74 | |||
75 | // Set the name of the database | ||
76 | void setName(const QString &name); | ||
77 | |||
78 | // Get the name of the database | ||
79 | QString getName(); | ||
80 | |||
81 | KeyList *getKeys(); | ||
82 | void setKeys(KeyList *); | ||
83 | |||
84 | /*! gets the number of fields defined in the database */ | ||
85 | inline int getNumFields() { | ||
86 | return kRep->getNumFields(); | ||
87 | } | ||
88 | |||
89 | /*! gets the index of a key given its name */ | ||
90 | inline int getKeyIndex(QString qs) { | ||
91 | return kRep->getKeyIndex(qs); | ||
92 | } | ||
93 | |||
94 | /*! gets the type of a key given its index */ | ||
95 | inline TVVariant::KeyType getKeyType(int i) { | ||
96 | return kRep->getKeyType(i); | ||
97 | } | ||
98 | |||
99 | /*! gets the name of a key given its index */ | ||
100 | inline QString getKeyName(int i) { | ||
101 | return kRep->getKeyName(i); | ||
102 | } | ||
103 | |||
104 | // Access functions.. iterator type stuff | ||
105 | |||
106 | void first(); | ||
107 | void last(); | ||
108 | |||
109 | bool next(); | ||
110 | bool previous(); | ||
111 | |||
112 | DataElem* getCurrentData(); | ||
113 | |||
114 | private: | ||
115 | /* does the work of freeing used memory */ | ||
116 | void freeTable(); | ||
117 | QString name; | ||
118 | |||
119 | QVector<DataElem> master_table; | ||
120 | DBAccess *archive; | ||
121 | |||
122 | KeyList *kRep; | ||
123 | |||
124 | unsigned int number_elems; | ||
125 | unsigned int table_size; /* should always be a power of 2 */ | ||
126 | bool full; /* since because we are using an int for indexing there is | ||
127 | an upper limit on the number of items we can store. */ | ||
128 | unsigned int current_elem; | ||
129 | }; | ||
130 | #endif | ||