diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-31 18:45:59 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-10-31 18:45:59 +0100 |
commit | 1d245e28c9b1b18a45097a72bc4ff166c59c37ba (patch) | |
tree | 46853e4df7d5b60435088b8503966567639b51b6 /common/propertymapper.h | |
parent | eed2f992300a82debdeda3ece5acf5c05954bbf7 (diff) | |
download | sink-1d245e28c9b1b18a45097a72bc4ff166c59c37ba.tar.gz sink-1d245e28c9b1b18a45097a72bc4ff166c59c37ba.zip |
Mail::Contact mapping
Diffstat (limited to 'common/propertymapper.h')
-rw-r--r-- | common/propertymapper.h | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/common/propertymapper.h b/common/propertymapper.h index 8227940..a63b7e7 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -25,6 +25,14 @@ | |||
25 | #include <functional> | 25 | #include <functional> |
26 | #include <flatbuffers/flatbuffers.h> | 26 | #include <flatbuffers/flatbuffers.h> |
27 | 27 | ||
28 | namespace Sink { | ||
29 | namespace ApplicationDomain { | ||
30 | namespace Buffer { | ||
31 | struct MailContact; | ||
32 | } | ||
33 | } | ||
34 | } | ||
35 | |||
28 | /** | 36 | /** |
29 | * Defines how to convert qt primitives to flatbuffer ones | 37 | * Defines how to convert qt primitives to flatbuffer ones |
30 | */ | 38 | */ |
@@ -42,6 +50,8 @@ template <typename T> | |||
42 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<uint8_t> *); | 50 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<uint8_t> *); |
43 | template <typename T> | 51 | template <typename T> |
44 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *); | 52 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *); |
53 | template <typename T> | ||
54 | QVariant SINK_EXPORT propertyToVariant(const Sink::ApplicationDomain::Buffer::MailContact *); | ||
45 | 55 | ||
46 | /** | 56 | /** |
47 | * The property mapper is a non-typesafe virtual dispatch. | 57 | * The property mapper is a non-typesafe virtual dispatch. |
@@ -107,6 +117,12 @@ public: | |||
107 | addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); }); | 117 | addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); }); |
108 | } | 118 | } |
109 | 119 | ||
120 | template <typename T, typename Buffer> | ||
121 | void addMapping(const Sink::ApplicationDomain::Buffer::MailContact *(Buffer::*f)() const) | ||
122 | { | ||
123 | addMapping(T::name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<typename T::Type>((buffer->*f)()); }); | ||
124 | } | ||
125 | |||
110 | private: | 126 | private: |
111 | QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors; | 127 | QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors; |
112 | }; | 128 | }; |
@@ -176,6 +192,15 @@ public: | |||
176 | }); | 192 | }); |
177 | } | 193 | } |
178 | 194 | ||
195 | template <typename T> | ||
196 | void addMapping(void (BufferBuilder::*f)(flatbuffers::Offset<Sink::ApplicationDomain::Buffer::MailContact>)) | ||
197 | { | ||
198 | addMapping(T::name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | ||
199 | auto offset = variantToProperty<typename T::Type>(value, fbb); | ||
200 | return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; | ||
201 | }); | ||
202 | } | ||
203 | |||
179 | private: | 204 | private: |
180 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; | 205 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; |
181 | }; | 206 | }; |