entity_p.h

00001 /*
00002     Copyright (c) 2008 Tobias Koenig <tokoe@kde.org>
00003 
00004     This library is free software; you can redistribute it and/or modify it
00005     under the terms of the GNU Library General Public License as published by
00006     the Free Software Foundation; either version 2 of the License, or (at your
00007     option) any later version.
00008 
00009     This library is distributed in the hope that it will be useful, but WITHOUT
00010     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00011     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00012     License for more details.
00013 
00014     You should have received a copy of the GNU Library General Public License
00015     along with this library; see the file COPYING.LIB.  If not, write to the
00016     Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
00017     02110-1301, USA.
00018 */
00019 
00020 #ifndef ENTITY_P_H
00021 #define ENTITY_P_H
00022 
00023 #include "entity.h"
00024 #include "collection.h"
00025 
00026 #include <QtCore/QSet>
00027 #include <QtCore/QSharedData>
00028 #include <QtCore/QString>
00029 
00030 #define AKONADI_DEFINE_PRIVATE( Class ) \
00031 Class##Private* Class ::d_func() { return reinterpret_cast<Class##Private *>( d_ptr.data() ); } \
00032 const Class##Private* Class ::d_func() const { return reinterpret_cast<const Class##Private *>( d_ptr.data() ); }
00033 
00034 namespace Akonadi {
00035 
00039 class EntityPrivate : public QSharedData
00040 {
00041   public:
00042     EntityPrivate( Entity::Id id = -1 )
00043       : mId( id ),
00044       mParent( 0 )
00045     {
00046     }
00047 
00048     virtual ~EntityPrivate()
00049     {
00050       qDeleteAll( mAttributes );
00051       delete mParent;
00052     }
00053 
00054     EntityPrivate( const EntityPrivate &other )
00055       : QSharedData( other ),
00056       mParent( 0 )
00057     {
00058       mId = other.mId;
00059       mRemoteId = other.mRemoteId;
00060       foreach ( Attribute* attr, other.mAttributes )
00061         mAttributes.insert( attr->type(), attr->clone() );
00062       mDeletedAttributes = other.mDeletedAttributes;
00063       if ( other.mParent )
00064         mParent = new Collection( *(other.mParent) );
00065     }
00066 
00067     virtual void resetChangeLog()
00068     {
00069       mDeletedAttributes.clear();
00070     }
00071 
00072     virtual EntityPrivate *clone() const = 0;
00073 
00074     Entity::Id mId;
00075     QString mRemoteId;
00076     QHash<QByteArray, Attribute*> mAttributes;
00077     QSet<QByteArray> mDeletedAttributes;
00078     mutable Collection* mParent;
00079 };
00080 
00081 }
00082 
00090 template <>
00091 Q_INLINE_TEMPLATE Akonadi::EntityPrivate* QSharedDataPointer<Akonadi::EntityPrivate>::clone()
00092 {
00093   return d->clone();
00094 }
00095 
00096 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys