diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-03 09:01:05 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-03-03 09:01:05 +0100 |
commit | 4d9746c828558c9f872e0aed52442863affb25d5 (patch) | |
tree | 507d7c2ba67f47d3cbbcf01a722236ff1b48426b /common/propertymapper.h | |
parent | 9cea920b7dd51867a0be0fed2f461b6be73c103e (diff) | |
download | sink-4d9746c828558c9f872e0aed52442863affb25d5.tar.gz sink-4d9746c828558c9f872e0aed52442863affb25d5.zip |
Fromatted the whole codebase with clang-format.
clang-format -i */**{.cpp,.h}
Diffstat (limited to 'common/propertymapper.h')
-rw-r--r-- | common/propertymapper.h | 71 |
1 files changed, 33 insertions, 38 deletions
diff --git a/common/propertymapper.h b/common/propertymapper.h index 57202ab..cf8ce7b 100644 --- a/common/propertymapper.h +++ b/common/propertymapper.h | |||
@@ -49,7 +49,7 @@ QVariant SINK_EXPORT propertyToVariant(const flatbuffers::Vector<uint8_t> *); | |||
49 | * a virtual method per property, the property mapper can be filled with accessors | 49 | * a virtual method per property, the property mapper can be filled with accessors |
50 | * that extract the properties from resource types. | 50 | * that extract the properties from resource types. |
51 | */ | 51 | */ |
52 | template<typename BufferType> | 52 | template <typename BufferType> |
53 | class ReadPropertyMapper | 53 | class ReadPropertyMapper |
54 | { | 54 | { |
55 | public: | 55 | public: |
@@ -63,63 +63,66 @@ public: | |||
63 | } | 63 | } |
64 | return QVariant(); | 64 | return QVariant(); |
65 | } | 65 | } |
66 | bool hasMapping(const QByteArray &key) const { return mReadAccessors.contains(key); } | 66 | bool hasMapping(const QByteArray &key) const |
67 | QList<QByteArray> availableProperties() const { return mReadAccessors.keys(); } | 67 | { |
68 | void addMapping(const QByteArray &property, const std::function<QVariant(BufferType const *)> &mapping) { | 68 | return mReadAccessors.contains(key); |
69 | } | ||
70 | QList<QByteArray> availableProperties() const | ||
71 | { | ||
72 | return mReadAccessors.keys(); | ||
73 | } | ||
74 | void addMapping(const QByteArray &property, const std::function<QVariant(BufferType const *)> &mapping) | ||
75 | { | ||
69 | mReadAccessors.insert(property, mapping); | 76 | mReadAccessors.insert(property, mapping); |
70 | } | 77 | } |
71 | 78 | ||
72 | template <typename T, typename Buffer> | 79 | template <typename T, typename Buffer> |
73 | void addMapping(const QByteArray &name, const flatbuffers::String *(Buffer::*f)() const) | 80 | void addMapping(const QByteArray &name, const flatbuffers::String *(Buffer::*f)() const) |
74 | { | 81 | { |
75 | addMapping(name, [f](Buffer const *buffer) -> QVariant { | 82 | addMapping(name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<T>((buffer->*f)()); }); |
76 | return propertyToVariant<T>((buffer->*f)()); | ||
77 | }); | ||
78 | } | 83 | } |
79 | 84 | ||
80 | template <typename T, typename Buffer> | 85 | template <typename T, typename Buffer> |
81 | void addMapping(const QByteArray &name, uint8_t (Buffer::*f)() const) | 86 | void addMapping(const QByteArray &name, uint8_t (Buffer::*f)() const) |
82 | { | 87 | { |
83 | addMapping(name, [f](Buffer const *buffer) -> QVariant { | 88 | addMapping(name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<T>((buffer->*f)()); }); |
84 | return propertyToVariant<T>((buffer->*f)()); | ||
85 | }); | ||
86 | } | 89 | } |
87 | 90 | ||
88 | template <typename T, typename Buffer> | 91 | template <typename T, typename Buffer> |
89 | void addMapping(const QByteArray &name, bool (Buffer::*f)() const) | 92 | void addMapping(const QByteArray &name, bool (Buffer::*f)() const) |
90 | { | 93 | { |
91 | addMapping(name, [f](Buffer const *buffer) -> QVariant { | 94 | addMapping(name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<T>((buffer->*f)()); }); |
92 | return propertyToVariant<T>((buffer->*f)()); | ||
93 | }); | ||
94 | } | 95 | } |
95 | 96 | ||
96 | template <typename T, typename Buffer> | 97 | template <typename T, typename Buffer> |
97 | void addMapping(const QByteArray &name, const flatbuffers::Vector<uint8_t> * (Buffer::*f)() const) | 98 | void addMapping(const QByteArray &name, const flatbuffers::Vector<uint8_t> *(Buffer::*f)() const) |
98 | { | 99 | { |
99 | addMapping(name, [f](Buffer const *buffer) -> QVariant { | 100 | addMapping(name, [f](Buffer const *buffer) -> QVariant { return propertyToVariant<T>((buffer->*f)()); }); |
100 | return propertyToVariant<T>((buffer->*f)()); | ||
101 | }); | ||
102 | } | 101 | } |
103 | 102 | ||
104 | private: | 103 | private: |
105 | QHash<QByteArray, std::function<QVariant(BufferType const *)> > mReadAccessors; | 104 | QHash<QByteArray, std::function<QVariant(BufferType const *)>> mReadAccessors; |
106 | }; | 105 | }; |
107 | 106 | ||
108 | template<typename BufferBuilder> | 107 | template <typename BufferBuilder> |
109 | class WritePropertyMapper | 108 | class WritePropertyMapper |
110 | { | 109 | { |
111 | public: | 110 | public: |
112 | virtual ~WritePropertyMapper(){}; | 111 | virtual ~WritePropertyMapper(){}; |
113 | 112 | ||
114 | virtual void setProperty(const QByteArray &key, const QVariant &value, QList<std::function<void(BufferBuilder &)> > &builderCalls, flatbuffers::FlatBufferBuilder &fbb) const | 113 | virtual void setProperty(const QByteArray &key, const QVariant &value, QList<std::function<void(BufferBuilder &)>> &builderCalls, flatbuffers::FlatBufferBuilder &fbb) const |
115 | { | 114 | { |
116 | if (mWriteAccessors.contains(key)) { | 115 | if (mWriteAccessors.contains(key)) { |
117 | auto accessor = mWriteAccessors.value(key); | 116 | auto accessor = mWriteAccessors.value(key); |
118 | builderCalls << accessor(value, fbb); | 117 | builderCalls << accessor(value, fbb); |
119 | } | 118 | } |
120 | } | 119 | } |
121 | bool hasMapping(const QByteArray &key) const { return mWriteAccessors.contains(key); } | 120 | bool hasMapping(const QByteArray &key) const |
122 | void addMapping(const QByteArray &property, const std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> &mapping) { | 121 | { |
122 | return mWriteAccessors.contains(key); | ||
123 | } | ||
124 | void addMapping(const QByteArray &property, const std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> &mapping) | ||
125 | { | ||
123 | mWriteAccessors.insert(property, mapping); | 126 | mWriteAccessors.insert(property, mapping); |
124 | } | 127 | } |
125 | 128 | ||
@@ -127,9 +130,7 @@ public: | |||
127 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(uint8_t)) | 130 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(uint8_t)) |
128 | { | 131 | { |
129 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | 132 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { |
130 | return [value, f](BufferBuilder &builder) { | 133 | return [value, f](BufferBuilder &builder) { (builder.*f)(value.value<T>()); }; |
131 | (builder.*f)(value.value<T>()); | ||
132 | }; | ||
133 | }); | 134 | }); |
134 | } | 135 | } |
135 | 136 | ||
@@ -137,9 +138,7 @@ public: | |||
137 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(bool)) | 138 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(bool)) |
138 | { | 139 | { |
139 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | 140 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { |
140 | return [value, f](BufferBuilder &builder) { | 141 | return [value, f](BufferBuilder &builder) { (builder.*f)(value.value<T>()); }; |
141 | (builder.*f)(value.value<T>()); | ||
142 | }; | ||
143 | }); | 142 | }); |
144 | } | 143 | } |
145 | 144 | ||
@@ -148,23 +147,19 @@ public: | |||
148 | { | 147 | { |
149 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | 148 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { |
150 | auto offset = variantToProperty<T>(value, fbb); | 149 | auto offset = variantToProperty<T>(value, fbb); |
151 | return [offset, f](BufferBuilder &builder) { | 150 | return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; |
152 | (builder.*f)(offset); | ||
153 | }; | ||
154 | }); | 151 | }); |
155 | } | 152 | } |
156 | 153 | ||
157 | template <typename T> | 154 | template <typename T> |
158 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::Vector<uint8_t> >)) | 155 | void addMapping(const QByteArray &name, void (BufferBuilder::*f)(flatbuffers::Offset<flatbuffers::Vector<uint8_t>>)) |
159 | { | 156 | { |
160 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { | 157 | addMapping(name, [f](const QVariant &value, flatbuffers::FlatBufferBuilder &fbb) -> std::function<void(BufferBuilder &)> { |
161 | auto offset = variantToProperty<T>(value, fbb); | 158 | auto offset = variantToProperty<T>(value, fbb); |
162 | return [offset, f](BufferBuilder &builder) { | 159 | return [offset, f](BufferBuilder &builder) { (builder.*f)(offset); }; |
163 | (builder.*f)(offset); | ||
164 | }; | ||
165 | }); | 160 | }); |
166 | } | 161 | } |
162 | |||
167 | private: | 163 | private: |
168 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)> > mWriteAccessors; | 164 | QHash<QByteArray, std::function<std::function<void(BufferBuilder &)>(const QVariant &, flatbuffers::FlatBufferBuilder &)>> mWriteAccessors; |
169 | }; | 165 | }; |
170 | |||