diff options
author | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-03-27 15:14:55 -0400 |
---|---|---|
committer | Fabian Guerra <fabian.guerra@mapbox.com> | 2018-03-28 19:40:09 -0400 |
commit | 63d7ebba9d319ef2304c16c39a1c75d862d3a4e0 (patch) | |
tree | 5319cc81be555fd87e7ddedc52ac03b80441940c | |
parent | ddc77692f4c3c4dd6f2348d5828934520dd2ad59 (diff) | |
download | qtlocation-mapboxgl-63d7ebba9d319ef2304c16c39a1c75d862d3a4e0.tar.gz |
[ios, macos] Add mgl_coalesce: as expression function.
-rw-r--r-- | platform/darwin/src/NSExpression+MGLAdditions.mm | 19 | ||||
-rw-r--r-- | platform/darwin/src/NSExpression+MGLPrivateAdditions.h | 2 | ||||
-rw-r--r-- | platform/darwin/test/MGLExpressionTests.mm | 2 |
3 files changed, 11 insertions, 12 deletions
diff --git a/platform/darwin/src/NSExpression+MGLAdditions.mm b/platform/darwin/src/NSExpression+MGLAdditions.mm index 23ba0d87fe..2ff0d100f6 100644 --- a/platform/darwin/src/NSExpression+MGLAdditions.mm +++ b/platform/darwin/src/NSExpression+MGLAdditions.mm @@ -60,6 +60,7 @@ INSTALL_METHOD(mgl_join:); INSTALL_METHOD(mgl_interpolate:withCurveType:parameters:stops:); INSTALL_METHOD(mgl_step:from:stops:); + INSTALL_METHOD(mgl_coalesce:); // Install functions that resemble control structures, taking arbitrary // numbers of arguments. Vararg aftermarket functions need to be declared @@ -99,6 +100,12 @@ return nil; } +- (id)mgl_coalesce:(NSArray<NSExpression *> *)elements { + [NSException raise:NSInvalidArgumentException + format:@"Coalesce expressions lack underlying Objective-C implementations."]; + return nil; +} + /** A placeholder for a method that evaluates an expression based on an arbitrary number of variable names and assigned expressions. @@ -399,12 +406,6 @@ return [self valueForKeyPath:@"mgl_jsonExpressionObject"]; } -- (id)mgl_coalesce { - [NSException raise:NSInvalidArgumentException - format:@"Coalesce expressions lack underlying Objective-C implementations."]; - return nil; -} - @end @implementation NSDictionary (MGLExpressionAdditions) @@ -663,7 +664,7 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { [expressions addObject:[NSExpression mgl_expressionWithJSONObject:operand]]; } - return [NSExpression expressionWithFormat:@"FUNCTION(%@, 'mgl_coalesce')", expressions]; + return [NSExpression expressionWithFormat:@"mgl_coalesce(%@)", expressions]; } else { NSArray *subexpressions = MGLSubexpressionsWithJSONObjects(array); return [NSExpression expressionForFunction:@"MGL_FUNCTION" arguments:subexpressions]; @@ -873,10 +874,10 @@ NSArray *MGLSubexpressionsWithJSONObjects(NSArray *objects) { } return expressionObject; - } else if ([function isEqualToString:@"mgl_coalesce"]) { + } else if ([function isEqualToString:@"mgl_coalesce:"]) { NSMutableArray *expressionObject = [NSMutableArray arrayWithObjects:@"coalesce", nil]; - for (NSExpression *expression in self.operand.constantValue) { + for (NSExpression *expression in self.arguments.firstObject.constantValue) { [expressionObject addObject:[expression mgl_jsonExpressionObject]]; } diff --git a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h index f726dd3e71..d255cfdb0f 100644 --- a/platform/darwin/src/NSExpression+MGLPrivateAdditions.h +++ b/platform/darwin/src/NSExpression+MGLPrivateAdditions.h @@ -54,8 +54,6 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly) id mgl_jsonExpressionObject; -@property (nonatomic, readonly) id mgl_coalesce; - @end @interface NSDictionary (MGLExpressionAdditions) diff --git a/platform/darwin/test/MGLExpressionTests.mm b/platform/darwin/test/MGLExpressionTests.mm index bfb1a2edc5..f00ea690f5 100644 --- a/platform/darwin/test/MGLExpressionTests.mm +++ b/platform/darwin/test/MGLExpressionTests.mm @@ -646,7 +646,7 @@ using namespace std::string_literals; - (void)testCoalesceExpressionObject { { - NSExpression *expression = [NSExpression expressionWithFormat:@"FUNCTION(%@, 'mgl_coalesce')", + NSExpression *expression = [NSExpression expressionWithFormat:@"mgl_coalesce(%@)", @[[NSExpression expressionForKeyPath:@"x"], [NSExpression expressionForKeyPath:@"y"], [NSExpression expressionForKeyPath:@"z"], |