summaryrefslogtreecommitdiffstats
path: root/common/domainadaptor.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'common/domainadaptor.cpp')
-rw-r--r--common/domainadaptor.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/common/domainadaptor.cpp b/common/domainadaptor.cpp
new file mode 100644
index 0000000..aa8c3d9
--- /dev/null
+++ b/common/domainadaptor.cpp
@@ -0,0 +1,63 @@
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 "domainadaptor.h"
21
22template <>
23flatbuffers::uoffset_t extractProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb)
24{
25 if (property.isValid()) {
26 return fbb.CreateString(property.toString().toStdString()).o;
27 }
28 return 0;
29}
30
31template <>
32QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > initializeReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event>()
33{
34 auto propertyMapper = QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> >::create();
35 propertyMapper->addMapping("summary", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant {
36 if (buffer->summary()) {
37 return QString::fromStdString(buffer->summary()->c_str());
38 }
39 return QVariant();
40 });
41 propertyMapper->addMapping("uid", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant {
42 if (buffer->uid()) {
43 return QString::fromStdString(buffer->uid()->c_str());
44 }
45 return QVariant();
46 });
47 return propertyMapper;
48}
49
50template <>
51QSharedPointer<WritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder> > initializeWritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder>()
52{
53 auto propertyMapper = QSharedPointer<WritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder> >::create();
54 propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Akonadi2::ApplicationDomain::Buffer::EventBuilder &)> {
55 auto offset = extractProperty<QString>(value, fbb);
56 return [offset](Akonadi2::ApplicationDomain::Buffer::EventBuilder &builder) { builder.add_summary(offset); };
57 });
58 propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Akonadi2::ApplicationDomain::Buffer::EventBuilder &)> {
59 auto offset = extractProperty<QString>(value, fbb);
60 return [offset](Akonadi2::ApplicationDomain::Buffer::EventBuilder &builder) { builder.add_uid(offset); };
61 });
62 return propertyMapper;
63}