1 | /* |
2 | Copyright (c) 2008 Tobias Koenig <tokoe@kde.org> |
3 | |
4 | This library is free software; you can redistribute it and/or modify it |
5 | under the terms of the GNU Library General Public License as published by |
6 | the Free Software Foundation; either version 2 of the License, or (at your |
7 | option) any later version. |
8 | |
9 | This library is distributed in the hope that it will be useful, but WITHOUT |
10 | ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public |
12 | License for more details. |
13 | |
14 | You should have received a copy of the GNU Library General Public License |
15 | along with this library; see the file COPYING.LIB. If not, write to the |
16 | Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
17 | 02110-1301, USA. |
18 | */ |
19 | |
20 | #ifndef ENTITY_P_H |
21 | #define ENTITY_P_H |
22 | |
23 | #include "entity.h" |
24 | #include "collection.h" |
25 | |
26 | #include <QtCore/QSet> |
27 | #include <QtCore/QSharedData> |
28 | #include <QtCore/QString> |
29 | |
30 | #define AKONADI_DEFINE_PRIVATE( Class ) \ |
31 | Class##Private *Class ::d_func() { return reinterpret_cast<Class##Private *>( d_ptr.data() ); } \ |
32 | const Class##Private *Class ::d_func() const { return reinterpret_cast<const Class##Private *>( d_ptr.data() ); } |
33 | |
34 | namespace Akonadi { |
35 | |
36 | /** |
37 | * @internal |
38 | */ |
39 | class EntityPrivate : public QSharedData |
40 | { |
41 | public: |
42 | explicit EntityPrivate(Entity::Id id = -1) |
43 | : mId(id) |
44 | , mParent(0) |
45 | { |
46 | } |
47 | |
48 | virtual ~EntityPrivate() |
49 | { |
50 | qDeleteAll(mAttributes); |
51 | delete mParent; |
52 | } |
53 | |
54 | EntityPrivate(const EntityPrivate &other) |
55 | : QSharedData(other) |
56 | , mParent(0) |
57 | { |
58 | mId = other.mId; |
59 | mRemoteId = other.mRemoteId; |
60 | mRemoteRevision = other.mRemoteRevision; |
61 | foreach (Attribute *attr, other.mAttributes) { |
62 | mAttributes.insert(attr->type(), attr->clone()); |
63 | } |
64 | mDeletedAttributes = other.mDeletedAttributes; |
65 | if (other.mParent) { |
66 | mParent = new Collection(*(other.mParent)); |
67 | } |
68 | } |
69 | |
70 | virtual void resetChangeLog() |
71 | { |
72 | mDeletedAttributes.clear(); |
73 | } |
74 | |
75 | virtual EntityPrivate *clone() const = 0; |
76 | |
77 | Entity::Id mId; |
78 | QString mRemoteId; |
79 | QString mRemoteRevision; |
80 | QHash<QByteArray, Attribute *> mAttributes; |
81 | QSet<QByteArray> mDeletedAttributes; |
82 | mutable Collection *mParent; |
83 | }; |
84 | |
85 | } |
86 | |
87 | /** |
88 | * @internal |
89 | * |
90 | * This template specialization is used to change the detach |
91 | * behaviour of QSharedDataPointer to allow 'virtual copy constructors', |
92 | * so Akonadi::ItemPrivate and Akonadi::CollectionPrivate are copied correctly. |
93 | */ |
94 | template <> |
95 | Q_INLINE_TEMPLATE Akonadi::EntityPrivate *QSharedDataPointer<Akonadi::EntityPrivate>::clone() |
96 | { |
97 | return d->clone(); |
98 | } |
99 | |
100 | #endif |
101 | |