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 /common/propertymapper.h | |
parent | 00bb8525c973fc583137c7bc307d3cff76ad24d5 (diff) | |
download | sink-042d8fb10552d0bcc92647338d9d763357f35880.tar.gz sink-042d8fb10552d0bcc92647338d9d763357f35880.zip |
Support the attachment property
Diffstat (limited to 'common/propertymapper.h')
-rw-r--r-- | common/propertymapper.h | 22 |
1 files changed, 22 insertions, 0 deletions
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 | }; |