diff options
Diffstat (limited to 'common/domain')
-rw-r--r-- | common/domain/applicationdomaintype.cpp | 3 | ||||
-rw-r--r-- | common/domain/applicationdomaintype.h | 1 | ||||
-rw-r--r-- | common/domain/contact.fbs | 1 | ||||
-rw-r--r-- | common/domain/typeimplementations.cpp | 193 | ||||
-rw-r--r-- | common/domain/typeimplementations.h | 25 | ||||
-rw-r--r-- | common/domain/typeimplementations_p.h | 154 |
6 files changed, 261 insertions, 116 deletions
diff --git a/common/domain/applicationdomaintype.cpp b/common/domain/applicationdomaintype.cpp index 67d463f..3718f77 100644 --- a/common/domain/applicationdomaintype.cpp +++ b/common/domain/applicationdomaintype.cpp | |||
@@ -25,8 +25,6 @@ | |||
25 | #include "storage.h" //for generateUid() | 25 | #include "storage.h" //for generateUid() |
26 | #include <QFile> | 26 | #include <QFile> |
27 | 27 | ||
28 | SINK_DEBUG_AREA("applicationdomaintype"); | ||
29 | |||
30 | QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::Mail::Contact &c) | 28 | QDebug Sink::ApplicationDomain::operator<< (QDebug d, const Sink::ApplicationDomain::Mail::Contact &c) |
31 | { | 29 | { |
32 | d << "Contact(" << c.name << ", " << c.emailAddress << ")"; | 30 | d << "Contact(" << c.name << ", " << c.emailAddress << ")"; |
@@ -114,6 +112,7 @@ SINK_REGISTER_PROPERTY(Contact, Lastname); | |||
114 | SINK_REGISTER_PROPERTY(Contact, Emails); | 112 | SINK_REGISTER_PROPERTY(Contact, Emails); |
115 | SINK_REGISTER_PROPERTY(Contact, Vcard); | 113 | SINK_REGISTER_PROPERTY(Contact, Vcard); |
116 | SINK_REGISTER_PROPERTY(Contact, Addressbook); | 114 | SINK_REGISTER_PROPERTY(Contact, Addressbook); |
115 | SINK_REGISTER_PROPERTY(Contact, Photo); | ||
117 | 116 | ||
118 | SINK_REGISTER_ENTITY(Addressbook); | 117 | SINK_REGISTER_ENTITY(Addressbook); |
119 | SINK_REGISTER_PROPERTY(Addressbook, Name); | 118 | SINK_REGISTER_PROPERTY(Addressbook, Name); |
diff --git a/common/domain/applicationdomaintype.h b/common/domain/applicationdomaintype.h index e5aa46e..602d54c 100644 --- a/common/domain/applicationdomaintype.h +++ b/common/domain/applicationdomaintype.h | |||
@@ -377,6 +377,7 @@ struct SINK_EXPORT Contact : public Entity { | |||
377 | SINK_PROPERTY(QString, Lastname, lastname); | 377 | SINK_PROPERTY(QString, Lastname, lastname); |
378 | SINK_PROPERTY(QList<Email>, Emails, emails); | 378 | SINK_PROPERTY(QList<Email>, Emails, emails); |
379 | SINK_PROPERTY(QByteArray, Vcard, vcard); | 379 | SINK_PROPERTY(QByteArray, Vcard, vcard); |
380 | SINK_PROPERTY(QByteArray, Photo, photo); | ||
380 | SINK_REFERENCE_PROPERTY(Addressbook, Addressbook, addressbook); | 381 | SINK_REFERENCE_PROPERTY(Addressbook, Addressbook, addressbook); |
381 | }; | 382 | }; |
382 | 383 | ||
diff --git a/common/domain/contact.fbs b/common/domain/contact.fbs index d941d5a..e689756 100644 --- a/common/domain/contact.fbs +++ b/common/domain/contact.fbs | |||
@@ -13,6 +13,7 @@ table Contact { | |||
13 | addressbook:string; | 13 | addressbook:string; |
14 | emails: [ContactEmail]; | 14 | emails: [ContactEmail]; |
15 | vcard: string; | 15 | vcard: string; |
16 | photo: string; | ||
16 | } | 17 | } |
17 | 18 | ||
18 | root_type Contact; | 19 | root_type Contact; |
diff --git a/common/domain/typeimplementations.cpp b/common/domain/typeimplementations.cpp index eb3851e..47a9cf7 100644 --- a/common/domain/typeimplementations.cpp +++ b/common/domain/typeimplementations.cpp | |||
@@ -28,25 +28,52 @@ | |||
28 | #include "entity_generated.h" | 28 | #include "entity_generated.h" |
29 | #include "mail/threadindexer.h" | 29 | #include "mail/threadindexer.h" |
30 | #include "domainadaptor.h" | 30 | #include "domainadaptor.h" |
31 | #include "typeimplementations_p.h" | ||
31 | 32 | ||
32 | using namespace Sink; | 33 | using namespace Sink; |
33 | using namespace Sink::ApplicationDomain; | 34 | using namespace Sink::ApplicationDomain; |
34 | 35 | ||
36 | #define SINK_REGISTER_SERIALIZER(MAPPER, ENTITYTYPE, PROPERTY, LOWERCASEPROPERTY) \ | ||
37 | 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); | ||
38 | |||
39 | typedef IndexConfig<Mail, | ||
40 | ValueIndex<Mail::Date>, | ||
41 | ValueIndex<Mail::Folder>, | ||
42 | ValueIndex<Mail::ParentMessageId>, | ||
43 | ValueIndex<Mail::MessageId>, | ||
44 | ValueIndex<Mail::Draft>, | ||
45 | SortedIndex<Mail::Folder, Mail::Date>, | ||
46 | SecondaryIndex<Mail::MessageId, Mail::ThreadId>, | ||
47 | SecondaryIndex<Mail::ThreadId, Mail::MessageId>, | ||
48 | CustomSecondaryIndex<Mail::MessageId, Mail::ThreadId, ThreadIndexer> | ||
49 | > MailIndexConfig; | ||
50 | |||
51 | typedef IndexConfig<Folder, | ||
52 | ValueIndex<Folder::Name>, | ||
53 | ValueIndex<Folder::Parent> | ||
54 | > FolderIndexConfig; | ||
55 | |||
56 | typedef IndexConfig<Contact, | ||
57 | ValueIndex<Contact::Uid> | ||
58 | > ContactIndexConfig; | ||
59 | |||
60 | typedef IndexConfig<Addressbook, | ||
61 | ValueIndex<Addressbook::Parent> | ||
62 | > AddressbookIndexConfig; | ||
63 | |||
64 | typedef IndexConfig<Event, | ||
65 | ValueIndex<Event::Uid> | ||
66 | > EventIndexConfig; | ||
67 | |||
68 | |||
35 | void TypeImplementation<Mail>::configure(TypeIndex &index) | 69 | void TypeImplementation<Mail>::configure(TypeIndex &index) |
36 | { | 70 | { |
37 | // index.addProperty<Mail::Sender>(); | 71 | MailIndexConfig::configure(index); |
38 | /* index.addProperty<QByteArray>(Mail::SenderName::name); */ | 72 | } |
39 | /* index->addProperty<QString>(Mail::Subject::name); */ | ||
40 | /* index->addFulltextProperty<QString>(Mail::Subject::name); */ | ||
41 | index.addProperty<Mail::Date>(); | ||
42 | index.addProperty<Mail::Folder>(); | ||
43 | index.addPropertyWithSorting<Mail::Folder, Mail::Date>(); | ||
44 | index.addProperty<Mail::ParentMessageId>(); | ||
45 | index.addProperty<Mail::MessageId>(); | ||
46 | 73 | ||
47 | index.addSecondaryPropertyIndexer<Mail::MessageId, Mail::ThreadId, ThreadIndexer>(); | 74 | QMap<QByteArray, int> TypeImplementation<Mail>::typeDatabases() |
48 | index.addSecondaryProperty<Mail::MessageId, Mail::ThreadId>(); | 75 | { |
49 | index.addSecondaryProperty<Mail::ThreadId, Mail::MessageId>(); | 76 | return merge(QMap<QByteArray, int>{{QByteArray{Mail::name} + ".main", 0}}, MailIndexConfig::databases()); |
50 | } | 77 | } |
51 | 78 | ||
52 | void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMapper) | 79 | void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMapper) |
@@ -61,69 +88,44 @@ void TypeImplementation<Mail>::configure(IndexPropertyMapper &indexPropertyMappe | |||
61 | }); | 88 | }); |
62 | } | 89 | } |
63 | 90 | ||
64 | void TypeImplementation<Mail>::configure(ReadPropertyMapper<Buffer> &propertyMapper) | 91 | void TypeImplementation<Mail>::configure(PropertyMapper &propertyMapper) |
65 | { | 92 | { |
66 | propertyMapper.addMapping<Mail::Sender, Buffer>(&Buffer::sender); | 93 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Sender, sender); |
67 | propertyMapper.addMapping<Mail::To, Buffer>(&Buffer::to); | 94 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, To, to); |
68 | propertyMapper.addMapping<Mail::Cc, Buffer>(&Buffer::cc); | 95 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Cc, cc); |
69 | propertyMapper.addMapping<Mail::Bcc, Buffer>(&Buffer::bcc); | 96 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Bcc, bcc); |
70 | propertyMapper.addMapping<Mail::Subject, Buffer>(&Buffer::subject); | 97 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Subject, subject); |
71 | propertyMapper.addMapping<Mail::Date, Buffer>(&Buffer::date); | 98 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Date, date); |
72 | propertyMapper.addMapping<Mail::Unread, Buffer>(&Buffer::unread); | 99 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Unread, unread); |
73 | propertyMapper.addMapping<Mail::Important, Buffer>(&Buffer::important); | 100 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Important, important); |
74 | propertyMapper.addMapping<Mail::Folder, Buffer>(&Buffer::folder); | 101 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Folder, folder); |
75 | propertyMapper.addMapping<Mail::MimeMessage, Buffer>(&Buffer::mimeMessage); | 102 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, MimeMessage, mimeMessage); |
76 | propertyMapper.addMapping<Mail::FullPayloadAvailable, Buffer>(&Buffer::fullPayloadAvailable); | 103 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, FullPayloadAvailable, fullPayloadAvailable); |
77 | propertyMapper.addMapping<Mail::Draft, Buffer>(&Buffer::draft); | 104 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Draft, draft); |
78 | propertyMapper.addMapping<Mail::Trash, Buffer>(&Buffer::trash); | 105 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Trash, trash); |
79 | propertyMapper.addMapping<Mail::Sent, Buffer>(&Buffer::sent); | 106 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, Sent, sent); |
80 | propertyMapper.addMapping<Mail::MessageId, Buffer>(&Buffer::messageId); | 107 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, MessageId, messageId); |
81 | propertyMapper.addMapping<Mail::ParentMessageId, Buffer>(&Buffer::parentMessageId); | 108 | SINK_REGISTER_SERIALIZER(propertyMapper, Mail, ParentMessageId, parentMessageId); |
82 | } | ||
83 | |||
84 | void TypeImplementation<Mail>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper) | ||
85 | { | ||
86 | propertyMapper.addMapping<Mail::Sender>(&BufferBuilder::add_sender); | ||
87 | propertyMapper.addMapping<Mail::To>(&BufferBuilder::add_to); | ||
88 | propertyMapper.addMapping<Mail::Cc>(&BufferBuilder::add_cc); | ||
89 | propertyMapper.addMapping<Mail::Bcc>(&BufferBuilder::add_bcc); | ||
90 | propertyMapper.addMapping<Mail::Subject>(&BufferBuilder::add_subject); | ||
91 | propertyMapper.addMapping<Mail::Date>(&BufferBuilder::add_date); | ||
92 | propertyMapper.addMapping<Mail::Unread>(&BufferBuilder::add_unread); | ||
93 | propertyMapper.addMapping<Mail::Important>(&BufferBuilder::add_important); | ||
94 | propertyMapper.addMapping<Mail::Folder>(&BufferBuilder::add_folder); | ||
95 | propertyMapper.addMapping<Mail::MimeMessage>(&BufferBuilder::add_mimeMessage); | ||
96 | propertyMapper.addMapping<Mail::FullPayloadAvailable>(&BufferBuilder::add_fullPayloadAvailable); | ||
97 | propertyMapper.addMapping<Mail::Draft>(&BufferBuilder::add_draft); | ||
98 | propertyMapper.addMapping<Mail::Trash>(&BufferBuilder::add_trash); | ||
99 | propertyMapper.addMapping<Mail::Sent>(&BufferBuilder::add_sent); | ||
100 | propertyMapper.addMapping<Mail::MessageId>(&BufferBuilder::add_messageId); | ||
101 | propertyMapper.addMapping<Mail::ParentMessageId>(&BufferBuilder::add_parentMessageId); | ||
102 | } | 109 | } |
103 | 110 | ||
104 | 111 | ||
105 | void TypeImplementation<Folder>::configure(TypeIndex &index) | 112 | void TypeImplementation<Folder>::configure(TypeIndex &index) |
106 | { | 113 | { |
107 | index.addProperty<QByteArray>(Folder::Parent::name); | 114 | FolderIndexConfig::configure(index); |
108 | index.addProperty<QString>(Folder::Name::name); | ||
109 | } | 115 | } |
110 | 116 | ||
111 | void TypeImplementation<Folder>::configure(ReadPropertyMapper<Buffer> &propertyMapper) | 117 | QMap<QByteArray, int> TypeImplementation<Folder>::typeDatabases() |
112 | { | 118 | { |
113 | propertyMapper.addMapping<Folder::Parent, Buffer>(&Buffer::parent); | 119 | return merge(QMap<QByteArray, int>{{QByteArray{Folder::name} + ".main", 0}}, FolderIndexConfig::databases()); |
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 | } | 120 | } |
119 | 121 | ||
120 | void TypeImplementation<Folder>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper) | 122 | void TypeImplementation<Folder>::configure(PropertyMapper &propertyMapper) |
121 | { | 123 | { |
122 | propertyMapper.addMapping<Folder::Parent>(&BufferBuilder::add_parent); | 124 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Parent, parent); |
123 | propertyMapper.addMapping<Folder::Name>(&BufferBuilder::add_name); | 125 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Name, name); |
124 | propertyMapper.addMapping<Folder::Icon>(&BufferBuilder::add_icon); | 126 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Icon, icon); |
125 | propertyMapper.addMapping<Folder::SpecialPurpose>(&BufferBuilder::add_specialpurpose); | 127 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, SpecialPurpose, specialpurpose); |
126 | propertyMapper.addMapping<Folder::Enabled>(&BufferBuilder::add_enabled); | 128 | SINK_REGISTER_SERIALIZER(propertyMapper, Folder, Enabled, enabled); |
127 | } | 129 | } |
128 | 130 | ||
129 | void TypeImplementation<Folder>::configure(IndexPropertyMapper &) | 131 | void TypeImplementation<Folder>::configure(IndexPropertyMapper &) |
@@ -134,29 +136,24 @@ void TypeImplementation<Folder>::configure(IndexPropertyMapper &) | |||
134 | 136 | ||
135 | void TypeImplementation<Contact>::configure(TypeIndex &index) | 137 | void TypeImplementation<Contact>::configure(TypeIndex &index) |
136 | { | 138 | { |
137 | index.addProperty<QByteArray>(Contact::Uid::name); | 139 | ContactIndexConfig::configure(index); |
138 | } | 140 | } |
139 | 141 | ||
140 | void TypeImplementation<Contact>::configure(ReadPropertyMapper<Buffer> &propertyMapper) | 142 | QMap<QByteArray, int> TypeImplementation<Contact>::typeDatabases() |
141 | { | 143 | { |
142 | propertyMapper.addMapping<Contact::Uid, Buffer>(&Buffer::uid); | 144 | return merge(QMap<QByteArray, int>{{QByteArray{Contact::name} + ".main", 0}}, ContactIndexConfig::databases()); |
143 | propertyMapper.addMapping<Contact::Fn, Buffer>(&Buffer::fn); | ||
144 | propertyMapper.addMapping<Contact::Emails, Buffer>(&Buffer::emails); | ||
145 | propertyMapper.addMapping<Contact::Vcard, Buffer>(&Buffer::vcard); | ||
146 | propertyMapper.addMapping<Contact::Addressbook, Buffer>(&Buffer::addressbook); | ||
147 | propertyMapper.addMapping<Contact::Firstname, Buffer>(&Buffer::firstname); | ||
148 | propertyMapper.addMapping<Contact::Lastname, Buffer>(&Buffer::lastname); | ||
149 | } | 145 | } |
150 | 146 | ||
151 | void TypeImplementation<Contact>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper) | 147 | void TypeImplementation<Contact>::configure(PropertyMapper &propertyMapper) |
152 | { | 148 | { |
153 | propertyMapper.addMapping<Contact::Uid>(&BufferBuilder::add_uid); | 149 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Uid, uid); |
154 | propertyMapper.addMapping<Contact::Fn>(&BufferBuilder::add_fn); | 150 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Fn, fn); |
155 | propertyMapper.addMapping<Contact::Emails>(&BufferBuilder::add_emails); | 151 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Emails, emails); |
156 | propertyMapper.addMapping<Contact::Vcard>(&BufferBuilder::add_vcard); | 152 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Vcard, vcard); |
157 | propertyMapper.addMapping<Contact::Addressbook>(&BufferBuilder::add_addressbook); | 153 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Addressbook, addressbook); |
158 | propertyMapper.addMapping<Contact::Firstname>(&BufferBuilder::add_firstname); | 154 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Firstname, firstname); |
159 | propertyMapper.addMapping<Contact::Lastname>(&BufferBuilder::add_lastname); | 155 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Lastname, lastname); |
156 | SINK_REGISTER_SERIALIZER(propertyMapper, Contact, Photo, photo); | ||
160 | } | 157 | } |
161 | 158 | ||
162 | void TypeImplementation<Contact>::configure(IndexPropertyMapper &) | 159 | void TypeImplementation<Contact>::configure(IndexPropertyMapper &) |
@@ -167,20 +164,18 @@ void TypeImplementation<Contact>::configure(IndexPropertyMapper &) | |||
167 | 164 | ||
168 | void TypeImplementation<Addressbook>::configure(TypeIndex &index) | 165 | void TypeImplementation<Addressbook>::configure(TypeIndex &index) |
169 | { | 166 | { |
170 | index.addProperty<QByteArray>(Addressbook::Parent::name); | 167 | AddressbookIndexConfig::configure(index); |
171 | index.addProperty<QString>(Addressbook::Name::name); | ||
172 | } | 168 | } |
173 | 169 | ||
174 | void TypeImplementation<Addressbook>::configure(ReadPropertyMapper<Buffer> &propertyMapper) | 170 | QMap<QByteArray, int> TypeImplementation<Addressbook>::typeDatabases() |
175 | { | 171 | { |
176 | propertyMapper.addMapping<Addressbook::Parent, Buffer>(&Buffer::parent); | 172 | return merge(QMap<QByteArray, int>{{QByteArray{Addressbook::name} + ".main", 0}}, AddressbookIndexConfig::databases()); |
177 | propertyMapper.addMapping<Addressbook::Name, Buffer>(&Buffer::name); | ||
178 | } | 173 | } |
179 | 174 | ||
180 | void TypeImplementation<Addressbook>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper) | 175 | void TypeImplementation<Addressbook>::configure(PropertyMapper &propertyMapper) |
181 | { | 176 | { |
182 | propertyMapper.addMapping<Addressbook::Parent>(&BufferBuilder::add_parent); | 177 | SINK_REGISTER_SERIALIZER(propertyMapper, Addressbook, Parent, parent); |
183 | propertyMapper.addMapping<Addressbook::Name>(&BufferBuilder::add_name); | 178 | SINK_REGISTER_SERIALIZER(propertyMapper, Addressbook, Name, name); |
184 | } | 179 | } |
185 | 180 | ||
186 | void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &) | 181 | void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &) |
@@ -191,26 +186,24 @@ void TypeImplementation<Addressbook>::configure(IndexPropertyMapper &) | |||
191 | 186 | ||
192 | void TypeImplementation<Event>::configure(TypeIndex &index) | 187 | void TypeImplementation<Event>::configure(TypeIndex &index) |
193 | { | 188 | { |
194 | index.addProperty<QByteArray>(Event::Uid::name); | 189 | EventIndexConfig::configure(index); |
195 | } | 190 | } |
196 | 191 | ||
197 | void TypeImplementation<Event>::configure(ReadPropertyMapper<Buffer> &propertyMapper) | 192 | QMap<QByteArray, int> TypeImplementation<Event>::typeDatabases() |
198 | { | 193 | { |
199 | propertyMapper.addMapping<Event::Summary, Buffer>(&Buffer::summary); | 194 | return merge(QMap<QByteArray, int>{{QByteArray{Event::name} + ".main", 0}}, EventIndexConfig::databases()); |
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 | } | 195 | } |
204 | 196 | ||
205 | void TypeImplementation<Event>::configure(WritePropertyMapper<BufferBuilder> &propertyMapper) | 197 | void TypeImplementation<Event>::configure(PropertyMapper &propertyMapper) |
206 | { | 198 | { |
207 | propertyMapper.addMapping<Event::Summary>(&BufferBuilder::add_summary); | 199 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Summary, summary); |
208 | propertyMapper.addMapping<Event::Description>(&BufferBuilder::add_description); | 200 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Description, description); |
209 | propertyMapper.addMapping<Event::Uid>(&BufferBuilder::add_uid); | 201 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Uid, uid); |
210 | propertyMapper.addMapping<Event::Attachment>(&BufferBuilder::add_attachment); | 202 | SINK_REGISTER_SERIALIZER(propertyMapper, Event, Attachment, attachment); |
211 | } | 203 | } |
212 | 204 | ||
213 | void TypeImplementation<Event>::configure(IndexPropertyMapper &) | 205 | void TypeImplementation<Event>::configure(IndexPropertyMapper &) |
214 | { | 206 | { |
215 | 207 | ||
216 | } | 208 | } |
209 | |||
diff --git a/common/domain/typeimplementations.h b/common/domain/typeimplementations.h index 37d6ca9..d36dfc1 100644 --- a/common/domain/typeimplementations.h +++ b/common/domain/typeimplementations.h | |||
@@ -26,10 +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 | template<typename T> | 29 | class PropertyMapper; |
30 | class ReadPropertyMapper; | ||
31 | template<typename T> | ||
32 | class WritePropertyMapper; | ||
33 | class IndexPropertyMapper; | 30 | class IndexPropertyMapper; |
34 | 31 | ||
35 | class TypeIndex; | 32 | class TypeIndex; |
@@ -48,9 +45,9 @@ public: | |||
48 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; | 45 | typedef Sink::ApplicationDomain::Buffer::Mail Buffer; |
49 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; | 46 | typedef Sink::ApplicationDomain::Buffer::MailBuilder BufferBuilder; |
50 | static void configure(TypeIndex &index); | 47 | static void configure(TypeIndex &index); |
51 | static void configure(ReadPropertyMapper<Buffer> &propertyMapper); | 48 | static void configure(PropertyMapper &propertyMapper); |
52 | static void configure(WritePropertyMapper<BufferBuilder> &propertyMapper); | ||
53 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 49 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
50 | static QMap<QByteArray, int> typeDatabases(); | ||
54 | }; | 51 | }; |
55 | 52 | ||
56 | template<> | 53 | template<> |
@@ -59,9 +56,9 @@ public: | |||
59 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; | 56 | typedef Sink::ApplicationDomain::Buffer::Folder Buffer; |
60 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; | 57 | typedef Sink::ApplicationDomain::Buffer::FolderBuilder BufferBuilder; |
61 | static void configure(TypeIndex &); | 58 | static void configure(TypeIndex &); |
62 | static void configure(ReadPropertyMapper<Buffer> &); | 59 | static void configure(PropertyMapper &); |
63 | static void configure(WritePropertyMapper<BufferBuilder> &); | ||
64 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 60 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
61 | static QMap<QByteArray, int> typeDatabases(); | ||
65 | }; | 62 | }; |
66 | 63 | ||
67 | template<> | 64 | template<> |
@@ -70,9 +67,9 @@ public: | |||
70 | typedef Sink::ApplicationDomain::Buffer::Contact Buffer; | 67 | typedef Sink::ApplicationDomain::Buffer::Contact Buffer; |
71 | typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; | 68 | typedef Sink::ApplicationDomain::Buffer::ContactBuilder BufferBuilder; |
72 | static void configure(TypeIndex &); | 69 | static void configure(TypeIndex &); |
73 | static void configure(ReadPropertyMapper<Buffer> &); | 70 | static void configure(PropertyMapper &); |
74 | static void configure(WritePropertyMapper<BufferBuilder> &); | ||
75 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 71 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
72 | static QMap<QByteArray, int> typeDatabases(); | ||
76 | }; | 73 | }; |
77 | 74 | ||
78 | template<> | 75 | template<> |
@@ -81,9 +78,9 @@ public: | |||
81 | typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; | 78 | typedef Sink::ApplicationDomain::Buffer::Addressbook Buffer; |
82 | typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; | 79 | typedef Sink::ApplicationDomain::Buffer::AddressbookBuilder BufferBuilder; |
83 | static void configure(TypeIndex &); | 80 | static void configure(TypeIndex &); |
84 | static void configure(ReadPropertyMapper<Buffer> &); | 81 | static void configure(PropertyMapper &); |
85 | static void configure(WritePropertyMapper<BufferBuilder> &); | ||
86 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 82 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
83 | static QMap<QByteArray, int> typeDatabases(); | ||
87 | }; | 84 | }; |
88 | 85 | ||
89 | template<> | 86 | template<> |
@@ -92,9 +89,9 @@ public: | |||
92 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; | 89 | typedef Sink::ApplicationDomain::Buffer::Event Buffer; |
93 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; | 90 | typedef Sink::ApplicationDomain::Buffer::EventBuilder BufferBuilder; |
94 | static void configure(TypeIndex &); | 91 | static void configure(TypeIndex &); |
95 | static void configure(ReadPropertyMapper<Buffer> &); | 92 | static void configure(PropertyMapper &); |
96 | static void configure(WritePropertyMapper<BufferBuilder> &); | ||
97 | static void configure(IndexPropertyMapper &indexPropertyMapper); | 93 | static void configure(IndexPropertyMapper &indexPropertyMapper); |
94 | static QMap<QByteArray, int> typeDatabases(); | ||
98 | }; | 95 | }; |
99 | 96 | ||
100 | } | 97 | } |
diff --git a/common/domain/typeimplementations_p.h b/common/domain/typeimplementations_p.h new file mode 100644 index 0000000..6f77a2d --- /dev/null +++ b/common/domain/typeimplementations_p.h | |||
@@ -0,0 +1,154 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2015 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This program is free software; you can redistribute it and/or modify | ||
5 | * it under the terms of the GNU General Public License as published by | ||
6 | * the Free Software Foundation; either version 2 of the License, or | ||
7 | * (at your option) any later version. | ||
8 | * | ||
9 | * This program is distributed in the hope that it will be useful, | ||
10 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
11 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
12 | * GNU General Public License for more details. | ||
13 | * | ||
14 | * You should have received a copy of the GNU General Public License | ||
15 | * along with this program; if not, write to the | ||
16 | * Free Software Foundation, Inc., | ||
17 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
18 | */ | ||
19 | |||
20 | #include "typeindex.h" | ||
21 | #include <QMap> | ||
22 | |||
23 | template <typename T, typename First> | ||
24 | void mergeImpl(T &map, First f) | ||
25 | { | ||
26 | for (auto it = f.constBegin(); it != f.constEnd(); it++) { | ||
27 | map.insert(it.key(), it.value()); | ||
28 | } | ||
29 | } | ||
30 | |||
31 | template <typename T, typename First, typename ... Tail> | ||
32 | void mergeImpl(T &map, First f, Tail ...maps) | ||
33 | { | ||
34 | for (auto it = f.constBegin(); it != f.constEnd(); it++) { | ||
35 | map.insert(it.key(), it.value()); | ||
36 | } | ||
37 | mergeImpl<T, Tail...>(map, maps...); | ||
38 | } | ||
39 | |||
40 | template <typename First, typename ... Tail> | ||
41 | First merge(First f, Tail ...maps) | ||
42 | { | ||
43 | First map; | ||
44 | mergeImpl(map, f, maps...); | ||
45 | return map; | ||
46 | } | ||
47 | |||
48 | template <typename Property> | ||
49 | class ValueIndex | ||
50 | { | ||
51 | public: | ||
52 | static void configure(TypeIndex &index) | ||
53 | { | ||
54 | index.addProperty<Property>(); | ||
55 | } | ||
56 | |||
57 | template <typename EntityType> | ||
58 | static QMap<QByteArray, int> databases() | ||
59 | { | ||
60 | return {{QByteArray{EntityType::name} +".index." + Property::name, 1}}; | ||
61 | } | ||
62 | }; | ||
63 | |||
64 | |||
65 | template <typename Property, typename SortProperty> | ||
66 | class SortedIndex | ||
67 | { | ||
68 | public: | ||
69 | static void configure(TypeIndex &index) | ||
70 | { | ||
71 | index.addPropertyWithSorting<Property, SortProperty>(); | ||
72 | } | ||
73 | |||
74 | template <typename EntityType> | ||
75 | static QMap<QByteArray, int> databases() | ||
76 | { | ||
77 | return {{QByteArray{EntityType::name} +".index." + Property::name + ".sort." + SortProperty::name, 1}}; | ||
78 | } | ||
79 | }; | ||
80 | |||
81 | template <typename Property, typename SecondaryProperty> | ||
82 | class SecondaryIndex | ||
83 | { | ||
84 | public: | ||
85 | static void configure(TypeIndex &index) | ||
86 | { | ||
87 | index.addSecondaryProperty<Property, SecondaryProperty>(); | ||
88 | } | ||
89 | |||
90 | template <typename EntityType> | ||
91 | static QMap<QByteArray, int> databases() | ||
92 | { | ||
93 | return {{QByteArray{EntityType::name} +".index." + Property::name + SecondaryProperty::name, 1}}; | ||
94 | } | ||
95 | }; | ||
96 | |||
97 | template <typename Property, typename SecondaryProperty, typename Indexer> | ||
98 | class CustomSecondaryIndex | ||
99 | { | ||
100 | public: | ||
101 | static void configure(TypeIndex &index) | ||
102 | { | ||
103 | index.addSecondaryPropertyIndexer<Property, SecondaryProperty, Indexer>(); | ||
104 | } | ||
105 | |||
106 | template <typename EntityType> | ||
107 | static QMap<QByteArray, int> databases() | ||
108 | { | ||
109 | return Indexer::databases(); | ||
110 | } | ||
111 | }; | ||
112 | |||
113 | template <typename EntityType, typename ... Indexes> | ||
114 | class IndexConfig | ||
115 | { | ||
116 | template <typename T> | ||
117 | static void applyIndex(TypeIndex &index) | ||
118 | { | ||
119 | T::configure(index); | ||
120 | } | ||
121 | |||
122 | ///Apply recursively for parameter pack | ||
123 | template <typename First, typename Second, typename ... Tail> | ||
124 | static void applyIndex(TypeIndex &index) | ||
125 | { | ||
126 | applyIndex<First>(index); | ||
127 | applyIndex<Second, Tail...>(index); | ||
128 | } | ||
129 | |||
130 | template <typename T> | ||
131 | static QMap<QByteArray, int> getDbs() | ||
132 | { | ||
133 | return T::template databases<EntityType>(); | ||
134 | } | ||
135 | |||
136 | template <typename First, typename Second, typename ... Tail> | ||
137 | static QMap<QByteArray, int> getDbs() | ||
138 | { | ||
139 | return merge(getDbs<First>(), getDbs<Second, Tail...>()); | ||
140 | } | ||
141 | |||
142 | public: | ||
143 | static void configure(TypeIndex &index) | ||
144 | { | ||
145 | applyIndex<Indexes...>(index); | ||
146 | } | ||
147 | |||
148 | static QMap<QByteArray, int> databases() | ||
149 | { | ||
150 | return getDbs<Indexes...>(); | ||
151 | } | ||
152 | |||
153 | }; | ||
154 | |||