kpilot
pilotDatabase.hGo to the documentation of this file.00001 #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 #include "pilot.h"
00034
00035
00050 class KDE_EXPORT PilotDatabase
00051 {
00052 public:
00053 PilotDatabase(const QString &name = QString::null);
00054 virtual ~PilotDatabase();
00055
00056
00057 QString name() const { return fName; } ;
00058
00063 static int instanceCount();
00064
00065
00066
00072 virtual bool createDatabase(long creator=0, long type=0,
00073 int cardno=0, int flags=0, int version=0) = 0;
00074
00080 virtual int deleteDatabase()=0;
00081
00083 virtual int readAppBlock(unsigned char* buffer, int maxLen) = 0;
00084
00086 virtual int writeAppBlock(unsigned char* buffer, int len) = 0;
00087
00091 virtual unsigned int recordCount() const=0;
00092
00095 virtual Pilot::RecordIDList idList();
00096
00099 virtual Pilot::RecordIDList modifiedIDList();
00100
00101
00103 virtual PilotRecord* readRecordById(recordid_t id) = 0;
00104
00106 virtual PilotRecord* readRecordByIndex(int index) = 0;
00107
00109 virtual PilotRecord* readNextRecInCategory(int category) = 0;
00110
00117 virtual PilotRecord* readNextModifiedRec(int *ind=NULL) = 0;
00118
00123 virtual recordid_t writeRecord(PilotRecord* newRecord) = 0;
00124
00132 virtual int deleteRecord(recordid_t id, bool all=false) = 0;
00133
00135 virtual int resetSyncFlags() = 0;
00136
00138 virtual int resetDBIndex() = 0;
00139
00141 virtual int cleanup() = 0;
00142
00143 bool isOpen() const { return fDBOpen; }
00144
00149 virtual QString dbPathName() const = 0;
00150
00155 typedef enum { eNone=0,
00156 eLocalDB=1,
00157 eSerialDB=2 } DBType;
00158 virtual DBType dbType() const = 0;
00159
00160 static inline bool isResource(struct DBInfo *info)
00161 {
00162 return (info->flags & dlpDBFlagResource);
00163 }
00164
00165 protected:
00166 virtual void openDatabase() = 0;
00167 virtual void closeDatabase() = 0;
00168
00169 void setDBOpen(bool yesno) { fDBOpen = yesno; }
00170
00171 private:
00172 bool fDBOpen;
00173 QString fName;
00174 };
00175
00191 template <class kdetype, class pilottype, class mapper>
00192 class DatabaseInterpreter
00193 {
00194 private:
00196 kdetype *interpret(PilotRecord *r)
00197 {
00198
00199 if (!r) return 0;
00200
00201 pilottype *a = new pilottype(r);
00202
00203 delete r;
00204
00205 if (!a) { return 0; }
00206
00207 kdetype *t = mapper::convert(a);
00208
00209
00210 if ( (void *)t != (void *)a )
00211 {
00212 delete a;
00213 }
00214 return t;
00215 }
00216 public:
00218 DatabaseInterpreter(PilotDatabase *d) : fDB(d) { } ;
00219
00221 kdetype *readRecordById(recordid_t id)
00222 {
00223 return interpret(fDB->readRecordById(id));
00224 }
00225
00227 kdetype *readRecordByIndex(int index)
00228 {
00229 return interpret(fDB->readRecordByIndex(index));
00230 }
00231
00233 kdetype *readNextRecInCategory(int category)
00234 {
00235 return interpret(fDB->readNextRecInCategory(category));
00236 }
00237
00244 kdetype *readNextModifiedRec(int *ind=NULL)
00245 {
00246 return interpret(fDB->readNextModifiedRec(ind));
00247 }
00248
00249
00254 PilotDatabase *db() const { return fDB; }
00255
00256 protected:
00257 PilotDatabase *fDB;
00258 } ;
00259
00264 template <class T>
00265 class NullMapper
00266 {
00267 public:
00269 static T *convert(T *t) { return t; }
00270 } ;
00271
00272 #endif
|