Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Rewrite predicate/filter conversion #7548

Merged
merged 4 commits into from
Jan 4, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 59 additions & 1 deletion include/mbgl/style/filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,85 +6,143 @@

#include <string>
#include <vector>
#include <tuple>

namespace mbgl {
namespace style {

class Filter;

class NullFilter {};
class NullFilter {
public:
friend bool operator==(const NullFilter&, const NullFilter&) {
return true;
}
};

class EqualsFilter {
public:
std::string key;
Value value;

friend bool operator==(const EqualsFilter& lhs, const EqualsFilter& rhs) {
return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
}
};

class NotEqualsFilter {
public:
std::string key;
Value value;

friend bool operator==(const NotEqualsFilter& lhs, const NotEqualsFilter& rhs) {
return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
}
};

class LessThanFilter {
public:
std::string key;
Value value;

friend bool operator==(const LessThanFilter& lhs, const LessThanFilter& rhs) {
return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
}
};

class LessThanEqualsFilter {
public:
std::string key;
Value value;

friend bool operator==(const LessThanEqualsFilter& lhs, const LessThanEqualsFilter& rhs) {
return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
}
};

class GreaterThanFilter {
public:
std::string key;
Value value;

friend bool operator==(const GreaterThanFilter& lhs, const GreaterThanFilter& rhs) {
return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
}
};

class GreaterThanEqualsFilter {
public:
std::string key;
Value value;

friend bool operator==(const GreaterThanEqualsFilter& lhs, const GreaterThanEqualsFilter& rhs) {
return std::tie(lhs.key, lhs.value) == std::tie(rhs.key, rhs.value);
}
};

class InFilter {
public:
std::string key;
std::vector<Value> values;

friend bool operator==(const InFilter& lhs, const InFilter& rhs) {
return std::tie(lhs.key, lhs.values) == std::tie(rhs.key, rhs.values);
}
};

class NotInFilter {
public:
std::string key;
std::vector<Value> values;

friend bool operator==(const NotInFilter& lhs, const NotInFilter& rhs) {
return std::tie(lhs.key, lhs.values) == std::tie(rhs.key, rhs.values);
}
};

class AnyFilter {
public:
std::vector<Filter> filters;

friend bool operator==(const AnyFilter& lhs, const AnyFilter& rhs) {
return lhs.filters == rhs.filters;
}
};

class AllFilter {
public:
std::vector<Filter> filters;

friend bool operator==(const AllFilter& lhs, const AllFilter& rhs) {
return lhs.filters == rhs.filters;
}
};

class NoneFilter {
public:
std::vector<Filter> filters;

friend bool operator==(const NoneFilter& lhs, const NoneFilter& rhs) {
return lhs.filters == rhs.filters;
}
};

class HasFilter {
public:
std::string key;

friend bool operator==(const HasFilter& lhs, const HasFilter& rhs) {
return lhs.key == rhs.key;
}
};

class NotHasFilter {
public:
std::string key;

friend bool operator==(const NotHasFilter& lhs, const NotHasFilter& rhs) {
return lhs.key == rhs.key;
}
};

using FilterBase = variant<
Expand Down
12 changes: 7 additions & 5 deletions platform/darwin/src/MGLVectorStyleLayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,9 @@ NS_ASSUME_NONNULL_BEGIN
To test whether a feature has or lacks a specific attribute, compare the attribute to `NULL` or `NIL`. Predicates created using the `+[NSPredicate predicateWithValue:]` method are also supported. String operators and custom operators are not supported.

For details about the predicate format string syntax, consult the “Predicate
Format String Syntax” chapter of the “Predicate Programming Guide” in Apple
developer documentation.
Format String Syntax” chapter of the
“<a href="https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/Predicates/">Predicate Programming Guide</a>”
in Apple developer documentation.

The predicate's left-hand expression must be a string that identifies a feature
attribute or, alternatively, one of the following special attributes:
Expand Down Expand Up @@ -119,9 +120,10 @@ NS_ASSUME_NONNULL_BEGIN

Automatic type casting is not performed. Therefore, a feature only matches this
predicate if its value for the attribute in question is of the same type as the
value specified in the predicate. Also, operator modifiers `c`, `d`, and the
combined `cd` for case and diacritic insensitivity are unsupported for
comparison and aggregate operators that are used in the predicate.
value specified in the predicate. Also, operator modifiers such as `c` (for
case insensitivity), `d` (for diacritic insensitivity), and `l` (for locale
sensitivity) are unsupported for comparison and aggregate operators that are
used in the predicate.

It is possible to create expressions that contain special characters in the
predicate format syntax. This includes the `$` in the `$id` and `$type` special
Expand Down
4 changes: 2 additions & 2 deletions platform/darwin/src/NSArray+MGLAdditions.mm
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ @implementation NSArray (MGLAdditions)
vector.push_back(propertyMap);
} else {
NSExpression *expression = [NSExpression expressionForConstantValue:value];
vector.push_back([expression mgl_filterValue]);
vector.push_back(expression.mgl_constantMBGLValue);
}
}
}
return vector;
}

Expand Down
Loading