summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-10-17 09:50:19 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-10-17 09:50:19 -0700
commit1eb92d9a417da81a2ee1515387589074a4961898 (patch)
tree502bd30051580518b17e4d2b431db007a8237fc4
parentd3b5aa5c7144b78590012b1fe2b21389280f0ed1 (diff)
downloadqtlocation-mapboxgl-1eb92d9a417da81a2ee1515387589074a4961898.tar.gz
A moved-from Value must be put into a distinct state
-rw-r--r--include/mbgl/style/conversion.hpp30
1 files changed, 26 insertions, 4 deletions
diff --git a/include/mbgl/style/conversion.hpp b/include/mbgl/style/conversion.hpp
index 40ae329c05..7e3073264b 100644
--- a/include/mbgl/style/conversion.hpp
+++ b/include/mbgl/style/conversion.hpp
@@ -61,17 +61,26 @@ public:
Value(Value&& v)
: vtable(v.vtable)
{
- vtable->move(std::move(v.storage), this->storage);
+ if (vtable) {
+ vtable->move(std::move(v.storage), this->storage);
+ }
}
~Value() {
- vtable->destroy(storage);
+ if (vtable) {
+ vtable->destroy(storage);
+ }
}
Value& operator=(Value&& v) {
- vtable->destroy(storage);
+ if (vtable) {
+ vtable->destroy(storage);
+ }
vtable = v.vtable;
- vtable->move(std::move(v.storage), this->storage);
+ if (vtable) {
+ vtable->move(std::move(v.storage), this->storage);
+ }
+ v.vtable = nullptr;
return *this;
}
@@ -80,54 +89,67 @@ public:
Value& operator=(const Value&) = delete;
friend inline bool isUndefined(const Value& v) {
+ assert(v.vtable);
return v.vtable->isUndefined(v.storage);
}
friend inline bool isArray(const Value& v) {
+ assert(v.vtable);
return v.vtable->isArray(v.storage);
}
friend inline std::size_t arrayLength(const Value& v) {
+ assert(v.vtable);
return v.vtable->arrayLength(v.storage);
}
friend inline Value arrayMember(const Value& v, std::size_t i) {
+ assert(v.vtable);
return v.vtable->arrayMember(v.storage, i);
}
friend inline bool isObject(const Value& v) {
+ assert(v.vtable);
return v.vtable->isObject(v.storage);
}
friend inline optional<Value> objectMember(const Value& v, const char * name) {
+ assert(v.vtable);
return v.vtable->objectMember(v.storage, name);
}
friend inline optional<Error> eachMember(const Value& v, const std::function<optional<Error> (const std::string&, const Value&)>& fn) {
+ assert(v.vtable);
return v.vtable->eachMember(v.storage, fn);
}
friend inline optional<bool> toBool(const Value& v) {
+ assert(v.vtable);
return v.vtable->toBool(v.storage);
}
friend inline optional<float> toNumber(const Value& v) {
+ assert(v.vtable);
return v.vtable->toNumber(v.storage);
}
friend inline optional<double> toDouble(const Value& v) {
+ assert(v.vtable);
return v.vtable->toDouble(v.storage);
}
friend inline optional<std::string> toString(const Value& v) {
+ assert(v.vtable);
return v.vtable->toString(v.storage);
}
friend inline optional<mbgl::Value> toValue(const Value& v) {
+ assert(v.vtable);
return v.vtable->toValue(v.storage);
}
friend inline optional<GeoJSON> toGeoJSON(const Value& v, Error& error) {
+ assert(v.vtable);
return v.vtable->toGeoJSON(v.storage, error);
}