diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-03 20:09:18 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-05-03 20:09:18 +0200 |
commit | c14f07a865940de86b229b4eba0d3bbb9b13967c (patch) | |
tree | cbb9a5a522d5462fc342b208f05cd109a2c77ec4 /common/propertymapper.h | |
parent | 9d079a832ec9c70fccb3446843bd8d7579e3aafd (diff) | |
download | sink-c14f07a865940de86b229b4eba0d3bbb9b13967c.tar.gz sink-c14f07a865940de86b229b4eba0d3bbb9b13967c.zip |
Support for QByteArrayList
Diffstat (limited to 'common/propertymapper.h')
-rw-r--r-- | common/propertymapper.h | 18 |
1 files changed, 17 insertions, 1 deletions
diff --git a/common/propertymapper.h b/common/propertymapper.h index cf8ce7b..edbc7f1 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -40,7 +40,8 @@ template <typename T> | |||
40 | QVariant SINK_EXPORT propertyToVariant(uint8_t); | 40 | QVariant SINK_EXPORT propertyToVariant(uint8_t); |
41 | template <typename T> | 41 | template <typename T> |
42 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<uint8_t> *); | 42 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<uint8_t> *); |
43 | 43 | template <typename T> | |
44 | QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *); | ||
44 | 45 | ||
45 | /** | 46 | /** |
46 | * The property mapper is a non-typesafe virtual dispatch. | 47 | * The property mapper is a non-typesafe virtual dispatch. |
@@ -100,6 +101,12 @@ public: | |||
100 | addMapping(name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<T>((buffer->*f)()); }); | 101 | addMapping(name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<T>((buffer->*f)()); }); |
101 | } | 102 | } |
102 | 103 | ||
104 | template <typename T, typename Buffer> | ||
105 | void addMapping(const QByteArray &name, const flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>> *(Buffer::*f)() const) | ||
106 | { | ||
107 | addMapping(name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<T>((buffer->*f)()); }); | ||
108 | } | ||
109 | |||
103 | private: | 110 | private: |
104 | QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors; | 111 | QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors; |
105 | }; | 112 | }; |
@@ -160,6 +167,15 @@ public: | |||
160 | }); | 167 | }); |
161 | } | 168 | } |
162 | 169 | ||
170 | template <typename T> | ||
171 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::Vector<flatbuffers::Offset<flatbuffers::String>>>)) | ||
172 | { | ||
173 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | ||
174 | auto offset = variantToProperty<T>(value, fbb); | ||
175 | return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; | ||
176 | }); | ||
177 | } | ||
178 | |||
163 | private: | 179 | private: |
164 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; | 180 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; |
165 | }; | 181 | }; |