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.h30
1 files changed, 26 insertions, 4 deletions
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h
index d6bbdd4..621a512 100644
--- a/common/domain/applicationdomaintype.h
+++ b/common/domain/applicationdomaintype.h
@@ -63,12 +63,12 @@
63#define SINK_BLOB_PROPERTY(NAME, LOWERCASENAME) \ 63#define SINK_BLOB_PROPERTY(NAME, LOWERCASENAME) \
64 struct NAME { \ 64 struct NAME { \
65 static constexpr const char *name = #LOWERCASENAME; \ 65 static constexpr const char *name = #LOWERCASENAME; \
66 typedef QString Type; \ 66 typedef BLOB Type; \
67 }; \ 67 }; \
68 void set##NAME(const QByteArray &value) { setBlobProperty(NAME::name, value); } \ 68 void set##NAME(const QByteArray &value) { setBlobProperty(NAME::name, value); } \
69 void set##NAME##Path(const QString &path) { setProperty(NAME::name, QVariant::fromValue(path)); } \ 69 void set##NAME##Path(const QString &path) { setProperty(NAME::name, QVariant::fromValue(BLOB{path})); } \
70 QByteArray get##NAME() const { return getBlobProperty(NAME::name); } \ 70 QByteArray get##NAME() const { return getBlobProperty(NAME::name); } \
71 QString get##NAME##Path() const { return getProperty(NAME::name).value<QString>(); } \ 71 QString get##NAME##Path() const { return getProperty(NAME::name).value<BLOB>().value; } \
72 72
73#define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \ 73#define SINK_REFERENCE_PROPERTY(TYPE, NAME, LOWERCASENAME) \
74 struct NAME { \ 74 struct NAME { \
@@ -98,6 +98,12 @@ struct SINK_EXPORT Progress {
98 98
99}; 99};
100 100
101struct BLOB {
102 QString value;
103};
104
105void copyBuffer(Sink::ApplicationDomain::BufferAdaptor &buffer, Sink::ApplicationDomain::BufferAdaptor &memoryAdaptor, const QList<QByteArray> &properties, bool copyBlobs);
106
101/** 107/**
102 * The domain type interface has two purposes: 108 * The domain type interface has two purposes:
103 * * provide a unified interface to read buffers (for zero-copy reading) 109 * * provide a unified interface to read buffers (for zero-copy reading)
@@ -115,14 +121,29 @@ public:
115 ApplicationDomainType(const ApplicationDomainType &other); 121 ApplicationDomainType(const ApplicationDomainType &other);
116 ApplicationDomainType& operator=(const ApplicationDomainType &other); 122 ApplicationDomainType& operator=(const ApplicationDomainType &other);
117 123
124 /**
125 * Returns an in memory representation of the same entity.
126 */
118 template <typename DomainType> 127 template <typename DomainType>
119 static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList<QByteArray> properties = QList<QByteArray>()) 128 static typename DomainType::Ptr getInMemoryRepresentation(const ApplicationDomainType &domainType, const QList<QByteArray> properties = QList<QByteArray>())
120 { 129 {
121 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(*(domainType.mAdaptor), properties); 130 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create(*(domainType.mAdaptor), properties);
122 //The identifier still internal refers to the memory-mapped pointer, we need to copy the memory or it will become invalid 131 //mIdentifier internally still refers to the memory-mapped memory, we need to copy the memory or it will become invalid
123 return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor); 132 return QSharedPointer<DomainType>::create(domainType.mResourceInstanceIdentifier, QByteArray(domainType.mIdentifier.constData(), domainType.mIdentifier.size()), domainType.mRevision, memoryAdaptor);
124 } 133 }
125 134
135 /**
136 * Returns an in memory copy without id and resource set.
137 */
138 template <typename DomainType>
139 static typename DomainType::Ptr getInMemoryCopy(const ApplicationDomainType &domainType, const QList<QByteArray> properties = QList<QByteArray>())
140 {
141 auto memoryAdaptor = QSharedPointer<Sink::ApplicationDomain::MemoryBufferAdaptor>::create();
142 Q_ASSERT(domainType.mAdaptor);
143 copyBuffer(*(domainType.mAdaptor), *memoryAdaptor, properties, true);
144 return QSharedPointer<DomainType>::create(QByteArray{}, QByteArray{}, 0, memoryAdaptor);
145 }
146
126 static QByteArray generateUid(); 147 static QByteArray generateUid();
127 148
128 template <class DomainType> 149 template <class DomainType>
@@ -430,3 +451,4 @@ Q_DECLARE_METATYPE(Sink::ApplicationDomain::Identity::Ptr)
430Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact) 451Q_DECLARE_METATYPE(Sink::ApplicationDomain::Mail::Contact)
431Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error) 452Q_DECLARE_METATYPE(Sink::ApplicationDomain::Error)
432Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress) 453Q_DECLARE_METATYPE(Sink::ApplicationDomain::Progress)
454Q_DECLARE_METATYPE(Sink::ApplicationDomain::BLOB)