summaryrefslogtreecommitdiff
path: root/include/mbgl/style/filter_evaluator.hpp
diff options
context:
space:
mode:
authorJesse Crocker <jesse@gaiagps.com>2017-03-01 11:15:11 -0700
committerJesse Crocker <jesse@gaiagps.com>2017-03-01 11:15:11 -0700
commit9e8dc9a9e3e86adb9987ae69766cc42c7d9efece (patch)
treef5f0abd4d342c89ad0405d01969f9d6caecc1c90 /include/mbgl/style/filter_evaluator.hpp
parent16fb0672e64a72b7400c321d55858b73cd5d8c3f (diff)
parentf28d75dccd9bf4a7615df87faccc5cf5eff8df89 (diff)
downloadqtlocation-mapboxgl-9e8dc9a9e3e86adb9987ae69766cc42c7d9efece.tar.gz
Merge remote-tracking branch 'origin/master' into feature/custom-vector-source
Diffstat (limited to 'include/mbgl/style/filter_evaluator.hpp')
-rw-r--r--include/mbgl/style/filter_evaluator.hpp92
1 files changed, 69 insertions, 23 deletions
diff --git a/include/mbgl/style/filter_evaluator.hpp b/include/mbgl/style/filter_evaluator.hpp
index 659f554bba..370064445a 100644
--- a/include/mbgl/style/filter_evaluator.hpp
+++ b/include/mbgl/style/filter_evaluator.hpp
@@ -31,37 +31,37 @@ public:
}
bool operator()(const EqualsFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
return actual && equal(*actual, filter.value);
}
bool operator()(const NotEqualsFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
return !actual || !equal(*actual, filter.value);
}
bool operator()(const LessThanFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ < rhs_; });
}
bool operator()(const LessThanEqualsFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ <= rhs_; });
}
bool operator()(const GreaterThanFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ > rhs_; });
}
bool operator()(const GreaterThanEqualsFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
return actual && compare(*actual, filter.value, [] (const auto& lhs_, const auto& rhs_) { return lhs_ >= rhs_; });
}
bool operator()(const InFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
if (!actual)
return false;
for (const auto& v: filter.values) {
@@ -73,7 +73,7 @@ public:
}
bool operator()(const NotInFilter& filter) const {
- optional<Value> actual = getValue(filter.key);
+ optional<Value> actual = propertyAccessor(filter.key);
if (!actual)
return true;
for (const auto& v: filter.values) {
@@ -112,30 +112,76 @@ public:
}
bool operator()(const HasFilter& filter) const {
- return bool(getValue(filter.key));
+ return bool(propertyAccessor(filter.key));
}
bool operator()(const NotHasFilter& filter) const {
- return !getValue(filter.key);
+ return !propertyAccessor(filter.key);
}
-private:
- optional<Value> getValue(const std::string& key_) const {
- if (key_ == "$type") {
- return optional<Value>(uint64_t(featureType));
- } else if (key_ == "$id") {
- if (featureIdentifier) {
- return FeatureIdentifier::visit(*featureIdentifier, [] (auto id) {
- return Value(std::move(id));
- });
- } else {
- return optional<Value>();
+
+ bool operator()(const TypeEqualsFilter& filter) const {
+ return featureType == filter.value;
+ }
+
+ bool operator()(const TypeNotEqualsFilter& filter) const {
+ return featureType != filter.value;
+ }
+
+ bool operator()(const TypeInFilter& filter) const {
+ for (const auto& v: filter.values) {
+ if (featureType == v) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ bool operator()(const TypeNotInFilter& filter) const {
+ for (const auto& v: filter.values) {
+ if (featureType == v) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+
+ bool operator()(const IdentifierEqualsFilter& filter) const {
+ return featureIdentifier == filter.value;
+ }
+
+ bool operator()(const IdentifierNotEqualsFilter& filter) const {
+ return featureIdentifier != filter.value;
+ }
+
+ bool operator()(const IdentifierInFilter& filter) const {
+ for (const auto& v: filter.values) {
+ if (featureIdentifier == v) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ bool operator()(const IdentifierNotInFilter& filter) const {
+ for (const auto& v: filter.values) {
+ if (featureIdentifier == v) {
+ return false;
}
- } else {
- return propertyAccessor(key_);
}
+ return true;
}
+ bool operator()(const HasIdentifierFilter&) const {
+ return bool(featureIdentifier);
+ }
+
+ bool operator()(const NotHasIdentifierFilter&) const {
+ return !featureIdentifier;
+ }
+
+private:
template <class Op>
struct Comparator {
const Op& op;