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 count();
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
00085 virtual int recordCount()=0;
00086
00089 virtual Pilot::RecordIDList idList();
00090
00093 virtual Pilot::RecordIDList modifiedIDList();
00094
00095
00097 virtual PilotRecord* readRecordById(recordid_t id) = 0;
00098
00100 virtual PilotRecord* readRecordByIndex(int index) = 0;
00101
00103 virtual PilotRecord* readNextRecInCategory(int category) = 0;
00104
00111 virtual PilotRecord* readNextModifiedRec(int *ind=NULL) = 0;
00112
00117 virtual recordid_t writeRecord(PilotRecord* newRecord) = 0;
00118
00126 virtual int deleteRecord(recordid_t id, bool all=false) = 0;
00127
00129 virtual int resetSyncFlags() = 0;
00130
00132 virtual int resetDBIndex() = 0;
00133
00135 virtual int cleanup() = 0;
00136
00137 bool isOpen() const { return fDBOpen; }
00138
00143 virtual QString dbPathName() const = 0;
00144
00149 typedef enum { eNone=0,
00150 eLocalDB=1,
00151 eSerialDB=2 } DBType;
00152 virtual DBType dbType() const = 0;
00153
00154 static inline bool isResource(struct DBInfo *info)
00155 {
00156 return (info->flags & dlpDBFlagResource);
00157 }
00158
00159 protected:
00160 virtual void openDatabase() = 0;
00161 virtual void closeDatabase() = 0;
00162
00163 void setDBOpen(bool yesno) { fDBOpen = yesno; }
00164
00165 private:
00166 bool fDBOpen;
00167 QString fName;
00168 };
00169
00185 template <class kdetype, class pilottype, class mapper>
00186 class DatabaseInterpreter
00187 {
00188 private:
00190 kdetype *interpret(PilotRecord *r)
00191 {
00192
00193 if (!r) return 0;
00194
00195 pilottype *a = new pilottype(r);
00196
00197 delete r;
00198
00199 if (!a) { return 0; }
00200
00201 kdetype *t = mapper::convert(a);
00202
00203
00204 if ( (void *)t != (void *)a )
00205 {
00206 delete a;
00207 }
00208 return t;
00209 }
00210 public:
00212 DatabaseInterpreter(PilotDatabase *d) : fDB(d) { } ;
00213
00215 kdetype *readRecordById(recordid_t id)
00216 {
00217 return interpret(fDB->readRecordById(id));
00218 }
00219
00221 kdetype *readRecordByIndex(int index)
00222 {
00223 return interpret(fDB->readRecordByIndex(index));
00224 }
00225
00227 kdetype *readNextRecInCategory(int category)
00228 {
00229 return interpret(fDB->readNextRecInCategory(category));
00230 }
00231
00238 kdetype *readNextModifiedRec(int *ind=NULL)
00239 {
00240 return interpret(fDB->readNextModifiedRec(ind));
00241 }
00242
00243
00248 PilotDatabase *db() const { return fDB; }
00249
00250 protected:
00251 PilotDatabase *fDB;
00252 } ;
00253
00258 template <class T>
00259 class NullMapper
00260 {
00261 public:
00263 static T *convert(T *t) { return t; }
00264 } ;
00265
00266 #endif
|