#import "MGLStyleAttributeFunction.h" #include #include #include #define MGLSetEnumProperty(name, Name, MBGLType, ObjCType) \ if (name.isFunction) { \ NSAssert([name isKindOfClass:[MGLStyleAttributeFunction class]], @"" #name @" should be a function"); \ \ __block std::vector> 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(value)); \ }]; \ auto function = mbgl::style::Function { \ 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(value) }); \ } #define MGLGetEnumProperty(Name, MBGLType, ObjCType) \ const char *type = @encode(ObjCType); \ mbgl::style::PropertyValue 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)property; + (instancetype)functionWithNumberPropertyValue:(mbgl::style::Function)property; + (instancetype)functionWithBoolPropertyValue:(mbgl::style::Function)property; + (instancetype)functionWithStringPropertyValue:(mbgl::style::Function)property; + (instancetype)functionWithOffsetPropertyValue:(mbgl::style::Function>)property; + (instancetype)functionWithPaddingPropertyValue:(mbgl::style::Function>)property; + (instancetype)functionWithStringArrayPropertyValue:(mbgl::style::Function>)property; + (instancetype)functionWithNumberArrayPropertyValue:(mbgl::style::Function>)property; + (instancetype)functionWithEnumProperyValue:(mbgl::style::Function)property type:(const char *)type; @end;