Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

datacache.h

Go to the documentation of this file.
00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 /*
00022  * This file is used to load the xml files that represent the database.
00023  * The main requirment for said file is each data entry must contain a key,
00024  * otherwise any other data headings are allowed.
00025  */
00026 
00027 #ifndef __DATACACHE_H__
00028 #define __DATACACHE_H__
00029 
00030 #include "common.h"
00031 
00032 /* OPIE */
00033 #include <opie2/odebug.h>
00034 using namespace Opie::Core;
00035 
00036 /* QT */
00037 #include <qstring.h>
00038 #include <qvector.h>
00039 
00040 class DBStore;
00041 
00043 class DBAccess {
00044 public:
00045 
00046 //    DBAccess(DBStore *d) { dstore = d; }
00047     virtual ~DBAccess() {}
00048 
00049     virtual QString type() {
00050         return QString();
00051     }
00052 
00053     virtual bool openSource(QIODevice *) {
00054         owarn << "DBAccess::openSource not yet implemented" << oendl;
00055         return false;
00056     }
00057 
00058     virtual bool saveSource(QIODevice *) {
00059         owarn << "DBAccess::saveSource(QString) not yet implemented" << oendl;
00060         return false;
00061     }
00062 
00063 protected:
00064     DBStore *dstore;
00065     QString source_name;
00066 };
00067 
00068 class DBStore {
00069 public:
00070     DBStore();
00071     ~DBStore();
00072 
00073     bool openSource(QIODevice *, const QString &source);
00074     bool saveSource(QIODevice *, const QString &source);
00075 
00076     // Add an item
00077     void addItem(DataElem *);
00078     void addItemInternal(DataElem *);
00079     void removeItem(DataElem *);
00080 
00081     // Set the name of the database
00082     void setName(const QString &name);
00083 
00084     // Get the name of the database
00085     QString getName();
00086 
00087     KeyList *getKeys();
00088     void setKeys(KeyList *);
00089 
00091     inline int getNumFields() {
00092        return kRep->getNumFields();
00093     }
00094 
00096     inline int getKeyIndex(QString qs) {
00097         return kRep->getKeyIndex(qs);
00098     }
00099 
00101     inline TVVariant::KeyType getKeyType(int i) {
00102         return kRep->getKeyType(i);
00103     }
00104 
00106     inline QString getKeyName(int i) {
00107         return kRep->getKeyName(i);
00108     }
00109 
00110 // Access functions.. iterator type stuff
00111 
00112     void first();
00113     void last();
00114 
00115     bool next();
00116     bool previous();
00117 
00118     DataElem* getCurrentData();
00119 
00120 private:
00121     /* does the work of freeing used memory */
00122     void freeTable();
00123     QString name;
00124 
00125     QVector<DataElem> master_table;
00126     DBAccess *archive;
00127 
00128     KeyList *kRep;
00129 
00130     unsigned int number_elems;
00131     unsigned int table_size; /* should always be a power of 2 */
00132     bool full; /* since because we are using an int for indexing there is
00133                   an upper limit on the number of items we can store. */
00134     unsigned int current_elem;
00135 };
00136 #endif

Generated on Sat Nov 5 16:17:08 2005 for OPIE by  doxygen 1.4.2