kpilot/lib
pilotDatabase.h00001 #ifndef _KPILOT_PILOTDATABASE_H
00002 #define _KPILOT_PILOTDATABASE_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #include "pilot.h"
00036
00037
00046 class KDE_EXPORT PilotDatabase
00047 {
00048 public:
00049 PilotDatabase(const QString &name = QString::null);
00050 virtual ~PilotDatabase();
00051
00052
00053 QString name() const { return fName; } ;
00054
00059 static int instanceCount();
00060
00061
00062
00068 virtual bool createDatabase(long creator=0, long type=0,
00069 int cardno=0, int flags=0, int version=0) = 0;
00070
00076 virtual int deleteDatabase()=0;
00077
00079 virtual int readAppBlock(unsigned char* buffer, int maxLen) = 0;
00080
00082 virtual int writeAppBlock(unsigned char* buffer, int len) = 0;
00083
00087 virtual unsigned int recordCount() const=0;
00088
00091 virtual Pilot::RecordIDList idList();
00092
00095 virtual Pilot::RecordIDList modifiedIDList();
00096
00097
00099 virtual PilotRecord* readRecordById(recordid_t id) = 0;
00100
00102 virtual PilotRecord* readRecordByIndex(int index) = 0;
00103
00105 virtual PilotRecord* readNextRecInCategory(int category) = 0;
00106
00113 virtual PilotRecord* readNextModifiedRec(int *ind=NULL) = 0;
00114
00119 virtual recordid_t writeRecord(PilotRecord* newRecord) = 0;
00120
00128 virtual int deleteRecord(recordid_t id, bool all=false) = 0;
00129
00131 virtual int resetSyncFlags() = 0;
00132
00134 virtual int resetDBIndex() = 0;
00135
00137 virtual int cleanup() = 0;
00138
00139 bool isOpen() const { return fDBOpen; }
00140
00145 virtual QString dbPathName() const = 0;
00146
00151 typedef enum { eNone=0,
00152 eLocalDB=1,
00153 eSerialDB=2 } DBType;
00154 virtual DBType dbType() const = 0;
00155
00156 static inline bool isResource(struct DBInfo *info)
00157 {
00158 return (info->flags & dlpDBFlagResource);
00159 }
00160
00161 protected:
00162 virtual void openDatabase() = 0;
00163 virtual void closeDatabase() = 0;
00164
00165 void setDBOpen(bool yesno) { fDBOpen = yesno; }
00166
00167 private:
00168 bool fDBOpen;
00169 QString fName;
00170 };
00171
00187 template <class kdetype, class pilottype, class mapper>
00188 class DatabaseInterpreter
00189 {
00190 private:
00192 kdetype *interpret(PilotRecord *r)
00193 {
00194
00195 if (!r) return 0;
00196
00197 pilottype *a = new pilottype(r);
00198
00199 delete r;
00200
00201 if (!a) { return 0; }
00202
00203 kdetype *t = mapper::convert(a);
00204
00205
00206 if ( (void *)t != (void *)a )
00207 {
00208 delete a;
00209 }
00210 return t;
00211 }
00212 public:
00214 DatabaseInterpreter(PilotDatabase *d) : fDB(d) { } ;
00215
00217 kdetype *readRecordById(recordid_t id)
00218 {
00219 return interpret(fDB->readRecordById(id));
00220 }
00221
00223 kdetype *readRecordByIndex(int index)
00224 {
00225 return interpret(fDB->readRecordByIndex(index));
00226 }
00227
00229 kdetype *readNextRecInCategory(int category)
00230 {
00231 return interpret(fDB->readNextRecInCategory(category));
00232 }
00233
00240 kdetype *readNextModifiedRec(int *ind=NULL)
00241 {
00242 return interpret(fDB->readNextModifiedRec(ind));
00243 }
00244
00245
00250 PilotDatabase *db() const { return fDB; }
00251
00252 protected:
00253 PilotDatabase *fDB;
00254 } ;
00255
00260 template <class T>
00261 class NullMapper
00262 {
00263 public:
00265 static T *convert(T *t) { return t; }
00266 } ;
00267
00268 #endif
|