diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-21 14:43:23 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-21 14:43:23 +0100 |
commit | 042d8fb10552d0bcc92647338d9d763357f35880 (patch) | |
tree | d03983d21128f753953e319f96a26a5e8968d7dd | |
parent | 00bb8525c973fc583137c7bc307d3cff76ad24d5 (diff) | |
download | sink-042d8fb10552d0bcc92647338d9d763357f35880.tar.gz sink-042d8fb10552d0bcc92647338d9d763357f35880.zip |
Support the attachment property
-rw-r--r-- | common/domain/event.cpp | 2 | ||||
-rw-r--r-- | common/propertymapper.cpp | 10 | ||||
-rw-r--r-- | common/propertymapper.h | 22 |
3 files changed, 34 insertions, 0 deletions
diff --git a/common/domain/event.cpp b/common/domain/event.cpp index d989efe..a348e65 100644 --- a/common/domain/event.cpp +++ b/common/domain/event.cpp | |||
@@ -65,6 +65,7 @@ QSharedPointer<ReadPropertyMapper<TypeImplementation<Event>::Buffer> > TypeImple | |||
65 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); | 65 | auto propertyMapper = QSharedPointer<ReadPropertyMapper<Buffer> >::create(); |
66 | propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); | 66 | propertyMapper->addMapping<QString, Buffer>("summary", &Buffer::summary); |
67 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); | 67 | propertyMapper->addMapping<QString, Buffer>("uid", &Buffer::uid); |
68 | propertyMapper->addMapping<QByteArray, Buffer>("attachment", &Buffer::attachment); | ||
68 | return propertyMapper; | 69 | return propertyMapper; |
69 | } | 70 | } |
70 | 71 | ||
@@ -73,5 +74,6 @@ QSharedPointer<WritePropertyMapper<TypeImplementation<Event>::BufferBuilder> > T | |||
73 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); | 74 | auto propertyMapper = QSharedPointer<WritePropertyMapper<BufferBuilder> >::create(); |
74 | propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary); | 75 | propertyMapper->addMapping<QString>("summary", &BufferBuilder::add_summary); |
75 | propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid); | 76 | propertyMapper->addMapping<QString>("uid", &BufferBuilder::add_uid); |
77 | propertyMapper->addMapping<QByteArray>("attachment", &BufferBuilder::add_attachment); | ||
76 | return propertyMapper; | 78 | return propertyMapper; |
77 | } | 79 | } |
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index 17a73cb..5348b11 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp | |||
@@ -68,6 +68,16 @@ QVariant propertyToVariant<QByteArray>(const flatbuffers::String *property) | |||
68 | } | 68 | } |
69 | 69 | ||
70 | template <> | 70 | template <> |
71 | QVariant propertyToVariant<QByteArray>(const flatbuffers::Vector<uint8_t> *property) | ||
72 | { | ||
73 | if (property) { | ||
74 | //We have to copy the memory, otherwise it would become eventually invalid | ||
75 | return QByteArray(reinterpret_cast<const char *>(property->Data()), property->Length()); | ||
76 | } | ||
77 | return QVariant(); | ||
78 | } | ||
79 | |||
80 | template <> | ||
71 | QVariant propertyToVariant<bool>(uint8_t property) | 81 | QVariant propertyToVariant<bool>(uint8_t property) |
72 | { | 82 | { |
73 | return static_cast<bool>(property); | 83 | return static_cast<bool>(property); |
diff --git a/common/propertymapper.h b/common/propertymapper.h index fb5accc..efde72c 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -37,6 +37,8 @@ template <typename T> | |||
37 | QVariant propertyToVariant(const flatbuffers::String *); | 37 | QVariant propertyToVariant(const flatbuffers::String *); |
38 | template <typename T> | 38 | template <typename T> |
39 | QVariant propertyToVariant(uint8_t); | 39 | QVariant propertyToVariant(uint8_t); |
40 | template <typename T> | ||
41 | QVariant propertyToVariant(const flatbuffers::Vector<uint8_t> *); | ||
40 | 42 | ||
41 | 43 | ||
42 | /** | 44 | /** |
@@ -87,6 +89,15 @@ public: | |||
87 | return propertyToVariant<T>((buffer->*f)()); | 89 | return propertyToVariant<T>((buffer->*f)()); |
88 | }); | 90 | }); |
89 | } | 91 | } |
92 | |||
93 | template <typename T, typename Buffer> | ||
94 | void addMapping(const QByteArray &name, const flatbuffers::Vector<uint8_t> * (Buffer::*f)() const) | ||
95 | { | ||
96 | addMapping(name, [f](Buffer const *buffer) -> QVariant { | ||
97 | return propertyToVariant<T>((buffer->*f)()); | ||
98 | }); | ||
99 | } | ||
100 | |||
90 | private: | 101 | private: |
91 | QHash<QByteArray, std::function<QVariant(BufferType const *)> > mReadAccessors; | 102 | QHash<QByteArray, std::function<QVariant(BufferType const *)> > mReadAccessors; |
92 | }; | 103 | }; |
@@ -137,6 +148,17 @@ public: | |||
137 | }; | 148 | }; |
138 | }); | 149 | }); |
139 | } | 150 | } |
151 | |||
152 | template <typename T> | ||
153 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::Vector<uint8_t> >)) | ||
154 | { | ||
155 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | ||
156 | auto offset = variantToProperty<T>(value, fbb); | ||
157 | return [offset, f](BufferBuilder &builder) { | ||
158 | (builder.*f)(offset); | ||
159 | }; | ||
160 | }); | ||
161 | } | ||
140 | private: | 162 | private: |
141 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> > mWriteAccessors; | 163 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> > mWriteAccessors; |
142 | }; | 164 | }; |