summaryrefslogtreecommitdiffstats
path: root/common/domain/applicationdomaintype.h
diff options
context:
space:
mode:
Diffstat (limited to 'common/domain/applicationdomaintype.h')
-rw-r--r--common/domain/applicationdomaintype.h61
1 files changed, 55 insertions, 6 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index 21e42cf..1c0f208 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -73,12 +73,12 @@
73#define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \ 73#define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \
74 struct NAME { \ 74 struct NAME { \
75 static constexpr const char *name = #LOWERCASENAME; \ 75 static constexpr const char *name = #LOWERCASENAME; \
76 typedef QByteArray Type; \ 76 typedef Reference Type; \
77 typedef ApplicationDomain::TYPE ReferenceType; \ 77 typedef ApplicationDomain::TYPE ReferenceType; \
78 }; \ 78 }; \
79 void set##NAME(const ApplicationDomain::TYPE &value) { setProperty(NAME::name, value); } \ 79 void set##NAME(const ApplicationDomain::TYPE &value) { setProperty(NAME::name, value); } \
80 void set##NAME(const QByteArray &value) { setProperty(NAME::name, QVariant::fromValue(value)); } \ 80 void set##NAME(const QByteArray &value) { setProperty(NAME::name, QVariant::fromValue(Reference{value})); } \
81 QByteArray get##NAME() const { return getProperty(NAME::name).value<QByteArray>(); } \ 81 QByteArray get##NAME() const { return getProperty(NAME::name).value<Reference>().value; } \
82 82
83#define SINK_INDEX_PROPERTY(TYPE, NAME, LOWERCASENAME) \ 83#define SINK_INDEX_PROPERTY(TYPE, NAME, LOWERCASENAME) \
84 struct NAME { \ 84 struct NAME { \
@@ -102,7 +102,27 @@ struct BLOB {
102 QString value; 102 QString value;
103}; 103};
104 104
105void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool copyBlobs); 105/**
106 * Internal type.
107 *
108 * Represents a reference to another entity in the same resource.
109 */
110struct Reference {
111 Reference() = default;
112 Reference(const Reference &) = default;
113 Reference(const QByteArray &id) : value(id) {};
114 Reference(const char *id) : value(id) {};
115 ~Reference() = default;
116 bool operator==(const Reference &other) const {
117 return value == other.value;
118 }
119 operator QByteArray() const {
120 return value;
121 }
122 QByteArray value;
123};
124
125void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool copyBlobs, bool pruneReferences);
106 126
107/** 127/**
108 * The domain type interface has two purposes: 128 * The domain type interface has two purposes:
@@ -121,6 +141,14 @@ public:
121 ApplicationDomainType(const ApplicationDomainType &other); 141 ApplicationDomainType(const ApplicationDomainType &other);
122 ApplicationDomainType& operator=(const ApplicationDomainType &other); 142 ApplicationDomainType& operator=(const ApplicationDomainType &other);
123 143
144 template <typename DomainType>
145 DomainType cast() {
146 static_assert(std::is_base_of<ApplicationDomainType, DomainType>::value, "You can only cast to base classes of ApplicationDomainType.");
147 DomainType t = *this;
148 t.mChangeSet = mChangeSet;
149 return t;
150 }
151
124 /** 152 /**
125 * Returns an in memory representation of the same entity. 153 * Returns an in memory representation of the same entity.
126 */ 154 */
@@ -140,7 +168,7 @@ public:
140 { 168 {
141 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(); 169 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create();
142 Q_ASSERT(domainType.mAdaptor); 170 Q_ASSERT(domainType.mAdaptor);
143 copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true); 171 copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true, true);
144 return QSharedPointer<DomainType>::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor); 172 return QSharedPointer<DomainType>::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor);
145 } 173 }
146 174
@@ -195,7 +223,7 @@ public:
195private: 223private:
196 friend QDebug operator<<(QDebug, const ApplicationDomainType &); 224 friend QDebug operator<<(QDebug, const ApplicationDomainType &);
197 QSharedPointer<BufferAdaptor> mAdaptor; 225 QSharedPointer<BufferAdaptor> mAdaptor;
198 QSet<QByteArray> mChangeSet; 226 QSharedPointer<QSet<QByteArray>> mChangeSet;
199 /* 227 /*
200 * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location. 228 * Each domain object needs to store the resource, identifier, revision triple so we can link back to the storage location.
201 */ 229 */
@@ -223,6 +251,19 @@ inline QDebug operator<< (QDebug d, const ApplicationDomainType &type)
223 return d; 251 return d;
224} 252}
225 253
254inline QDebug operator<< (QDebug d, const Reference &ref)
255{
256 d << ref.value;
257 return d;
258}
259
260inline QDebug operator<< (QDebug d, const BLOB &blob)
261{
262 d << blob.value;
263 return d;
264}
265
266
226struct SINK_EXPORT SinkAccount : public ApplicationDomainType { 267struct SINK_EXPORT SinkAccount : public ApplicationDomainType {
227 typedef QSharedPointer<SinkAccount> Ptr; 268 typedef QSharedPointer<SinkAccount> Ptr;
228 explicit SinkAccount(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor); 269 explicit SinkAccount(const QByteArray &resourceInstanceIdentifier, const QByteArray &identifier, qint64 revision, const QSharedPointer<BufferAdaptor> &adaptor);
@@ -318,6 +359,13 @@ struct SINK_EXPORT Mail : public Entity {
318 SINK_INDEX_PROPERTY(QByteArray, ThreadId, threadId); 359 SINK_INDEX_PROPERTY(QByteArray, ThreadId, threadId);
319}; 360};
320 361
362inline QDebug operator<< (QDebug d, const Mail::Contact &c)
363{
364 d << "Contact(" << c.name << ", " << c.emailAddress << ")";
365 return d;
366}
367
368
321/** 369/**
322 * The status of an account or resource. 370 * The status of an account or resource.
323 * 371 *
@@ -454,3 +502,4 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact)
454Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) 502Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error)
455Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) 503Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress)
456Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB) 504Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB)
505Q_DECLARE_METATYPE(Sink::ApplicationDomain::Reference)