diff options
-rw-r--r-- | common/domainadaptor.cpp | 25 | ||||
-rw-r--r-- | common/domainadaptor.h | 9 | ||||
-rw-r--r-- | dummyresource/domainadaptor.cpp | 7 |
3 files changed, 23 insertions, 18 deletions
diff --git a/common/domainadaptor.cpp b/common/domainadaptor.cpp index aa8c3d9..8a4b5ed 100644 --- a/common/domainadaptor.cpp +++ b/common/domainadaptor.cpp | |||
@@ -20,7 +20,7 @@ | |||
20 | #include "domainadaptor.h" | 20 | #include "domainadaptor.h" |
21 | 21 | ||
22 | template <> | 22 | template <> |
23 | flatbuffers::uoffset_t extractProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | 23 | flatbuffers::uoffset_t variantToProperty<QString>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) |
24 | { | 24 | { |
25 | if (property.isValid()) { | 25 | if (property.isValid()) { |
26 | return fbb.CreateString(property.toString().toStdString()).o; | 26 | return fbb.CreateString(property.toString().toStdString()).o; |
@@ -29,20 +29,23 @@ flatbuffers::uoffset_t extractProperty<QString>(const QVariant &property, flatbu | |||
29 | } | 29 | } |
30 | 30 | ||
31 | template <> | 31 | template <> |
32 | QVariant propertyToVariant<QString>(const flatbuffers::String *property) | ||
33 | { | ||
34 | if (property) { | ||
35 | return QString::fromStdString(property->c_str()); | ||
36 | } | ||
37 | return QVariant(); | ||
38 | } | ||
39 | |||
40 | template <> | ||
32 | QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > initializeReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event>() | 41 | QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> > initializeReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event>() |
33 | { | 42 | { |
34 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> >::create(); | 43 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Akonadi2::ApplicationDomain::Buffer::Event> >::create(); |
35 | propertyMapper->addMapping("summary", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant { | 44 | propertyMapper->addMapping("summary", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant { |
36 | if (buffer->summary()) { | 45 | return propertyToVariant<QString>(buffer->summary()); |
37 | return QString::fromStdString(buffer->summary()->c_str()); | ||
38 | } | ||
39 | return QVariant(); | ||
40 | }); | 46 | }); |
41 | propertyMapper->addMapping("uid", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant { | 47 | propertyMapper->addMapping("uid", [](Akonadi2::ApplicationDomain::Buffer::Event const *buffer) -> QVariant { |
42 | if (buffer->uid()) { | 48 | return propertyToVariant<QString>(buffer->uid()); |
43 | return QString::fromStdString(buffer->uid()->c_str()); | ||
44 | } | ||
45 | return QVariant(); | ||
46 | }); | 49 | }); |
47 | return propertyMapper; | 50 | return propertyMapper; |
48 | } | 51 | } |
@@ -52,11 +55,11 @@ QSharedPointer<WritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBui | |||
52 | { | 55 | { |
53 | auto propertyMapper = QSharedPointer<WritePropertyMapper<Akonadi2::ApplicationDomain::Buffer::EventBuilder> >::create(); | 56 | 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 &)> { | 57 | propertyMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Akonadi2::ApplicationDomain::Buffer::EventBuilder &)> { |
55 | auto offset = extractProperty<QString>(value, fbb); | 58 | auto offset = variantToProperty<QString>(value, fbb); |
56 | return [offset](Akonadi2::ApplicationDomain::Buffer::EventBuilder &builder) { builder.add_summary(offset); }; | 59 | return [offset](Akonadi2::ApplicationDomain::Buffer::EventBuilder &builder) { builder.add_summary(offset); }; |
57 | }); | 60 | }); |
58 | propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Akonadi2::ApplicationDomain::Buffer::EventBuilder &)> { | 61 | propertyMapper->addMapping("uid", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(Akonadi2::ApplicationDomain::Buffer::EventBuilder &)> { |
59 | auto offset = extractProperty<QString>(value, fbb); | 62 | auto offset = variantToProperty<QString>(value, fbb); |
60 | return [offset](Akonadi2::ApplicationDomain::Buffer::EventBuilder &builder) { builder.add_uid(offset); }; | 63 | return [offset](Akonadi2::ApplicationDomain::Buffer::EventBuilder &builder) { builder.add_uid(offset); }; |
61 | }); | 64 | }); |
62 | return propertyMapper; | 65 | return propertyMapper; |
diff --git a/common/domainadaptor.h b/common/domainadaptor.h index e356692..d07a2bd 100644 --- a/common/domainadaptor.h +++ b/common/domainadaptor.h | |||
@@ -79,10 +79,15 @@ private: | |||
79 | 79 | ||
80 | /** | 80 | /** |
81 | * Defines how to convert qt primitives to flatbuffer ones | 81 | * Defines how to convert qt primitives to flatbuffer ones |
82 | * TODO: rename to createProperty or so? | ||
83 | */ | 82 | */ |
84 | template <class T> | 83 | template <class T> |
85 | flatbuffers::uoffset_t extractProperty(const QVariant &, flatbuffers::FlatBufferBuilder &fbb); | 84 | flatbuffers::uoffset_t variantToProperty(const QVariant &, flatbuffers::FlatBufferBuilder &fbb); |
85 | |||
86 | /** | ||
87 | * Defines how to convert flatbuffer primitives to qt ones | ||
88 | */ | ||
89 | template <typename T> | ||
90 | QVariant propertyToVariant(const flatbuffers::String *); | ||
86 | 91 | ||
87 | /** | 92 | /** |
88 | * Create a buffer from a domain object using the provided mappings | 93 | * Create a buffer from a domain object using the provided mappings |
diff --git a/dummyresource/domainadaptor.cpp b/dummyresource/domainadaptor.cpp index fa00bbc..8649bc3 100644 --- a/dummyresource/domainadaptor.cpp +++ b/dummyresource/domainadaptor.cpp | |||
@@ -23,14 +23,11 @@ DummyEventAdaptorFactory::DummyEventAdaptorFactory() | |||
23 | { | 23 | { |
24 | //TODO turn this into initializeReadPropertyMapper as well? | 24 | //TODO turn this into initializeReadPropertyMapper as well? |
25 | mResourceMapper->addMapping("summary", [](DummyEvent const *buffer) -> QVariant { | 25 | mResourceMapper->addMapping("summary", [](DummyEvent const *buffer) -> QVariant { |
26 | if (buffer->summary()) { | 26 | return propertyToVariant<QString>(buffer->summary()); |
27 | return QString::fromStdString(buffer->summary()->c_str()); | ||
28 | } | ||
29 | return QVariant(); | ||
30 | }); | 27 | }); |
31 | 28 | ||
32 | mResourceWriteMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(DummyEventBuilder &)> { | 29 | mResourceWriteMapper->addMapping("summary", [](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(DummyEventBuilder &)> { |
33 | auto offset = extractProperty<QString>(value, fbb); | 30 | auto offset = variantToProperty<QString>(value, fbb); |
34 | return [offset](DummyEventBuilder &builder) { builder.add_summary(offset); }; | 31 | return [offset](DummyEventBuilder &builder) { builder.add_summary(offset); }; |
35 | }); | 32 | }); |
36 | } | 33 | } |