kpilot
pilotRecord.hGo to the documentation of this file.00001 #ifndef _KPILOT_PILOTRECORD_H
00002 #define _KPILOT_PILOTRECORD_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
00048 class KDE_EXPORT PilotRecordBase
00049 {
00050 public:
00060 PilotRecordBase(int attrib=0, int cat=0, recordid_t id=0) :
00061 fAttrib(attrib),fCat(0),fID(id)
00062 {
00063 setCategory(cat);
00064 }
00065
00073 PilotRecordBase( const PilotRecordBase *b ) :
00074 fAttrib( b ? b->attributes() : 0 ),
00075 fCat( 0 ),
00076 fID( b ? b->id() : 0 )
00077 {
00078 if (b)
00079 {
00080 setCategory( b->category() );
00081 }
00082 }
00083
00085 virtual ~PilotRecordBase() { } ;
00086
00090 inline int attributes() const
00091 {
00092 return fAttrib;
00093 }
00094
00096 inline void setAttributes(int attrib)
00097 {
00098 fAttrib = attrib;
00099 }
00100
00104 inline int category() const
00105 {
00106 return fCat;
00107 }
00108
00114 inline void setCategory(int cat)
00115 {
00116 if ( (cat<0) || (cat>=(int)Pilot::CATEGORY_COUNT))
00117 {
00118 cat=0;
00119 }
00120 fCat = cat;
00121 }
00122
00133 bool setCategory(const struct CategoryAppInfo *info, const QString &label)
00134 {
00135 if (!info)
00136 {
00137 return false;
00138 }
00139
00140 int cat = Pilot::findCategory( info, label, false );
00141 if ( (cat<0) || (cat>=(int)Pilot::CATEGORY_COUNT) )
00142 {
00143 return false;
00144 }
00145 else
00146 {
00147 setCategory( cat );
00148 return true;
00149 }
00150 }
00151
00155 inline recordid_t id() const
00156 {
00157 return fID;
00158 }
00159
00163 void setID(recordid_t id)
00164 {
00165 fID = id;
00166 }
00167
00173 inline bool isDeleted() const
00174 {
00175 return fAttrib & dlpRecAttrDeleted;
00176 }
00177
00181 inline bool isSecret() const
00182 {
00183 return fAttrib & dlpRecAttrSecret;
00184 }
00185
00192 inline bool isArchived() const
00193 {
00194 return fAttrib & dlpRecAttrArchived;
00195 }
00196
00200 inline bool isModified() const
00201 {
00202 return fAttrib & dlpRecAttrDirty;
00203 }
00204
00205 #define SETTER(a) {\
00206 if (d) { fAttrib |= a; } \
00207 else { fAttrib &= ~a; } }
00208
00210 inline void setDeleted(bool d=true) SETTER(dlpRecAttrDeleted)
00211
00213 inline void setSecret(bool d=true) SETTER(dlpRecAttrSecret)
00214
00216 inline void setArchived(bool d=true) SETTER(dlpRecAttrArchived)
00217
00219 inline void setModified(bool d=true) SETTER(dlpRecAttrDirty)
00220
00221 #undef SETTER
00222
00224 virtual QString textRepresentation() const;
00225
00226 private:
00227 int fAttrib, fCat;
00228 recordid_t fID;
00229 } ;
00230
00235 class KDE_EXPORT PilotRecord : public PilotRecordBase
00236 {
00237 public:
00244 PilotRecord(void* data, int length, int attrib, int cat, recordid_t uid) KDE_DEPRECATED;
00245
00252 PilotRecord(pi_buffer_t *buf, int attrib, int cat, recordid_t uid) :
00253 PilotRecordBase(attrib,cat,uid),
00254 fData((char *)buf->data),
00255 fLen(buf->used),
00256 fBuffer(buf)
00257 {
00258 fAllocated++;
00259 }
00260
00264 PilotRecord( pi_buffer_t *buf, const PilotRecordBase *entry ) :
00265 PilotRecordBase( entry ),
00266 fData((char *)buf->data),
00267 fLen(buf->used),
00268 fBuffer(buf)
00269 {
00270 fAllocated++;
00271 }
00272
00274 virtual ~PilotRecord()
00275 {
00276 if (fBuffer)
00277 {
00278 pi_buffer_free(fBuffer);
00279 }
00280 else
00281 {
00282 delete [] fData;
00283 }
00284 fDeleted++;
00285 }
00286
00288 PilotRecord(PilotRecord* orig);
00289
00296 char *data() const
00297 {
00298 if (fBuffer)
00299 {
00300 return (char *)(fBuffer->data);
00301 }
00302 else
00303 {
00304 return fData;
00305 }
00306 }
00307
00309 int size() const
00310 {
00311 if (fBuffer) return fBuffer->used; else
00312 return fLen;
00313 }
00314
00316 const pi_buffer_t *buffer() const { return fBuffer; }
00317
00321 void setData(pi_buffer_t *b)
00322 {
00323 if (fBuffer) { pi_buffer_free(fBuffer); }
00324 else { delete[] fData; } ;
00325 fData = (char *)b->data;
00326 fLen = b->used;
00327 fBuffer = b;
00328 }
00329
00331 PilotRecord& operator=(PilotRecord& orig);
00332
00334 void setData(const char* data, int len);
00335
00337 virtual QString textRepresentation() const;
00338
00339 private:
00340 char* fData;
00341 int fLen;
00342 pi_buffer_t *fBuffer;
00343
00344 public:
00350 static void allocationInfo();
00351 private:
00352 static int fAllocated,fDeleted;
00353 };
00354
00355 #endif
|