kpilot/lib

pilotRecord.cc

00001 /* KPilot
00002 **
00003 ** Copyright (C) 1998-2001 by Dan Pilone
00004 ** Copyright (C) 2003-2004 Reinhold Kainhofer <reinhold@kainhofer.com>
00005 **
00006 ** This is a wrapper for pilot-link's general
00007 ** Pilot database structures. These records are
00008 *** just collections of bits. See PilotAppCategory
00009 ** for interpreting the bits in a meaningful way.
00010 **
00011 ** As a crufty hack, the non-inline parts of
00012 ** PilotAppCategory live in this file as well.
00013 */
00014 
00015 /*
00016 ** This program is free software; you can redistribute it and/or modify
00017 ** it under the terms of the GNU Lesser General Public License as published by
00018 ** the Free Software Foundation; either version 2.1 of the License, or
00019 ** (at your option) any later version.
00020 **
00021 ** This program is distributed in the hope that it will be useful,
00022 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00024 ** GNU Lesser General Public License for more details.
00025 **
00026 ** You should have received a copy of the GNU Lesser General Public License
00027 ** along with this program in a file called COPYING; if not, write to
00028 ** the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00029 ** MA 02110-1301, USA.
00030 */
00031 
00032 /*
00033 ** Bug reports and questions can be sent to kde-pim@kde.org
00034 */
00035 #include <config.h>
00036 #include "options.h"
00037 #include "fakes.h"
00038 
00039 #include <string.h>
00040 
00041 #include <qregexp.h>
00042 
00043 #include <kglobal.h>
00044 #include <kcharsets.h>
00045 
00046 #include "pilot.h"
00047 #include "pilotRecord.h"
00048 
00049 
00050 
00051 /* virtual */ QString PilotRecordBase::textRepresentation() const
00052 {
00053     return CSL1("[ %1,%2,%3 ]") . arg(attributes(),category(),id());
00054 }
00055 
00056 /* virtual */ QString PilotRecord::textRepresentation() const
00057 {
00058     return CSL1("[ %1,%2 ]")
00059         .arg(PilotRecordBase::textRepresentation())
00060         .arg(size());
00061 }
00062 
00063 
00064 
00065 /* static */ int PilotRecord::fAllocated = 0;
00066 /* static */ int PilotRecord::fDeleted = 0;
00067 
00068 /* static */ void PilotRecord::allocationInfo()
00069 {
00070 #ifdef DEBUG
00071     FUNCTIONSETUP;
00072     DEBUGLIBRARY << fname
00073         << ": Allocated " << fAllocated
00074         << "  Deleted " << fDeleted << endl;
00075 #endif
00076 }
00077 
00078 PilotRecord::PilotRecord(void *data, int len, int attrib, int cat, recordid_t uid) :
00079     PilotRecordBase(attrib,cat,uid),
00080     fData(0L),
00081     fLen(len),
00082     fBuffer(0L)
00083 {
00084     FUNCTIONSETUPL(4);
00085     fData = new char[len];
00086 
00087     memcpy(fData, data, len);
00088 
00089     fAllocated++;
00090 }
00091 
00092 PilotRecord::PilotRecord(PilotRecord * orig) :
00093     PilotRecordBase( orig->attributes(), orig->category(), orig->id() ) ,
00094     fBuffer(0L)
00095 {
00096     FUNCTIONSETUPL(4);
00097     fData = new char[orig->size()];
00098 
00099     memcpy(fData, orig->data(), orig->size());
00100     fLen = orig->size();
00101     fAllocated++;
00102 }
00103 
00104 PilotRecord & PilotRecord::operator = (PilotRecord & orig)
00105 {
00106     FUNCTIONSETUP;
00107     if (fBuffer)
00108     {
00109         pi_buffer_free(fBuffer);
00110         fBuffer=0L;
00111         fData=0L;
00112     }
00113 
00114     if (fData)
00115         delete[]fData;
00116     fData = new char[orig.size()];
00117 
00118     memcpy(fData, orig.data(), orig.size());
00119     fLen = orig.size();
00120     setAttributes( orig.attributes() );
00121     setCategory( orig.category() );
00122     setID( orig.id() );
00123     return *this;
00124 }
00125 
00126 void PilotRecord::setData(const char *data, int len)
00127 {
00128     FUNCTIONSETUP;
00129     if (fData)
00130         delete[]fData;
00131     fData = new char[len];
00132 
00133     memcpy(fData, data, len);
00134     fLen = len;
00135 }
00136 
KDE Home | KDE Accessibility Home | Description of Access Keys