summaryrefslogtreecommitdiff
path: root/platform/darwin/src/NSExpression+MGLAdditions.mm
diff options
context:
space:
mode:
authorMinh Nguyễn <mxn@1ec5.org>2016-12-26 14:24:05 -0800
committerMinh Nguyễn <mxn@1ec5.org>2017-01-04 08:52:41 -0800
commite6132d248b54d202c3fa132b3084660a0bbe3c06 (patch)
treef6b98d23625169ded08d8f3b8965d3619f3fe2da /platform/darwin/src/NSExpression+MGLAdditions.mm
parent83309fd369c9623a1e2638f98f75206609d44258 (diff)
downloadqtlocation-mapboxgl-e6132d248b54d202c3fa132b3084660a0bbe3c06.tar.gz
[ios, macos] Rewrote predicate/filter conversion
When converting predicates to filters, symmetric comparison predicates can now compare a value to a key in addition to the usual key-to-value order. Added error checking for unhandled combinations like key-to-key. Fixed a crash converting a CONTAINS predicate into a filter. Added support for constant value expressions inside aggregate expressions. Allow sets as aggregate expressions just like arrays, except in BETWEEN predicates where order matters. Flatten NOT predicates into more specialized filters. When converting filters to predicates, use constant value expressions inside aggregate expressions. Convert to a BETWEEN predicate when possible. Replaced predicate round-tripping integration tests with systematic unit tests for converting in either direction, plus unit tests for round-tripping and symmetry. Refined exception names and messages. Realphabetized files in groups.
Diffstat (limited to 'platform/darwin/src/NSExpression+MGLAdditions.mm')
-rw-r--r--platform/darwin/src/NSExpression+MGLAdditions.mm25
1 files changed, 16 insertions, 9 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm
index 6af069487e..97f3e11dba 100644
--- a/platform/darwin/src/NSExpression+MGLAdditions.mm
+++ b/platform/darwin/src/NSExpression+MGLAdditions.mm
@@ -4,15 +4,19 @@
- (std::vector<mbgl::Value>)mgl_filterValues
{
- if ([self.constantValue isKindOfClass:NSArray.class]) {
- NSArray *values = self.constantValue;
- std::vector<mbgl::Value>convertedValues;
- for (id value in values) {
- convertedValues.push_back([self mgl_convertedValueWithValue:value]);
+ if ([self.constantValue isKindOfClass:[NSArray class]] || [self.constantValue isKindOfClass:[NSSet class]]) {
+ std::vector<mbgl::Value> convertedValues;
+ for (id item in self.constantValue) {
+ id constantValue = item;
+ if ([item isKindOfClass:[NSExpression class]]) {
+ constantValue = [constantValue constantValue];
+ }
+ convertedValues.push_back([self mgl_convertedValueWithValue:constantValue]);
}
return convertedValues;
}
- [NSException raise:@"Values not handled" format:@""];
+ [NSException raise:NSInvalidArgumentException
+ format:@"Constant value expression must contain an array or set."];
return { };
}
@@ -42,7 +46,10 @@
// We still do this conversion in order to provide a valid value.
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
- NSLog(@"One-time warning: Float values are converted to double and can introduce imprecision; please use double values explicitly in predicate arguments.");
+ NSLog(@"Float value in expression will be converted to a double; some imprecision may result. "
+ @"Use double values explicitly when specifying constant expression values and "
+ @"when specifying arguments to predicate and expression format strings. "
+ @"This will be logged only once.");
});
return { (double)number.doubleValue };
} else if ([number compare:@(0)] == NSOrderedDescending ||
@@ -55,8 +62,8 @@
// We use long long here to avoid any truncation.
return { (int64_t)number.longLongValue };
}
- } else if (value != [NSNull null]) {
- [NSException raise:@"Value not handled"
+ } else if (value && value != [NSNull null]) {
+ [NSException raise:NSInvalidArgumentException
format:@"Can’t convert %s:%@ to mbgl::Value", [value objCType], value];
}
return { };