kpilot

pilotRecord.cc

Go to the documentation of this file.
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 "options.h"
00036 
00037 #include <string.h>
00038 
00039 #include <qregexp.h>
00040 
00041 #include <kglobal.h>
00042 #include <kcharsets.h>
00043 
00044 #include "pilot.h"
00045 #include "pilotRecord.h"
00046 
00047 
00048 
00049 /* virtual */ QString PilotRecordBase::textRepresentation() const
00050 {
00051     return CSL1("[ %1,%2,%3 ]") . arg(attributes(),category(),id());
00052 }
00053 
00054 /* virtual */ QString PilotRecord::textRepresentation() const
00055 {
00056     return CSL1("[ %1,%2 ]")
00057         .arg(PilotRecordBase::textRepresentation())
00058         .arg(size());
00059 }
00060 
00061 
00062 
00063 /* static */ int PilotRecord::fAllocated = 0;
00064 /* static */ int PilotRecord::fDeleted = 0;
00065 
00066 /* static */ void PilotRecord::allocationInfo()
00067 {
00068     FUNCTIONSETUP;
00069     DEBUGKPILOT << fname
00070         << ": Allocated " << fAllocated
00071         << "  Deleted " << fDeleted << endl;
00072 }
00073 
00074 PilotRecord::PilotRecord(void *data, int len, int attrib, int cat, recordid_t uid) :
00075     PilotRecordBase(attrib,cat,uid),
00076     fData(0L),
00077     fLen(len),
00078     fBuffer(0L)
00079 {
00080     FUNCTIONSETUPL(4);
00081     fData = new char[len];
00082 
00083     memcpy(fData, data, len);
00084 
00085     fAllocated++;
00086 }
00087 
00088 PilotRecord::PilotRecord(PilotRecord * orig) :
00089     PilotRecordBase( orig->attributes(), orig->category(), orig->id() ) ,
00090     fBuffer(0L)
00091 {
00092     FUNCTIONSETUPL(4);
00093     fData = new char[orig->size()];
00094 
00095     memcpy(fData, orig->data(), orig->size());
00096     fLen = orig->size();
00097     fAllocated++;
00098 }
00099 
00100 PilotRecord & PilotRecord::operator = (PilotRecord & orig)
00101 {
00102     FUNCTIONSETUP;
00103     if (fBuffer)
00104     {
00105         pi_buffer_free(fBuffer);
00106         fBuffer=0L;
00107         fData=0L;
00108     }
00109 
00110     if (fData)
00111         delete[]fData;
00112     fData = new char[orig.size()];
00113 
00114     memcpy(fData, orig.data(), orig.size());
00115     fLen = orig.size();
00116     setAttributes( orig.attributes() );
00117     setCategory( orig.category() );
00118     setID( orig.id() );
00119     return *this;
00120 }
00121 
00122 void PilotRecord::setData(const char *data, int len)
00123 {
00124     FUNCTIONSETUP;
00125     if (fData)
00126         delete[]fData;
00127     fData = new char[len];
00128 
00129     memcpy(fData, data, len);
00130     fLen = len;
00131 }
00132