summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2018-11-30 14:31:37 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-01-14 10:45:49 -0400
commitf31386385952f42e0468c7d7a0ab0a066f0bf803 (patch)
tree74432eaa3544daa5f749a315399249c1af30e718
parenta4f2fe4209ef6961662fb53ee5c29cafacd2a303 (diff)
downloadqtlocation-mapboxgl-upstream/geometrytilefeature-getvalue-no-optional.tar.gz
[core] Remove optional from GeometryTileFeature::getValue()upstream/geometrytilefeature-getvalue-no-optional
-rw-r--r--platform/default/mbgl/tile/default_tile_feature.hpp8
-rw-r--r--src/mbgl/annotation/annotation_tile.cpp7
-rw-r--r--src/mbgl/annotation/annotation_tile.hpp2
-rw-r--r--src/mbgl/layout/symbol_feature.hpp2
-rw-r--r--src/mbgl/style/expression/compound_expression.cpp29
-rw-r--r--src/mbgl/style/expression/expression.cpp10
-rw-r--r--src/mbgl/tile/geojson_tile_data.hpp8
-rw-r--r--src/mbgl/tile/geometry_tile_data.hpp4
-rw-r--r--src/mbgl/tile/vector_tile_data.cpp5
-rw-r--r--src/mbgl/tile/vector_tile_data.hpp2
-rw-r--r--test/tile/vector_tile.test.cpp6
11 files changed, 40 insertions, 43 deletions
diff --git a/platform/default/mbgl/tile/default_tile_feature.hpp b/platform/default/mbgl/tile/default_tile_feature.hpp
index 9183fd583a..417bb8c637 100644
--- a/platform/default/mbgl/tile/default_tile_feature.hpp
+++ b/platform/default/mbgl/tile/default_tile_feature.hpp
@@ -29,13 +29,17 @@ public:
return id;
}
- optional<Value> getValue(const std::string& key) const override {
- return properties.count(key) ? properties.at(key) : optional<Value>();
+ Value getValue(const std::string& key) const override {
+ return properties.count(key) ? properties.at(key) : NullValue();
}
GeometryCollection getGeometries() const override {
return geometry;
}
+
+ const PropertyMap& getProperties() const override {
+ return properties;
+ }
};
} // namespace mbgl
diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp
index 74a7dad682..d22e1ca9b3 100644
--- a/src/mbgl/annotation/annotation_tile.cpp
+++ b/src/mbgl/annotation/annotation_tile.cpp
@@ -47,12 +47,9 @@ FeatureType AnnotationTileFeature::getType() const {
return data->type;
}
-optional<Value> AnnotationTileFeature::getValue(const std::string& key) const {
+Value AnnotationTileFeature::getValue(const std::string& key) const {
auto it = data->properties.find(key);
- if (it != data->properties.end()) {
- return optional<Value>(it->second);
- }
- return optional<Value>();
+ return it != data->properties.cend() ? it->second : NullValue();
}
FeatureIdentifier AnnotationTileFeature::getID() const {
diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp
index 7757f0b0ce..cc5a3dfb52 100644
--- a/src/mbgl/annotation/annotation_tile.hpp
+++ b/src/mbgl/annotation/annotation_tile.hpp
@@ -26,7 +26,7 @@ public:
~AnnotationTileFeature() override;
FeatureType getType() const override;
- optional<Value> getValue(const std::string&) const override;
+ Value getValue(const std::string&) const override;
FeatureIdentifier getID() const override;
const PropertyMap& getProperties() const override;
GeometryCollection getGeometries() const override;
diff --git a/src/mbgl/layout/symbol_feature.hpp b/src/mbgl/layout/symbol_feature.hpp
index 0773c48d39..617e8c9ba2 100644
--- a/src/mbgl/layout/symbol_feature.hpp
+++ b/src/mbgl/layout/symbol_feature.hpp
@@ -17,7 +17,7 @@ public:
{}
FeatureType getType() const override { return feature->getType(); }
- optional<Value> getValue(const std::string& key) const override { return feature->getValue(key); };
+ Value getValue(const std::string& key) const override { return feature->getValue(key); };
const PropertyMap& getProperties() const override { return feature->getProperties(); };
FeatureIdentifier getID() const override { return feature->getID(); };
GeometryCollection getGeometries() const override { return geometry; };
diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp
index cc1d58025b..53512ce89e 100644
--- a/src/mbgl/style/expression/compound_expression.cpp
+++ b/src/mbgl/style/expression/compound_expression.cpp
@@ -234,8 +234,12 @@ Value featureIdAsExpressionValue(EvaluationContext params) {
optional<Value> featurePropertyAsExpressionValue(EvaluationContext params, const std::string& key) {
assert(params.feature);
- auto property = params.feature->getValue(key);
- return property ? toExpressionValue(*property) : optional<Value>();
+ const PropertyMap& properties = params.feature->getProperties();
+ const auto it = properties.find(key);
+ if (it == properties.cend()) {
+ return optional<Value>();
+ }
+ return toExpressionValue(it->second);
};
optional<std::string> featureTypeAsString(FeatureType type) {
@@ -255,9 +259,7 @@ optional<std::string> featureTypeAsString(FeatureType type) {
optional<double> featurePropertyAsDouble(EvaluationContext params, const std::string& key) {
assert(params.feature);
- auto property = params.feature->getValue(key);
- if (!property) return {};
- return property->match(
+ return params.feature->getValue(key).match(
[](double value) { return value; },
[](uint64_t value) { return optional<double>(static_cast<double>(value)); },
[](int64_t value) { return optional<double>(static_cast<double>(value)); },
@@ -267,9 +269,7 @@ optional<double> featurePropertyAsDouble(EvaluationContext params, const std::st
optional<std::string> featurePropertyAsString(EvaluationContext params, const std::string& key) {
assert(params.feature);
- auto property = params.feature->getValue(key);
- if (!property) return {};
- return property->match(
+ return params.feature->getValue(key).match(
[](std::string value) { return value; },
[](auto) { return optional<std::string>(); }
);
@@ -376,7 +376,8 @@ const auto& hasContextCompoundExpression() {
};
}
- return params.feature->getValue(key) ? true : false;
+ const PropertyMap& properties = params.feature->getProperties();
+ return properties.find(key) != properties.cend();
});
return signature;
}
@@ -396,11 +397,12 @@ const auto& getContextCompoundExpression() {
};
}
- auto propertyValue = params.feature->getValue(key);
- if (!propertyValue) {
+ const PropertyMap& properties = params.feature->getProperties();
+ const auto it = properties.find(key);
+ if (it == properties.cend()) {
return Null;
}
- return Value(toExpressionValue(*propertyValue));
+ return toExpressionValue(it->second);
});
return signature;
}
@@ -817,7 +819,8 @@ const auto& filterIdGreaterOrEqualThanStringCompoundExpression() {
const auto& filterHasCompoundExpression() {
static auto signature = detail::makeSignature("filter-has", [](const EvaluationContext& params, const std::string& key) -> Result<bool> {
assert(params.feature);
- return bool(params.feature->getValue(key));
+ const PropertyMap& properties = params.feature->getProperties();
+ return properties.find(key) != properties.cend();
});
return signature;
}
diff --git a/src/mbgl/style/expression/expression.cpp b/src/mbgl/style/expression/expression.cpp
index bb03bcc2e5..8b61aef7ca 100644
--- a/src/mbgl/style/expression/expression.cpp
+++ b/src/mbgl/style/expression/expression.cpp
@@ -2,6 +2,8 @@
#include <mbgl/style/expression/compound_expression.hpp>
#include <mbgl/tile/geometry_tile_data.hpp>
+#include <mbgl/util/feature.hpp>
+
namespace mbgl {
namespace style {
namespace expression {
@@ -18,12 +20,8 @@ public:
const PropertyMap& getProperties() const override { return feature.properties; }
FeatureIdentifier getID() const override { return feature.id; }
GeometryCollection getGeometries() const override { return {}; }
- optional<mbgl::Value> getValue(const std::string& key) const override {
- auto it = feature.properties.find(key);
- if (it != feature.properties.end()) {
- return optional<mbgl::Value>(it->second);
- }
- return optional<mbgl::Value>();
+ mbgl::Value getValue(const std::string& key) const override {
+ return feature.properties.count(key) ? feature.properties.at(key) : NullValue();
}
};
diff --git a/src/mbgl/tile/geojson_tile_data.hpp b/src/mbgl/tile/geojson_tile_data.hpp
index 70a985db47..9325f1bb16 100644
--- a/src/mbgl/tile/geojson_tile_data.hpp
+++ b/src/mbgl/tile/geojson_tile_data.hpp
@@ -36,12 +36,8 @@ public:
return geometry;
}
- optional<Value> getValue(const std::string& key) const override {
- auto it = feature.properties.find(key);
- if (it != feature.properties.end()) {
- return optional<Value>(it->second);
- }
- return optional<Value>();
+ Value getValue(const std::string& key) const override {
+ return feature.properties.count(key) ? feature.properties.at(key) : NullValue();
}
};
diff --git a/src/mbgl/tile/geometry_tile_data.hpp b/src/mbgl/tile/geometry_tile_data.hpp
index 3913615465..8200e51ad8 100644
--- a/src/mbgl/tile/geometry_tile_data.hpp
+++ b/src/mbgl/tile/geometry_tile_data.hpp
@@ -41,8 +41,8 @@ class GeometryTileFeature {
public:
virtual ~GeometryTileFeature() = default;
virtual FeatureType getType() const = 0;
- virtual optional<Value> getValue(const std::string& key) const = 0;
- virtual const PropertyMap& getProperties() const { static PropertyMap empty; return empty; }
+ virtual Value getValue(const std::string& key) const = 0;
+ virtual const PropertyMap& getProperties() const = 0;
virtual FeatureIdentifier getID() const { return NullValue {}; }
virtual GeometryCollection getGeometries() const = 0;
};
diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp
index 305f8e7dcf..be66dc0709 100644
--- a/src/mbgl/tile/vector_tile_data.cpp
+++ b/src/mbgl/tile/vector_tile_data.cpp
@@ -21,9 +21,8 @@ FeatureType VectorTileFeature::getType() const {
}
}
-optional<Value> VectorTileFeature::getValue(const std::string& key) const {
- const optional<Value> value(feature.getValue(key));
- return value->is<NullValue>() ? nullopt : std::move(value);
+Value VectorTileFeature::getValue(const std::string& key) const {
+ return feature.getValue(key);
}
const PropertyMap& VectorTileFeature::getProperties() const {
diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp
index 7a169ac44c..ace20bcfc4 100644
--- a/src/mbgl/tile/vector_tile_data.hpp
+++ b/src/mbgl/tile/vector_tile_data.hpp
@@ -14,7 +14,7 @@ public:
VectorTileFeature(const mapbox::vector_tile::layer&, const protozero::data_view&);
FeatureType getType() const override;
- optional<Value> getValue(const std::string& key) const override;
+ Value getValue(const std::string& key) const override;
const PropertyMap& getProperties() const override;
FeatureIdentifier getID() const override;
GeometryCollection getGeometries() const override;
diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp
index ed3eda7863..07110fdd7f 100644
--- a/test/tile/vector_tile.test.cpp
+++ b/test/tile/vector_tile.test.cpp
@@ -103,7 +103,7 @@ TEST(VectorTileData, ParseResults) {
std::unordered_map<std::string, Value> properties = feature->getProperties();
ASSERT_EQ(properties.size(), 3u);
- ASSERT_EQ(properties.at("disputed"), *feature->getValue("disputed"));
+ ASSERT_EQ(properties.at("disputed"), feature->getValue("disputed"));
- ASSERT_EQ(feature->getValue("invalid"), nullopt);
-} \ No newline at end of file
+ ASSERT_EQ(feature->getValue("invalid"), NullValue());
+}