diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-04 14:47:28 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2015-12-04 14:47:28 +0100 |
commit | 553000673acf7297cfa4de620290ba73f3c438ac (patch) | |
tree | f5dd2cd502a7f7e48b60b4d4a4968016bc8a6fc0 /common/propertymapper.h | |
parent | 52f14f40f233146f76a3c1eb143deb12c6a5b2d6 (diff) | |
download | sink-553000673acf7297cfa4de620290ba73f3c438ac.tar.gz sink-553000673acf7297cfa4de620290ba73f3c438ac.zip |
Reduced boilerplate for buffer mapping
Diffstat (limited to 'common/propertymapper.h')
-rw-r--r-- | common/propertymapper.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/common/propertymapper.h b/common/propertymapper.h index 87c7485..98ad397 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -98,6 +98,17 @@ public: | |||
98 | void addMapping(const QByteArray &property, const std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> &mapping) { | 98 | void addMapping(const QByteArray &property, const std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> &mapping) { |
99 | mWriteAccessors.insert(property, mapping); | 99 | mWriteAccessors.insert(property, mapping); |
100 | } | 100 | } |
101 | |||
102 | template <typename T> | ||
103 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::String>)) | ||
104 | { | ||
105 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | ||
106 | auto offset = variantToProperty<T>(value, fbb); | ||
107 | return [offset, f](BufferBuilder &builder) { | ||
108 | (builder.*f)(offset); | ||
109 | }; | ||
110 | }); | ||
111 | } | ||
101 | private: | 112 | private: |
102 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> > mWriteAccessors; | 113 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> > mWriteAccessors; |
103 | }; | 114 | }; |