1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
|
#import "MGLStyleAttributeFunction.h"
#include <mbgl/util/color.hpp>
#include <mbgl/style/function.hpp>
#include <mbgl/style/property_value.hpp>
#define MGLSetEnumProperty(name, Name, MBGLType, ObjCType) \
if (name.isFunction) { \
NSAssert([name isKindOfClass:[MGLStyleAttributeFunction class]], @"" #name @" should be a function"); \
\
__block std::vector<std::pair<float, mbgl::style::MBGLType>> stops; \
[[(MGLStyleAttributeFunction *)name stops] enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull key, NSValue * _Nonnull obj, BOOL * _Nonnull stop) { \
NSAssert([obj isKindOfClass:[NSValue class]], @"Stops in " #name @" should be NSValues"); \
ObjCType value; \
[obj getValue:&value]; \
stops.emplace_back(key.floatValue, static_cast<mbgl::style::MBGLType>(value)); \
}]; \
auto function = mbgl::style::Function<mbgl::style::MBGLType> { \
stops, \
[(MGLStyleAttributeFunction *)name base].floatValue, \
}; \
self.layer->set##Name(function); \
} else { \
NSAssert([name isKindOfClass:[NSValue class]], @"" #name @"should be an NSValue"); \
ObjCType value; \
[(NSValue *)name getValue:&value]; \
self.layer->set##Name({ static_cast<mbgl::style::MBGLType>(value) }); \
}
#define MGLGetEnumProperty(Name, MBGLType, ObjCType) \
const char *type = @encode(ObjCType); \
mbgl::style::PropertyValue<mbgl::style::MBGLType> property = self.layer->get##Name(); \
if (property.isConstant()) { \
return [NSValue value:&property.asConstant() withObjCType:type]; \
} else if (property.isFunction()) { \
return nil; \
} else { \
return nil; \
}
@interface MGLStyleAttributeFunction(Private)
+ (instancetype)functionWithColorPropertyValue:(mbgl::style::Function<mbgl::Color>)property;
+ (instancetype)functionWithNumberPropertyValue:(mbgl::style::Function<float>)property;
+ (instancetype)functionWithBoolPropertyValue:(mbgl::style::Function<bool>)property;
+ (instancetype)functionWithStringPropertyValue:(mbgl::style::Function<std::string>)property;
+ (instancetype)functionWithOffsetPropertyValue:(mbgl::style::Function<std::array<float, 2>>)property;
+ (instancetype)functionWithPaddingPropertyValue:(mbgl::style::Function<std::array<float, 4>>)property;
+ (instancetype)functionWithStringArrayPropertyValue:(mbgl::style::Function<std::vector<std::string>>)property;
+ (instancetype)functionWithNumberArrayPropertyValue:(mbgl::style::Function<std::vector<float>>)property;
+ (instancetype)functionWithEnumProperyValue:(mbgl::style::Function<bool>)property type:(const char *)type;
@end;
|