summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzmiao <miao.zhao@mapbox.com>2020-04-21 20:19:51 +0300
committerzmiao <miao.zhao@mapbox.com>2020-04-22 15:53:08 +0300
commit3a14e52f4c7c4b0ef823266b48793267e3b78b64 (patch)
treec7657a66b1be1c68b05852407f8d7f1286f43b73
parent87c4cb55450fb17bcd8a871fe52f29d2646e0156 (diff)
downloadqtlocation-mapboxgl-3a14e52f4c7c4b0ef823266b48793267e3b78b64.tar.gz
[core] Distance expression: Fix expression serialization
-rw-r--r--src/mbgl/style/expression/distance.cpp14
-rw-r--r--src/mbgl/style/expression/within.cpp14
2 files changed, 16 insertions, 12 deletions
diff --git a/src/mbgl/style/expression/distance.cpp b/src/mbgl/style/expression/distance.cpp
index d2b35e0f6c..78d80dc649 100644
--- a/src/mbgl/style/expression/distance.cpp
+++ b/src/mbgl/style/expression/distance.cpp
@@ -535,8 +535,10 @@ ParseResult Distance::parse(const Convertible& value, ParsingContext& ctx) {
return ParseResult();
}
-Value convertValue(const mapbox::geojson::rapidjson_value& v) {
- if (v.IsDouble() || v.IsInt() || v.IsUint() || v.IsInt64() || v.IsUint64()) {
+mbgl::Value convertValue(const mapbox::geojson::rapidjson_value& v) {
+ if (v.IsNumber()) {
+ if (v.IsInt64()) return std::int64_t(v.GetInt64());
+ if (v.IsUint64()) return std::uint64_t(v.GetUint64());
return v.GetDouble();
}
if (v.IsBool()) {
@@ -546,7 +548,7 @@ Value convertValue(const mapbox::geojson::rapidjson_value& v) {
return std::string(v.GetString());
}
if (v.IsArray()) {
- std::vector<Value> result;
+ std::vector<mbgl::Value> result;
result.reserve(v.Size());
for (const auto& m : v.GetArray()) {
result.push_back(convertValue(m));
@@ -554,7 +556,7 @@ Value convertValue(const mapbox::geojson::rapidjson_value& v) {
return result;
}
if (v.IsObject()) {
- std::unordered_map<std::string, Value> result;
+ std::unordered_map<std::string, mbgl::Value> result;
for (const auto& m : v.GetObject()) {
result.emplace(m.name.GetString(), convertValue(m.value));
}
@@ -586,7 +588,7 @@ std::string getUnits(const mapbox::cheap_ruler::CheapRuler::Unit& unit) {
}
mbgl::Value Distance::serialize() const {
- std::unordered_map<std::string, Value> serialized;
+ std::unordered_map<std::string, mbgl::Value> serialized;
rapidjson::CrtAllocator allocator;
const mapbox::geojson::rapidjson_value value = mapbox::geojson::convert(geoJSONSource, allocator);
if (value.IsObject()) {
@@ -597,7 +599,7 @@ mbgl::Value Distance::serialize() const {
mbgl::Log::Error(mbgl::Event::General,
"Failed to serialize 'distance' expression, converted rapidJSON is not an object");
}
- return std::vector<mbgl::Value>{{getOperator(), *fromExpressionValue<mbgl::Value>(serialized), getUnits(unit)}};
+ return std::vector<mbgl::Value>{{getOperator(), serialized, getUnits(unit)}};
}
bool Distance::operator==(const Expression& e) const {
diff --git a/src/mbgl/style/expression/within.cpp b/src/mbgl/style/expression/within.cpp
index c5ec53ba3a..2b8a6a65bf 100644
--- a/src/mbgl/style/expression/within.cpp
+++ b/src/mbgl/style/expression/within.cpp
@@ -264,8 +264,10 @@ ParseResult Within::parse(const Convertible& value, ParsingContext& ctx) {
return ParseResult();
}
-Value valueConverter(const mapbox::geojson::rapidjson_value& v) {
- if (v.IsDouble() || v.IsInt() || v.IsUint() || v.IsInt64() || v.IsUint64()) {
+mbgl::Value valueConverter(const mapbox::geojson::rapidjson_value& v) {
+ if (v.IsNumber()) {
+ if (v.IsInt64()) return std::int64_t(v.GetInt64());
+ if (v.IsUint64()) return std::uint64_t(v.GetUint64());
return v.GetDouble();
}
if (v.IsBool()) {
@@ -275,7 +277,7 @@ Value valueConverter(const mapbox::geojson::rapidjson_value& v) {
return std::string(v.GetString());
}
if (v.IsArray()) {
- std::vector<Value> result;
+ std::vector<mbgl::Value> result;
result.reserve(v.Size());
for (const auto& m : v.GetArray()) {
result.push_back(valueConverter(m));
@@ -283,7 +285,7 @@ Value valueConverter(const mapbox::geojson::rapidjson_value& v) {
return result;
}
if (v.IsObject()) {
- std::unordered_map<std::string, Value> result;
+ std::unordered_map<std::string, mbgl::Value> result;
for (const auto& m : v.GetObject()) {
result.emplace(m.name.GetString(), valueConverter(m.value));
}
@@ -294,7 +296,7 @@ Value valueConverter(const mapbox::geojson::rapidjson_value& v) {
}
mbgl::Value Within::serialize() const {
- std::unordered_map<std::string, Value> serialized;
+ std::unordered_map<std::string, mbgl::Value> serialized;
rapidjson::CrtAllocator allocator;
const mapbox::geojson::rapidjson_value value = mapbox::geojson::convert(geoJSONSource, allocator);
if (value.IsObject()) {
@@ -305,7 +307,7 @@ mbgl::Value Within::serialize() const {
mbgl::Log::Error(mbgl::Event::General,
"Failed to serialize 'within' expression, converted rapidJSON is not an object");
}
- return std::vector<mbgl::Value>{{getOperator(), *fromExpressionValue<mbgl::Value>(serialized)}};
+ return std::vector<mbgl::Value>{{getOperator(), serialized}};
}
bool Within::operator==(const Expression& e) const {