diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-08 13:18:19 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-12-08 13:18:19 +0100 |
commit | ae4b64b198a143240aa5dd1e202e5016abfdae71 (patch) | |
tree | 5d9d58a512ebc60c44637d11c9424f67a02887e8 /common/propertymapper.cpp | |
parent | f425c2070131161dc11bcf70e35f8d1848cadb65 (diff) | |
download | sink-ae4b64b198a143240aa5dd1e202e5016abfdae71.tar.gz sink-ae4b64b198a143240aa5dd1e202e5016abfdae71.zip |
Wrap references in a Reerence type.
This allows us to make sure that references are not taken out of
context (the resource).
Because we need to use the type-specific accessors more we also ran into
a problem that we cannot "downcast" a reference with the change
recording still working, for that we have the cast<T>() operator now.
Diffstat (limited to 'common/propertymapper.cpp')
-rw-r--r-- | common/propertymapper.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/common/propertymapper.cpp b/common/propertymapper.cpp index 249221a..4cfe154 100644 --- a/common/propertymapper.cpp +++ b/common/propertymapper.cpp | |||
@@ -42,6 +42,15 @@ flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::BLOB>(const QV | |||
42 | } | 42 | } |
43 | 43 | ||
44 | template <> | 44 | template <> |
45 | flatbuffers::uoffset_t variantToProperty<Sink::ApplicationDomain::Reference>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | ||
46 | { | ||
47 | if (property.isValid()) { | ||
48 | return fbb.CreateString(property.value<Sink::ApplicationDomain::Reference>().value.toStdString()).o; | ||
49 | } | ||
50 | return 0; | ||
51 | } | ||
52 | |||
53 | template <> | ||
45 | flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) | 54 | flatbuffers::uoffset_t variantToProperty<QByteArray>(const QVariant &property, flatbuffers::FlatBufferBuilder &fbb) |
46 | { | 55 | { |
47 | if (property.isValid()) { | 56 | if (property.isValid()) { |
@@ -130,6 +139,16 @@ QVariant propertyToVariant<Sink::ApplicationDomain::BLOB>(const flatbuffers::Str | |||
130 | } | 139 | } |
131 | 140 | ||
132 | template <> | 141 | template <> |
142 | QVariant propertyToVariant<Sink::ApplicationDomain::Reference>(const flatbuffers::String *property) | ||
143 | { | ||
144 | if (property) { | ||
145 | // We have to copy the memory, otherwise it would become eventually invalid | ||
146 | return QVariant::fromValue(Sink::ApplicationDomain::Reference{QString::fromStdString(property->c_str()).toUtf8()}); | ||
147 | } | ||
148 | return QVariant(); | ||
149 | } | ||
150 | |||
151 | template <> | ||
133 | QVariant propertyToVariant<QByteArray>(const flatbuffers::String *property) | 152 | QVariant propertyToVariant<QByteArray>(const flatbuffers::String *property) |
134 | { | 153 | { |
135 | if (property) { | 154 | if (property) { |