diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-28 15:29:18 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-04-28 15:30:15 +0200 |
commit | ca5020095abfb76e63bd801e9722c07193eb05f5 (patch) | |
tree | 34d6344e982adcea4652a3ccb6bfb43b118a5189 | |
parent | a08984c450b1cd2584272b0d57a2f95ae3d074c3 (diff) | |
download | sink-ca5020095abfb76e63bd801e9722c07193eb05f5.tar.gz sink-ca5020095abfb76e63bd801e9722c07193eb05f5.zip |
A single propertymapper for both directions
-rw-r--r-- | common/domain/typeimplementations.cpp | 137 | ||||
-rw-r--r-- | common/domain/typeimplementations.h | 18 | ||||
-rw-r--r-- | common/domainadaptor.h | 23 | ||||
-rw-r--r-- | common/propertymapper.h | 64 | ||||
-rw-r--r-- | tests/domainadaptortest.cpp | 4 |
5 files changed, 89 insertions, 157 deletions
diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp index 598e5a7..a87e73d 100644 --- a/common/domain/typeimplementations.cpp +++ b/common/domain/typeimplementations.cpp | |||
@@ -32,6 +32,10 @@ | |||
32 | using namespace Sink; | 32 | using namespace Sink; |
33 | using namespace Sink::ApplicationDomain; | 33 | using namespace Sink::ApplicationDomain; |
34 | 34 | ||
35 | #define SINK_REGISTER_SERIALIZER(MAPPER, ENTITYTYPE, PROPERTY, LOWERCASEPROPERTY) \ | ||
36 | MAPPER.addMapping<ENTITYTYPE::PROPERTY, Sink::ApplicationDomain::Buffer::ENTITYTYPE, Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder>(&Sink::ApplicationDomain::Buffer::ENTITYTYPE::LOWERCASEPROPERTY, &Sink::ApplicationDomain::Buffer::ENTITYTYPE##Builder::add_##LOWERCASEPROPERTY); | ||
37 | |||
38 | |||
35 | void TypeImplementation<Mail>::configure(TypeIndex &index) | 39 | void TypeImplementation<Mail>::configure(TypeIndex &index) |
36 | { | 40 | { |
37 | // index.addProperty<Mail::Sender>(); | 41 | // index.addProperty<Mail::Sender>(); |
@@ -61,69 +65,39 @@ void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMappe | |||
61 | }); | 65 | }); |
62 | } | 66 | } |
63 | 67 | ||
64 | void TypeImplementation<Mail>::configure(ReadPropertyMapper &propertyMapper) | 68 | void TypeImplementation<Mail>::configure(PropertyMapper &propertyMapper) |
65 | { | ||
66 | propertyMapper.addMapping<Mail::Sender, Buffer>(&Buffer::sender); | ||
67 | propertyMapper.addMapping<Mail::To, Buffer>(&Buffer::to); | ||
68 | propertyMapper.addMapping<Mail::Cc, Buffer>(&Buffer::cc); | ||
69 | propertyMapper.addMapping<Mail::Bcc, Buffer>(&Buffer::bcc); | ||
70 | propertyMapper.addMapping<Mail::Subject, Buffer>(&Buffer::subject); | ||
71 | propertyMapper.addMapping<Mail::Date, Buffer>(&Buffer::date); | ||
72 | propertyMapper.addMapping<Mail::Unread, Buffer>(&Buffer::unread); | ||
73 | propertyMapper.addMapping<Mail::Important, Buffer>(&Buffer::important); | ||
74 | propertyMapper.addMapping<Mail::Folder, Buffer>(&Buffer::folder); | ||
75 | propertyMapper.addMapping<Mail::MimeMessage, Buffer>(&Buffer::mimeMessage); | ||
76 | propertyMapper.addMapping<Mail::FullPayloadAvailable, Buffer>(&Buffer::fullPayloadAvailable); | ||
77 | propertyMapper.addMapping<Mail::Draft, Buffer>(&Buffer::draft); | ||
78 | propertyMapper.addMapping<Mail::Trash, Buffer>(&Buffer::trash); | ||
79 | propertyMapper.addMapping<Mail::Sent, Buffer>(&Buffer::sent); | ||
80 | propertyMapper.addMapping<Mail::MessageId, Buffer>(&Buffer::messageId); | ||
81 | propertyMapper.addMapping<Mail::ParentMessageId, Buffer>(&Buffer::parentMessageId); | ||
82 | } | ||
83 | |||
84 | void TypeImplementation<Mail>::configure(WritePropertyMapper &propertyMapper) | ||
85 | { | 69 | { |
86 | propertyMapper.addMapping<Mail::Sender, BufferBuilder>(&BufferBuilder::add_sender); | 70 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Sender, sender); |
87 | propertyMapper.addMapping<Mail::To, BufferBuilder>(&BufferBuilder::add_to); | 71 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, To, to); |
88 | propertyMapper.addMapping<Mail::Cc, BufferBuilder>(&BufferBuilder::add_cc); | 72 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Cc, cc); |
89 | propertyMapper.addMapping<Mail::Bcc, BufferBuilder>(&BufferBuilder::add_bcc); | 73 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Bcc, bcc); |
90 | propertyMapper.addMapping<Mail::Subject, BufferBuilder>(&BufferBuilder::add_subject); | 74 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Subject, subject); |
91 | propertyMapper.addMapping<Mail::Date, BufferBuilder>(&BufferBuilder::add_date); | 75 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Date, date); |
92 | propertyMapper.addMapping<Mail::Unread, BufferBuilder>(&BufferBuilder::add_unread); | 76 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Unread, unread); |
93 | propertyMapper.addMapping<Mail::Important, BufferBuilder>(&BufferBuilder::add_important); | 77 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Important, important); |
94 | propertyMapper.addMapping<Mail::Folder, BufferBuilder>(&BufferBuilder::add_folder); | 78 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Folder, folder); |
95 | propertyMapper.addMapping<Mail::MimeMessage, BufferBuilder>(&BufferBuilder::add_mimeMessage); | 79 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, MimeMessage, mimeMessage); |
96 | propertyMapper.addMapping<Mail::FullPayloadAvailable, BufferBuilder>(&BufferBuilder::add_fullPayloadAvailable); | 80 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, FullPayloadAvailable, fullPayloadAvailable); |
97 | propertyMapper.addMapping<Mail::Draft, BufferBuilder>(&BufferBuilder::add_draft); | 81 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Draft, draft); |
98 | propertyMapper.addMapping<Mail::Trash, BufferBuilder>(&BufferBuilder::add_trash); | 82 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Trash, trash); |
99 | propertyMapper.addMapping<Mail::Sent, BufferBuilder>(&BufferBuilder::add_sent); | 83 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Sent, sent); |
100 | propertyMapper.addMapping<Mail::MessageId, BufferBuilder>(&BufferBuilder::add_messageId); | 84 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, MessageId, messageId); |
101 | propertyMapper.addMapping<Mail::ParentMessageId, BufferBuilder>(&BufferBuilder::add_parentMessageId); | 85 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, ParentMessageId, parentMessageId); |
102 | } | 86 | } |
103 | 87 | ||
104 | |||
105 | void TypeImplementation<Folder>::configure(TypeIndex &index) | 88 | void TypeImplementation<Folder>::configure(TypeIndex &index) |
106 | { | 89 | { |
107 | index.addProperty<QByteArray>(Folder::Parent::name); | 90 | index.addProperty<QByteArray>(Folder::Parent::name); |
108 | index.addProperty<QString>(Folder::Name::name); | 91 | index.addProperty<QString>(Folder::Name::name); |
109 | } | 92 | } |
110 | 93 | ||
111 | void TypeImplementation<Folder>::configure(ReadPropertyMapper &propertyMapper) | 94 | void TypeImplementation<Folder>::configure(PropertyMapper &propertyMapper) |
112 | { | ||
113 | propertyMapper.addMapping<Folder::Parent, Buffer>(&Buffer::parent); | ||
114 | propertyMapper.addMapping<Folder::Name, Buffer>(&Buffer::name); | ||
115 | propertyMapper.addMapping<Folder::Icon, Buffer>(&Buffer::icon); | ||
116 | propertyMapper.addMapping<Folder::SpecialPurpose, Buffer>(&Buffer::specialpurpose); | ||
117 | propertyMapper.addMapping<Folder::Enabled, Buffer>(&Buffer::enabled); | ||
118 | } | ||
119 | |||
120 | void TypeImplementation<Folder>::configure(WritePropertyMapper &propertyMapper) | ||
121 | { | 95 | { |
122 | propertyMapper.addMapping<Folder::Parent, BufferBuilder>(&BufferBuilder::add_parent); | 96 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Parent, parent); |
123 | propertyMapper.addMapping<Folder::Name, BufferBuilder>(&BufferBuilder::add_name); | 97 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Name, name); |
124 | propertyMapper.addMapping<Folder::Icon, BufferBuilder>(&BufferBuilder::add_icon); | 98 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Icon, icon); |
125 | propertyMapper.addMapping<Folder::SpecialPurpose, BufferBuilder>(&BufferBuilder::add_specialpurpose); | 99 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, SpecialPurpose, specialpurpose); |
126 | propertyMapper.addMapping<Folder::Enabled, BufferBuilder>(&BufferBuilder::add_enabled); | 100 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Enabled, enabled); |
127 | } | 101 | } |
128 | 102 | ||
129 | void TypeImplementation<Folder>::configure(IndexPropertyMapper &) | 103 | void TypeImplementation<Folder>::configure(IndexPropertyMapper &) |
@@ -137,26 +111,15 @@ void TypeImplementation<Contact>::configure(TypeIndex &index) | |||
137 | index.addProperty<QByteArray>(Contact::Uid::name); | 111 | index.addProperty<QByteArray>(Contact::Uid::name); |
138 | } | 112 | } |
139 | 113 | ||
140 | void TypeImplementation<Contact>::configure(ReadPropertyMapper &propertyMapper) | 114 | void TypeImplementation<Contact>::configure(PropertyMapper &propertyMapper) |
141 | { | 115 | { |
142 | propertyMapper.addMapping<Contact::Uid, Buffer>(&Buffer::uid); | 116 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Uid, uid); |
143 | propertyMapper.addMapping<Contact::Fn, Buffer>(&Buffer::fn); | 117 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Fn, fn); |
144 | propertyMapper.addMapping<Contact::Emails, Buffer>(&Buffer::emails); | 118 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Emails, emails); |
145 | propertyMapper.addMapping<Contact::Vcard, Buffer>(&Buffer::vcard); | 119 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Vcard, vcard); |
146 | propertyMapper.addMapping<Contact::Addressbook, Buffer>(&Buffer::addressbook); | 120 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Addressbook, addressbook); |
147 | propertyMapper.addMapping<Contact::Firstname, Buffer>(&Buffer::firstname); | 121 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Firstname, firstname); |
148 | propertyMapper.addMapping<Contact::Lastname, Buffer>(&Buffer::lastname); | 122 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Lastname, lastname); |
149 | } | ||
150 | |||
151 | void TypeImplementation<Contact>::configure(WritePropertyMapper &propertyMapper) | ||
152 | { | ||
153 | propertyMapper.addMapping<Contact::Uid, BufferBuilder>(&BufferBuilder::add_uid); | ||
154 | propertyMapper.addMapping<Contact::Fn, BufferBuilder>(&BufferBuilder::add_fn); | ||
155 | propertyMapper.addMapping<Contact::Emails, BufferBuilder>(&BufferBuilder::add_emails); | ||
156 | propertyMapper.addMapping<Contact::Vcard, BufferBuilder>(&BufferBuilder::add_vcard); | ||
157 | propertyMapper.addMapping<Contact::Addressbook, BufferBuilder>(&BufferBuilder::add_addressbook); | ||
158 | propertyMapper.addMapping<Contact::Firstname, BufferBuilder>(&BufferBuilder::add_firstname); | ||
159 | propertyMapper.addMapping<Contact::Lastname, BufferBuilder>(&BufferBuilder::add_lastname); | ||
160 | } | 123 | } |
161 | 124 | ||
162 | void TypeImplementation<Contact>::configure(IndexPropertyMapper &) | 125 | void TypeImplementation<Contact>::configure(IndexPropertyMapper &) |
@@ -171,16 +134,10 @@ void TypeImplementation<Addressbook>::configure(TypeIndex &index) | |||
171 | index.addProperty<QString>(Addressbook::Name::name); | 134 | index.addProperty<QString>(Addressbook::Name::name); |
172 | } | 135 | } |
173 | 136 | ||
174 | void TypeImplementation<Addressbook>::configure(ReadPropertyMapper &propertyMapper) | 137 | void TypeImplementation<Addressbook>::configure(PropertyMapper &propertyMapper) |
175 | { | 138 | { |
176 | propertyMapper.addMapping<Addressbook::Parent, Buffer>(&Buffer::parent); | 139 | SINK_REGISTER_SERIALIZER(propertyMapper, Addressbook, Parent, parent); |
177 | propertyMapper.addMapping<Addressbook::Name, Buffer>(&Buffer::name); | 140 | SINK_REGISTER_SERIALIZER(propertyMapper, Addressbook, Name, name); |
178 | } | ||
179 | |||
180 | void TypeImplementation<Addressbook>::configure(WritePropertyMapper &propertyMapper) | ||
181 | { | ||
182 | propertyMapper.addMapping<Addressbook::Parent, BufferBuilder>(&BufferBuilder::add_parent); | ||
183 | propertyMapper.addMapping<Addressbook::Name, BufferBuilder>(&BufferBuilder::add_name); | ||
184 | } | 141 | } |
185 | 142 | ||
186 | void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &) | 143 | void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &) |
@@ -194,20 +151,12 @@ void TypeImplementation<Event>::configure(TypeIndex &index) | |||
194 | index.addProperty<QByteArray>(Event::Uid::name); | 151 | index.addProperty<QByteArray>(Event::Uid::name); |
195 | } | 152 | } |
196 | 153 | ||
197 | void TypeImplementation<Event>::configure(ReadPropertyMapper &propertyMapper) | 154 | void TypeImplementation<Event>::configure(PropertyMapper &propertyMapper) |
198 | { | ||
199 | propertyMapper.addMapping<Event::Summary, Buffer>(&Buffer::summary); | ||
200 | propertyMapper.addMapping<Event::Description, Buffer>(&Buffer::description); | ||
201 | propertyMapper.addMapping<Event::Uid, Buffer>(&Buffer::uid); | ||
202 | propertyMapper.addMapping<Event::Attachment, Buffer>(&Buffer::attachment); | ||
203 | } | ||
204 | |||
205 | void TypeImplementation<Event>::configure(WritePropertyMapper &propertyMapper) | ||
206 | { | 155 | { |
207 | propertyMapper.addMapping<Event::Summary, BufferBuilder>(&BufferBuilder::add_summary); | 156 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Summary, summary); |
208 | propertyMapper.addMapping<Event::Description, BufferBuilder>(&BufferBuilder::add_description); | 157 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Description, description); |
209 | propertyMapper.addMapping<Event::Uid, BufferBuilder>(&BufferBuilder::add_uid); | 158 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Uid, uid); |
210 | propertyMapper.addMapping<Event::Attachment, BufferBuilder>(&BufferBuilder::add_attachment); | 159 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Attachment, attachment); |
211 | } | 160 | } |
212 | 161 | ||
213 | void TypeImplementation<Event>::configure(IndexPropertyMapper &) | 162 | void TypeImplementation<Event>::configure(IndexPropertyMapper &) |
diff --git a/common/domain/typeimplementations.h b/common/domain/typeimplementations.h index 8acea58..7e4608c 100644 --- a/common/domain/typeimplementations.h +++ b/common/domain/typeimplementations.h | |||
@@ -26,8 +26,7 @@ | |||
26 | #include "contact_generated.h" | 26 | #include "contact_generated.h" |
27 | #include "addressbook_generated.h" | 27 | #include "addressbook_generated.h" |
28 | 28 | ||
29 | class ReadPropertyMapper; | 29 | class PropertyMapper; |
30 | class WritePropertyMapper; | ||
31 | class IndexPropertyMapper; | 30 | class IndexPropertyMapper; |
32 | 31 | ||
33 | class TypeIndex; | 32 | class TypeIndex; |
@@ -46,8 +45,7 @@ public: | |||
46 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; | 45 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; |
47 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; | 46 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; |
48 | static void configure(TypeIndex &index); | 47 | static void configure(TypeIndex &index); |
49 | static void configure(ReadPropertyMapper &propertyMapper); | 48 | static void configure(PropertyMapper &propertyMapper); |
50 | static void configure(WritePropertyMapper &propertyMapper); | ||
51 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 49 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
52 | }; | 50 | }; |
53 | 51 | ||
@@ -57,8 +55,7 @@ public: | |||
57 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; | 55 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; |
58 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; | 56 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; |
59 | static void configure(TypeIndex &); | 57 | static void configure(TypeIndex &); |
60 | static void configure(ReadPropertyMapper &); | 58 | static void configure(PropertyMapper &); |
61 | static void configure(WritePropertyMapper &); | ||
62 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 59 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
63 | }; | 60 | }; |
64 | 61 | ||
@@ -68,8 +65,7 @@ public: | |||
68 | typedef Sink::ApplicationDomain::Buffer::Contact Buffer; | 65 | typedef Sink::ApplicationDomain::Buffer::Contact Buffer; |
69 | typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; | 66 | typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; |
70 | static void configure(TypeIndex &); | 67 | static void configure(TypeIndex &); |
71 | static void configure(ReadPropertyMapper &); | 68 | static void configure(PropertyMapper &); |
72 | static void configure(WritePropertyMapper &); | ||
73 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 69 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
74 | }; | 70 | }; |
75 | 71 | ||
@@ -79,8 +75,7 @@ public: | |||
79 | typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; | 75 | typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; |
80 | typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; | 76 | typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; |
81 | static void configure(TypeIndex &); | 77 | static void configure(TypeIndex &); |
82 | static void configure(ReadPropertyMapper &); | 78 | static void configure(PropertyMapper &); |
83 | static void configure(WritePropertyMapper &); | ||
84 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 79 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
85 | }; | 80 | }; |
86 | 81 | ||
@@ -90,8 +85,7 @@ public: | |||
90 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; | 85 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; |
91 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; | 86 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; |
92 | static void configure(TypeIndex &); | 87 | static void configure(TypeIndex &); |
93 | static void configure(ReadPropertyMapper &); | 88 | static void configure(PropertyMapper &); |
94 | static void configure(WritePropertyMapper &); | ||
95 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 89 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
96 | }; | 90 | }; |
97 | 91 | ||
diff --git a/common/domainadaptor.h b/common/domainadaptor.h index 1db43ca..c38b713 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h | |||
@@ -38,7 +38,7 @@ | |||
38 | */ | 38 | */ |
39 | template <class Builder, class Buffer> | 39 | template <class Builder, class Buffer> |
40 | flatbuffers::Offset<Buffer> | 40 | flatbuffers::Offset<Buffer> |
41 | createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const WritePropertyMapper &mapper) | 41 | createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, const PropertyMapper &mapper) |
42 | { | 42 | { |
43 | // First create a primitives such as strings using the mappings | 43 | // First create a primitives such as strings using the mappings |
44 | QList<std::function<void(void *builder)>> propertiesToAddToResource; | 44 | QList<std::function<void(void *builder)>> propertiesToAddToResource; |
@@ -66,7 +66,7 @@ createBufferPart(const Sink::ApplicationDomain::ApplicationDomainType &domainObj | |||
66 | * After this the buffer can be extracted from the FlatBufferBuilder object. | 66 | * After this the buffer can be extracted from the FlatBufferBuilder object. |
67 | */ | 67 | */ |
68 | template <typename Buffer, typename BufferBuilder> | 68 | template <typename Buffer, typename BufferBuilder> |
69 | static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, WritePropertyMapper &mapper) | 69 | static void createBufferPartBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, PropertyMapper &mapper) |
70 | { | 70 | { |
71 | auto pos = createBufferPart<BufferBuilder, Buffer>(domainObject, fbb, mapper); | 71 | auto pos = createBufferPart<BufferBuilder, Buffer>(domainObject, fbb, mapper); |
72 | // Because we cannot template the following call | 72 | // Because we cannot template the following call |
@@ -151,7 +151,7 @@ public: | |||
151 | } | 151 | } |
152 | 152 | ||
153 | void const *mLocalBuffer; | 153 | void const *mLocalBuffer; |
154 | QSharedPointer<ReadPropertyMapper> mLocalMapper; | 154 | QSharedPointer<PropertyMapper> mLocalMapper; |
155 | QSharedPointer<IndexPropertyMapper> mIndexMapper; | 155 | QSharedPointer<IndexPropertyMapper> mIndexMapper; |
156 | TypeIndex *mIndex; | 156 | TypeIndex *mIndex; |
157 | }; | 157 | }; |
@@ -169,12 +169,10 @@ class SINK_EXPORT DomainTypeAdaptorFactory : public DomainTypeAdaptorFactoryInte | |||
169 | 169 | ||
170 | public: | 170 | public: |
171 | DomainTypeAdaptorFactory() | 171 | DomainTypeAdaptorFactory() |
172 | : mLocalMapper(QSharedPointer<ReadPropertyMapper>::create()), | 172 | : mPropertyMapper(QSharedPointer<PropertyMapper>::create()), |
173 | mLocalWriteMapper(QSharedPointer<WritePropertyMapper>::create()), | ||
174 | mIndexMapper(QSharedPointer<IndexPropertyMapper>::create()) | 173 | mIndexMapper(QSharedPointer<IndexPropertyMapper>::create()) |
175 | { | 174 | { |
176 | Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalMapper); | 175 | Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mPropertyMapper); |
177 | Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mLocalWriteMapper); | ||
178 | Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mIndexMapper); | 176 | Sink::ApplicationDomain::TypeImplementation<DomainType>::configure(*mIndexMapper); |
179 | } | 177 | } |
180 | 178 | ||
@@ -189,7 +187,7 @@ public: | |||
189 | { | 187 | { |
190 | auto adaptor = QSharedPointer<DatastoreBufferAdaptor>::create(); | 188 | auto adaptor = QSharedPointer<DatastoreBufferAdaptor>::create(); |
191 | adaptor->mLocalBuffer = Sink::EntityBuffer::readBuffer<LocalBuffer>(entity.local()); | 189 | adaptor->mLocalBuffer = Sink::EntityBuffer::readBuffer<LocalBuffer>(entity.local()); |
192 | adaptor->mLocalMapper = mLocalMapper; | 190 | adaptor->mLocalMapper = mPropertyMapper; |
193 | adaptor->mIndexMapper = mIndexMapper; | 191 | adaptor->mIndexMapper = mIndexMapper; |
194 | adaptor->mIndex = index; | 192 | adaptor->mIndex = index; |
195 | return adaptor; | 193 | return adaptor; |
@@ -199,11 +197,7 @@ public: | |||
199 | createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE | 197 | createBuffer(const Sink::ApplicationDomain::ApplicationDomainType &domainObject, flatbuffers::FlatBufferBuilder &fbb, void const *metadataData = 0, size_t metadataSize = 0) Q_DECL_OVERRIDE |
200 | { | 198 | { |
201 | flatbuffers::FlatBufferBuilder localFbb; | 199 | flatbuffers::FlatBufferBuilder localFbb; |
202 | if (mLocalWriteMapper) { | 200 | createBufferPartBuffer<LocalBuffer, LocalBuilder>(domainObject, localFbb, *mPropertyMapper); |
203 | // SinkTrace() << "Creating local buffer part"; | ||
204 | createBufferPartBuffer<LocalBuffer, LocalBuilder>(domainObject, localFbb, *mLocalWriteMapper); | ||
205 | } | ||
206 | |||
207 | Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, 0, 0, localFbb.GetBufferPointer(), localFbb.GetSize()); | 201 | Sink::EntityBuffer::assembleEntityBuffer(fbb, metadataData, metadataSize, 0, 0, localFbb.GetBufferPointer(), localFbb.GetSize()); |
208 | return true; | 202 | return true; |
209 | } | 203 | } |
@@ -219,8 +213,7 @@ public: | |||
219 | 213 | ||
220 | 214 | ||
221 | protected: | 215 | protected: |
222 | QSharedPointer<ReadPropertyMapper> mLocalMapper; | 216 | QSharedPointer<PropertyMapper> mPropertyMapper; |
223 | QSharedPointer<WritePropertyMapper> mLocalWriteMapper; | ||
224 | QSharedPointer<IndexPropertyMapper> mIndexMapper; | 217 | QSharedPointer<IndexPropertyMapper> mIndexMapper; |
225 | }; | 218 | }; |
226 | 219 | ||
diff --git a/common/propertymapper.h b/common/propertymapper.h index fa4592b..fd24278 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -65,10 +65,17 @@ QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Of | |||
65 | * a virtual method per property, the property mapper can be filled with accessors | 65 | * a virtual method per property, the property mapper can be filled with accessors |
66 | * that extract the properties from resource types. | 66 | * that extract the properties from resource types. |
67 | */ | 67 | */ |
68 | class ReadPropertyMapper | 68 | class PropertyMapper |
69 | { | 69 | { |
70 | public: | 70 | public: |
71 | virtual ~ReadPropertyMapper(){}; | 71 | virtual ~PropertyMapper(){}; |
72 | |||
73 | template <typename T, typename Buffer, typename BufferBuilder, typename FunctionReturnValue, typename Arg> | ||
74 | void addMapping(FunctionReturnValue (Buffer::*f)() const, void (BufferBuilder::*f2)(Arg)) | ||
75 | { | ||
76 | addReadMapping<T, Buffer, FunctionReturnValue>(f); | ||
77 | addWriteMapping<T, BufferBuilder>(f2); | ||
78 | } | ||
72 | 79 | ||
73 | virtual QVariant getProperty(const QByteArray &key, void const *buffer) const | 80 | virtual QVariant getProperty(const QByteArray &key, void const *buffer) const |
74 | { | 81 | { |
@@ -79,6 +86,14 @@ public: | |||
79 | return QVariant(); | 86 | return QVariant(); |
80 | } | 87 | } |
81 | 88 | ||
89 | virtual void setProperty(const QByteArray &key, const QVariant &value, QList<std::function<void(void *builder)>> &builderCalls, flatbuffers::FlatBufferBuilder &fbb) const | ||
90 | { | ||
91 | if (mWriteAccessors.contains(key)) { | ||
92 | auto accessor = mWriteAccessors.value(key); | ||
93 | builderCalls << accessor(value, fbb); | ||
94 | } | ||
95 | } | ||
96 | |||
82 | bool hasMapping(const QByteArray &key) const | 97 | bool hasMapping(const QByteArray &key) const |
83 | { | 98 | { |
84 | return mReadAccessors.contains(key); | 99 | return mReadAccessors.contains(key); |
@@ -89,69 +104,50 @@ public: | |||
89 | return mReadAccessors.keys(); | 104 | return mReadAccessors.keys(); |
90 | } | 105 | } |
91 | 106 | ||
92 | void addMapping(const QByteArray &property, const std::function<QVariant(void const *)> &mapping) | 107 | private: |
108 | void addReadMapping(const QByteArray &property, const std::function<QVariant(void const *)> &mapping) | ||
93 | { | 109 | { |
94 | mReadAccessors.insert(property, mapping); | 110 | mReadAccessors.insert(property, mapping); |
95 | } | 111 | } |
96 | 112 | ||
97 | template <typename T, typename Buffer, typename FunctionReturnValue> | 113 | template <typename T, typename Buffer, typename FunctionReturnValue> |
98 | void addMapping(FunctionReturnValue (Buffer::*f)() const) | 114 | void addReadMapping(FunctionReturnValue (Buffer::*f)() const) |
99 | { | 115 | { |
100 | addMapping(T::name, [f](void const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((static_cast<const Buffer*>(buffer)->*f)()); }); | 116 | addReadMapping(T::name, [f](void const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((static_cast<const Buffer*>(buffer)->*f)()); }); |
101 | } | 117 | } |
102 | 118 | ||
103 | private: | ||
104 | QHash<QByteArray, std::function<QVariant(void const *)>> mReadAccessors; | ||
105 | }; | ||
106 | 119 | ||
107 | class WritePropertyMapper | 120 | void addWriteMapping(const QByteArray &property, const std::function<std::function<void(void *builder)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> &mapping) |
108 | { | ||
109 | public: | ||
110 | virtual ~WritePropertyMapper(){}; | ||
111 | |||
112 | virtual void setProperty(const QByteArray &key, const QVariant &value, QList<std::function<void(void *builder)>> &builderCalls, flatbuffers::FlatBufferBuilder &fbb) const | ||
113 | { | ||
114 | if (mWriteAccessors.contains(key)) { | ||
115 | auto accessor = mWriteAccessors.value(key); | ||
116 | builderCalls << accessor(value, fbb); | ||
117 | } | ||
118 | } | ||
119 | |||
120 | bool hasMapping(const QByteArray &key) const | ||
121 | { | ||
122 | return mWriteAccessors.contains(key); | ||
123 | } | ||
124 | |||
125 | void addMapping(const QByteArray &property, const std::function<std::function<void(void *builder)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> &mapping) | ||
126 | { | 121 | { |
127 | mWriteAccessors.insert(property, mapping); | 122 | mWriteAccessors.insert(property, mapping); |
128 | } | 123 | } |
129 | 124 | ||
130 | template <typename T, typename BufferBuilder> | 125 | template <typename T, typename BufferBuilder> |
131 | void addMapping(void (BufferBuilder::*f)(uint8_t)) | 126 | void addWriteMapping(void (BufferBuilder::*f)(uint8_t)) |
132 | { | 127 | { |
133 | addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> { | 128 | addWriteMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> { |
134 | return [value, f](void *builder) { (static_cast<BufferBuilder*>(builder)->*f)(value.value<typename T::Type>()); }; | 129 | return [value, f](void *builder) { (static_cast<BufferBuilder*>(builder)->*f)(value.value<typename T::Type>()); }; |
135 | }); | 130 | }); |
136 | } | 131 | } |
137 | 132 | ||
138 | template <typename T, typename BufferBuilder> | 133 | template <typename T, typename BufferBuilder> |
139 | void addMapping(void (BufferBuilder::*f)(bool)) | 134 | void addWriteMapping(void (BufferBuilder::*f)(bool)) |
140 | { | 135 | { |
141 | addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> { | 136 | addWriteMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> { |
142 | return [value, f](void *builder) { (static_cast<BufferBuilder*>(builder)->*f)(value.value<typename T::Type>()); }; | 137 | return [value, f](void *builder) { (static_cast<BufferBuilder*>(builder)->*f)(value.value<typename T::Type>()); }; |
143 | }); | 138 | }); |
144 | } | 139 | } |
145 | 140 | ||
146 | template <typename T, typename BufferBuilder, typename Arg> | 141 | template <typename T, typename BufferBuilder, typename Arg> |
147 | void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset<Arg>)) | 142 | void addWriteMapping(void (BufferBuilder::*f)(flatbuffers::Offset<Arg>)) |
148 | { | 143 | { |
149 | addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> { | 144 | addWriteMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(void *builder)> { |
150 | auto offset = variantToProperty<typename T::Type>(value, fbb); | 145 | auto offset = variantToProperty<typename T::Type>(value, fbb); |
151 | return [offset, f](void *builder) { (static_cast<BufferBuilder*>(builder)->*f)(offset); }; | 146 | return [offset, f](void *builder) { (static_cast<BufferBuilder*>(builder)->*f)(offset); }; |
152 | }); | 147 | }); |
153 | } | 148 | } |
154 | 149 | ||
155 | private: | 150 | QHash<QByteArray, std::function<QVariant(void const *)>> mReadAccessors; |
156 | QHash<QByteArray, std::function<std::function<void(void *builder)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; | 151 | QHash<QByteArray, std::function<std::function<void(void *builder)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; |
157 | }; | 152 | }; |
153 | |||
diff --git a/tests/domainadaptortest.cpp b/tests/domainadaptortest.cpp index 2b7455a..df44819 100644 --- a/tests/domainadaptortest.cpp +++ b/tests/domainadaptortest.cpp | |||
@@ -47,7 +47,7 @@ private slots: | |||
47 | 47 | ||
48 | void testCreateBufferPart() | 48 | void testCreateBufferPart() |
49 | { | 49 | { |
50 | auto writeMapper = QSharedPointer<WritePropertyMapper>::create(); | 50 | auto writeMapper = QSharedPointer<PropertyMapper>::create(); |
51 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Event>::configure(*writeMapper); | 51 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Event>::configure(*writeMapper); |
52 | 52 | ||
53 | Sink::ApplicationDomain::Event event; | 53 | Sink::ApplicationDomain::Event event; |
@@ -100,7 +100,7 @@ private slots: | |||
100 | 100 | ||
101 | void testMail() | 101 | void testMail() |
102 | { | 102 | { |
103 | auto writeMapper = QSharedPointer<WritePropertyMapper>::create(); | 103 | auto writeMapper = QSharedPointer<PropertyMapper>::create(); |
104 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Mail>::configure(*writeMapper); | 104 | Sink::ApplicationDomain::TypeImplementation<Sink::ApplicationDomain::Mail>::configure(*writeMapper); |
105 | 105 | ||
106 | Sink::ApplicationDomain::Mail mail; | 106 | Sink::ApplicationDomain::Mail mail; |