summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-02-09 16:18:57 -0600
committerMinh Nguyễn <mxn@1ec5.org>2017-02-09 14:18:57 -0800
commita1a639120d7662cb68f0ba5770e4f42cc9415069 (patch)
treefc92f9c1f0422da0bda7d35a0a6e446626c5b06d /src
parent272dc3f6a91ee1f0734c6642d610366f4396ec93 (diff)
downloadqtlocation-mapboxgl-a1a639120d7662cb68f0ba5770e4f42cc9415069.tar.gz
[core] Introduce dedicated filter types for $type and $id special cases (#7971)
* [core] Introduce dedicated filter types for $type and $id special cases * [ios, macos] Special-case $id, $type in predicates Also support $id ≟ nil.
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/style/conversion/stringify.hpp86
1 files changed, 79 insertions, 7 deletions
diff --git a/src/mbgl/style/conversion/stringify.hpp b/src/mbgl/style/conversion/stringify.hpp
index 4b9cf6d26e..4afbf198e5 100644
--- a/src/mbgl/style/conversion/stringify.hpp
+++ b/src/mbgl/style/conversion/stringify.hpp
@@ -103,6 +103,29 @@ void stringify(Writer& writer, const Value& v) {
}
template <class Writer>
+void stringify(Writer& writer, FeatureType type) {
+ switch (type) {
+ case FeatureType::Unknown:
+ writer.String("Unknown");
+ break;
+ case FeatureType::Point:
+ writer.String("Point");
+ break;
+ case FeatureType::LineString:
+ writer.String("LineString");
+ break;
+ case FeatureType::Polygon:
+ writer.String("Polygon");
+ break;
+ }
+}
+
+template <class Writer>
+void stringify(Writer& writer, const FeatureIdentifier& id) {
+ FeatureIdentifier::visit(id, [&] (const auto& id_) { stringify(writer, id_); });
+}
+
+template <class Writer>
class StringifyFilter {
public:
Writer& writer;
@@ -156,28 +179,78 @@ public:
}
void operator()(const HasFilter& f) {
- stringifyUnaryFilter(f, "has");
+ stringifyUnaryFilter("has", f.key);
}
void operator()(const NotHasFilter& f) {
- stringifyUnaryFilter(f, "!has");
+ stringifyUnaryFilter("!has", f.key);
+ }
+
+ void operator()(const TypeEqualsFilter& f) {
+ stringifyBinaryFilter(f, "==", "$type");
+ }
+
+ void operator()(const TypeNotEqualsFilter& f) {
+ stringifyBinaryFilter(f, "!=", "$type");
+ }
+
+ void operator()(const TypeInFilter& f) {
+ stringifySetFilter(f, "in", "$type");
+ }
+
+ void operator()(const TypeNotInFilter& f) {
+ stringifySetFilter(f, "!in", "$type");
+ }
+
+ void operator()(const IdentifierEqualsFilter& f) {
+ stringifyBinaryFilter(f, "==", "$id");
+ }
+
+ void operator()(const IdentifierNotEqualsFilter& f) {
+ stringifyBinaryFilter(f, "!=", "$id");
+ }
+
+ void operator()(const IdentifierInFilter& f) {
+ stringifySetFilter(f, "in", "$id");
+ }
+
+ void operator()(const IdentifierNotInFilter& f) {
+ stringifySetFilter(f, "!in", "$id");
+ }
+
+ void operator()(const HasIdentifierFilter&) {
+ stringifyUnaryFilter("has", "$id");
+ }
+
+ void operator()(const NotHasIdentifierFilter&) {
+ stringifyUnaryFilter("!has", "$id");
}
private:
template <class F>
void stringifyBinaryFilter(const F& f, const char * op) {
+ stringifyBinaryFilter(f, op, f.key);
+ }
+
+ template <class F>
+ void stringifyBinaryFilter(const F& f, const char * op, const std::string& key) {
writer.StartArray();
writer.String(op);
- writer.String(f.key);
+ writer.String(key);
stringify(writer, f.value);
writer.EndArray();
}
template <class F>
void stringifySetFilter(const F& f, const char * op) {
+ stringifySetFilter(f, op, f.key);
+ }
+
+ template <class F>
+ void stringifySetFilter(const F& f, const char * op, const std::string& key) {
writer.StartArray();
writer.String(op);
- writer.String(f.key);
+ writer.String(key);
for (const auto& value : f.values) {
stringify(writer, value);
}
@@ -194,11 +267,10 @@ private:
writer.EndArray();
}
- template <class F>
- void stringifyUnaryFilter(const F& f, const char * op) {
+ void stringifyUnaryFilter(const char * op, const std::string& key) {
writer.StartArray();
writer.String(op);
- writer.String(f.key);
+ writer.String(key);
writer.EndArray();
}
};