diff options
author | Minh Nguyễn <mxn@1ec5.org> | 2017-01-02 15:54:17 -0800 |
---|---|---|
committer | Minh Nguyễn <mxn@1ec5.org> | 2017-01-07 14:37:53 -0800 |
commit | 80df3090ecc92a4c04890222928f352aaf467b27 (patch) | |
tree | 2963df50f43edc3e09a75c1df868b2f8bf3d69ae /platform/darwin | |
parent | 428c0fdf70d08dfe433058a66a61bf9c4fb93d9d (diff) | |
download | qtlocation-mapboxgl-80df3090ecc92a4c04890222928f352aaf467b27.tar.gz |
[ios, macos] Split NSValue+MGLStyleEnumAttributeAdditions category per style layer type
Also renamed the file to have a slightly more wieldy name.
Diffstat (limited to 'platform/darwin')
-rw-r--r-- | platform/darwin/docs/guides/For Style Authors.md.ejs | 6 | ||||
-rw-r--r-- | platform/darwin/scripts/generate-style-code.js | 62 | ||||
-rw-r--r-- | platform/darwin/src/MGLStyleValue_Private.h | 1 | ||||
-rw-r--r-- | platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs | 66 | ||||
-rw-r--r-- | platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs | 46 | ||||
-rw-r--r-- | platform/darwin/src/NSValue+MGLStyleLayerAdditions.h (renamed from platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h) | 247 | ||||
-rw-r--r-- | platform/darwin/src/NSValue+MGLStyleLayerAdditions.h.ejs | 44 | ||||
-rw-r--r-- | platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm (renamed from platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm) | 174 | ||||
-rw-r--r-- | platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm.ejs | 28 |
9 files changed, 335 insertions, 339 deletions
diff --git a/platform/darwin/docs/guides/For Style Authors.md.ejs b/platform/darwin/docs/guides/For Style Authors.md.ejs index cbe38ff6ba..4ead778c03 100644 --- a/platform/darwin/docs/guides/For Style Authors.md.ejs +++ b/platform/darwin/docs/guides/For Style Authors.md.ejs @@ -3,7 +3,7 @@ const iOS = os === 'iOS'; const macOS = os === 'macOS'; const cocoaPrefix = iOS ? 'UI' : 'NS'; - const types = locals.types; + const layers = locals.layers; const renamedProperties = locals.renamedProperties; -%> <!-- @@ -227,8 +227,8 @@ object is a member of one of the following subclasses of `MGLStyleLayer`: In style JSON | In the SDK --------------|----------- -<% for (const type of types) { -%> -`<%- type %>` | `MGL<%- camelize(type) %>StyleLayer` +<% for (const layer of layers) { -%> +`<%- layer.type %>` | `MGL<%- camelize(layer.type) %>StyleLayer` <% } -%> You configure layout and paint attributes by setting properties on these style diff --git a/platform/darwin/scripts/generate-style-code.js b/platform/darwin/scripts/generate-style-code.js index a656b48dd3..98ee1a83f7 100644 --- a/platform/darwin/scripts/generate-style-code.js +++ b/platform/darwin/scripts/generate-style-code.js @@ -368,32 +368,32 @@ global.mbglType = function(property) { const layerH = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.h.ejs', 'utf8'), { strict: true }); const layerM = ejs.compile(fs.readFileSync('platform/darwin/src/MGLStyleLayer.mm.ejs', 'utf8'), { strict: true}); const testLayers = ejs.compile(fs.readFileSync('platform/darwin/test/MGLStyleLayerTests.m.ejs', 'utf8'), { strict: true}); -const categoryH = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs', 'utf8'), { strict: true}); -const categoryM = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs', 'utf8'), { strict: true}); +const categoryH = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleLayerAdditions.h.ejs', 'utf8'), { strict: true}); +const categoryM = ejs.compile(fs.readFileSync('platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm.ejs', 'utf8'), { strict: true}); const guideMD = ejs.compile(fs.readFileSync('platform/darwin/docs/guides/For Style Authors.md.ejs', 'utf8'), { strict: true }); -const layers = Object.keys(spec.layer.type.values).map((type) => { - const layoutProperties = Object.keys(spec[`layout_${type}`]).reduce((memo, name) => { +const layers = _(spec.layer.type.values).map((value, layerType) => { + const layoutProperties = Object.keys(spec[`layout_${layerType}`]).reduce((memo, name) => { if (name !== 'visibility') { - spec[`layout_${type}`][name].name = name; - memo.push(spec[`layout_${type}`][name]); + spec[`layout_${layerType}`][name].name = name; + memo.push(spec[`layout_${layerType}`][name]); } return memo; }, []); - const paintProperties = Object.keys(spec[`paint_${type}`]).reduce((memo, name) => { - spec[`paint_${type}`][name].name = name; - memo.push(spec[`paint_${type}`][name]); + const paintProperties = Object.keys(spec[`paint_${layerType}`]).reduce((memo, name) => { + spec[`paint_${layerType}`][name].name = name; + memo.push(spec[`paint_${layerType}`][name]); return memo; }, []); return { - doc: spec.layer.type.values[type].doc, - type: type, + doc: spec.layer.type.values[layerType].doc, + type: layerType, layoutProperties: _.sortBy(layoutProperties, ['name']), paintProperties: _.sortBy(paintProperties, ['name']), }; -}); +}).sortBy(['type']).value(); function duplicatePlatformDecls(src) { // Look for a documentation comment that contains “MGLColor” and the @@ -414,22 +414,21 @@ ${macosComment}${decl} }); } -var allLayoutProperties = []; -var allPaintProperties = []; -var allTypes = []; -var allRenamedProperties = {}; +let enumPropertiesByLayerType = {}; +var renamedPropertiesByLayerType = {}; -for (let layer of layers) { - allLayoutProperties.push(layer.layoutProperties); - allPaintProperties.push(layer.paintProperties); - allTypes.push(layer.type); +for (var layer of layers) { let properties = _.concat(layer.layoutProperties, layer.paintProperties); - layer.containsEnumerationProperties = _.some(properties, prop => prop.type === "enum"); + let enumProperties = _.filter(properties, prop => prop.type === 'enum'); + if (enumProperties.length) { + enumPropertiesByLayerType[layer.type] = enumProperties; + layer.containsEnumerationProperties = true; + } let renamedProperties = {}; _.assign(renamedProperties, _.filter(properties, prop => 'original' in prop || 'getter' in prop)); if (!_.isEmpty(renamedProperties)) { - allRenamedProperties[layer.type] = renamedProperties; + renamedPropertiesByLayerType[layer.type] = renamedProperties; } fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer))); @@ -437,23 +436,20 @@ for (let layer of layers) { fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer)); } -fs.writeFileSync(`platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h`, categoryH({ - layoutProperties: _.flatten(allLayoutProperties), - paintProperties: _.flatten(allPaintProperties), - types: allTypes +fs.writeFileSync(`platform/darwin/src/NSValue+MGLStyleLayerAdditions.h`, categoryH({ + enumPropertiesByLayerType: enumPropertiesByLayerType, })); -fs.writeFileSync(`platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm`, categoryM({ - layoutProperties: _.flatten(allLayoutProperties), - paintProperties: _.flatten(allPaintProperties) +fs.writeFileSync(`platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm`, categoryM({ + enumPropertiesByLayerType: enumPropertiesByLayerType, })); fs.writeFileSync(`platform/ios/docs/guides/For Style Authors.md`, guideMD({ os: 'iOS', - renamedProperties: allRenamedProperties, - types: allTypes, + renamedProperties: renamedPropertiesByLayerType, + layers: layers, })); fs.writeFileSync(`platform/macos/docs/guides/For Style Authors.md`, guideMD({ os: 'macOS', - renamedProperties: allRenamedProperties, - types: allTypes, + renamedProperties: renamedPropertiesByLayerType, + layers: layers, })); diff --git a/platform/darwin/src/MGLStyleValue_Private.h b/platform/darwin/src/MGLStyleValue_Private.h index e35c0d8008..2c3de3fb74 100644 --- a/platform/darwin/src/MGLStyleValue_Private.h +++ b/platform/darwin/src/MGLStyleValue_Private.h @@ -4,7 +4,6 @@ #import "NSValue+MGLStyleAttributeAdditions.h" #import "MGLTypes.h" -#import "MGLLineStyleLayer.h" #import <mbgl/util/enum.hpp> #if TARGET_OS_IPHONE diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs deleted file mode 100644 index c078ac7d02..0000000000 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h.ejs +++ /dev/null @@ -1,66 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. - -<% -const types = locals.types; -const layoutProperties = locals.layoutProperties; -const paintProperties = locals.paintProperties; --%> -#import <Foundation/Foundation.h> - -<% if (types) { -%> -<% for (const type of types) { -%> -#import "MGL<%- camelize(type) %>StyleLayer.h" -<% } -%> -<% } -%> - -NS_ASSUME_NONNULL_BEGIN - -/** - Methods for round-tripping values for Mapbox style layer enumeration values. -*/ -@interface NSValue (MGLStyleEnumAttributeAdditions) - -#pragma mark Working with Style Layer Enumeration Attribute Values - -<% if (layoutProperties.length) { -%> -<% for (const property of layoutProperties) { -%> -<% if (property.type == "enum") { -%> -/** - Creates a new value object containing the given `MGL<%- camelize(property.name) %>` enumeration. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>; - -/** - The `MGL<%- camelize(property.name) %>` enumeration representation of the value. -*/ -@property (readonly) MGL<%- camelize(property.name) %> MGL<%- camelize(property.name) %>Value; - -<% } -%> -<% } -%> -<% } -%> -<% if (paintProperties.length) { -%> -<% for (const property of paintProperties) { -%> -<% if (property.type == "enum") { -%> -/** - Creates a new value object containing the given `MGL<%- camelize(property.name) %>` structure. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>; - -/** - The `MGL<%- camelize(property.name) %>` enumeration representation of the value. -*/ -@property (readonly) MGL<%- camelize(property.name) %> MGL<%- camelize(property.name) %>Value; - -<% } -%> -<% } -%> -<% } -%> -@end - -NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs b/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs deleted file mode 100644 index fab278aac8..0000000000 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm.ejs +++ /dev/null @@ -1,46 +0,0 @@ -// This file is generated. -// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -<% -const type = locals.type; -const layoutProperties = locals.layoutProperties; -const paintProperties = locals.paintProperties; --%> - -#import "NSValue+MGLStyleEnumAttributeAdditions.h" - -@implementation NSValue (MGLStyleEnumAttributeAdditions) - -<% if (layoutProperties.length) { -%> -<% for (const property of layoutProperties) { -%> -<% if (property.type == "enum") { -%> -+ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> { - return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; -} - -- (MGL<%- camelize(property.name) %>)MGL<%- camelize(property.name) %>Value { - MGL<%- camelize(property.name) %> value; - [self getValue:&value]; - return value; -} - -<% } -%> -<% } -%> -<% } -%> -<% if (paintProperties.length) { -%> -<% for (const property of paintProperties) { -%> -<% if (property.type == "enum") { -%> -+ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> { -return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; -} - -- (MGL<%- camelize(property.name) %>)MGL<%- camelize(property.name) %>Value { - MGL<%- camelize(property.name) %> value; - [self getValue:&value]; - return value; -} - -<% } -%> -<% } -%> -<% } -%> - -@end diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.h index 3387ce8188..92fda42d76 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.h +++ b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.h @@ -3,230 +3,259 @@ #import <Foundation/Foundation.h> +#import "MGLCircleStyleLayer.h" #import "MGLFillStyleLayer.h" #import "MGLLineStyleLayer.h" #import "MGLSymbolStyleLayer.h" -#import "MGLCircleStyleLayer.h" -#import "MGLRasterStyleLayer.h" -#import "MGLBackgroundStyleLayer.h" NS_ASSUME_NONNULL_BEGIN /** - Methods for round-tripping values for Mapbox style layer enumeration values. -*/ -@interface NSValue (MGLStyleEnumAttributeAdditions) + Methods for wrapping an enumeration value for a style layer attribute in an + `MGLCircleStyleLayer` object and unwrapping its raw value. + */ +@interface NSValue (MGLCircleStyleLayerAdditions) + +#pragma mark Working with Circle Style Layer Attribute Values + +/** + Creates a new value object containing the given `MGLCirclePitchScale` enumeration. -#pragma mark Working with Style Layer Enumeration Attribute Values + @param circlePitchScale The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale; + +/** + The `MGLCirclePitchScale` enumeration representation of the value. + */ +@property (readonly) MGLCirclePitchScale MGLCirclePitchScaleValue; + +/** + Creates a new value object containing the given `MGLCircleTranslateAnchor` enumeration. + + @param circleTranslateAnchor The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor; + +/** + The `MGLCircleTranslateAnchor` enumeration representation of the value. + */ +@property (readonly) MGLCircleTranslateAnchor MGLCircleTranslateAnchorValue; + +@end + +/** + Methods for wrapping an enumeration value for a style layer attribute in an + `MGLFillStyleLayer` object and unwrapping its raw value. + */ +@interface NSValue (MGLFillStyleLayerAdditions) + +#pragma mark Working with Fill Style Layer Attribute Values + +/** + Creates a new value object containing the given `MGLFillTranslateAnchor` enumeration. + + @param fillTranslateAnchor The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor; + +/** + The `MGLFillTranslateAnchor` enumeration representation of the value. + */ +@property (readonly) MGLFillTranslateAnchor MGLFillTranslateAnchorValue; + +@end + +/** + Methods for wrapping an enumeration value for a style layer attribute in an + `MGLLineStyleLayer` object and unwrapping its raw value. + */ +@interface NSValue (MGLLineStyleLayerAdditions) + +#pragma mark Working with Line Style Layer Attribute Values /** Creates a new value object containing the given `MGLLineCap` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param lineCap The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLLineCap:(MGLLineCap)lineCap; /** The `MGLLineCap` enumeration representation of the value. -*/ + */ @property (readonly) MGLLineCap MGLLineCapValue; /** Creates a new value object containing the given `MGLLineJoin` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param lineJoin The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLLineJoin:(MGLLineJoin)lineJoin; /** The `MGLLineJoin` enumeration representation of the value. -*/ + */ @property (readonly) MGLLineJoin MGLLineJoinValue; /** + Creates a new value object containing the given `MGLLineTranslateAnchor` enumeration. + + @param lineTranslateAnchor The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor; + +/** + The `MGLLineTranslateAnchor` enumeration representation of the value. + */ +@property (readonly) MGLLineTranslateAnchor MGLLineTranslateAnchorValue; + +@end + +/** + Methods for wrapping an enumeration value for a style layer attribute in an + `MGLSymbolStyleLayer` object and unwrapping its raw value. + */ +@interface NSValue (MGLSymbolStyleLayerAdditions) + +#pragma mark Working with Symbol Style Layer Attribute Values + +/** Creates a new value object containing the given `MGLIconRotationAlignment` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param iconRotationAlignment The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)iconRotationAlignment; /** The `MGLIconRotationAlignment` enumeration representation of the value. -*/ + */ @property (readonly) MGLIconRotationAlignment MGLIconRotationAlignmentValue; /** Creates a new value object containing the given `MGLIconTextFit` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param iconTextFit The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLIconTextFit:(MGLIconTextFit)iconTextFit; /** The `MGLIconTextFit` enumeration representation of the value. -*/ + */ @property (readonly) MGLIconTextFit MGLIconTextFitValue; /** Creates a new value object containing the given `MGLSymbolPlacement` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param symbolPlacement The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement; /** The `MGLSymbolPlacement` enumeration representation of the value. -*/ + */ @property (readonly) MGLSymbolPlacement MGLSymbolPlacementValue; /** Creates a new value object containing the given `MGLTextAnchor` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param textAnchor The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor; /** The `MGLTextAnchor` enumeration representation of the value. -*/ + */ @property (readonly) MGLTextAnchor MGLTextAnchorValue; /** Creates a new value object containing the given `MGLTextJustification` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param textJustification The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLTextJustification:(MGLTextJustification)textJustification; /** The `MGLTextJustification` enumeration representation of the value. -*/ + */ @property (readonly) MGLTextJustification MGLTextJustificationValue; /** Creates a new value object containing the given `MGLTextPitchAlignment` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param textPitchAlignment The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)textPitchAlignment; /** The `MGLTextPitchAlignment` enumeration representation of the value. -*/ + */ @property (readonly) MGLTextPitchAlignment MGLTextPitchAlignmentValue; /** Creates a new value object containing the given `MGLTextRotationAlignment` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param textRotationAlignment The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)textRotationAlignment; /** The `MGLTextRotationAlignment` enumeration representation of the value. -*/ + */ @property (readonly) MGLTextRotationAlignment MGLTextRotationAlignmentValue; /** Creates a new value object containing the given `MGLTextTransform` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param textTransform The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLTextTransform:(MGLTextTransform)textTransform; /** The `MGLTextTransform` enumeration representation of the value. -*/ + */ @property (readonly) MGLTextTransform MGLTextTransformValue; /** - Creates a new value object containing the given `MGLFillTranslateAnchor` structure. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor; - -/** - The `MGLFillTranslateAnchor` enumeration representation of the value. -*/ -@property (readonly) MGLFillTranslateAnchor MGLFillTranslateAnchorValue; - -/** - Creates a new value object containing the given `MGLLineTranslateAnchor` structure. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor; - -/** - The `MGLLineTranslateAnchor` enumeration representation of the value. -*/ -@property (readonly) MGLLineTranslateAnchor MGLLineTranslateAnchorValue; + Creates a new value object containing the given `MGLIconTranslateAnchor` enumeration. -/** - Creates a new value object containing the given `MGLIconTranslateAnchor` structure. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param iconTranslateAnchor The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)iconTranslateAnchor; /** The `MGLIconTranslateAnchor` enumeration representation of the value. -*/ + */ @property (readonly) MGLIconTranslateAnchor MGLIconTranslateAnchorValue; /** - Creates a new value object containing the given `MGLTextTranslateAnchor` structure. + Creates a new value object containing the given `MGLTextTranslateAnchor` enumeration. - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ + @param textTranslateAnchor The value for the new object. + @return A new value object that contains the enumeration value. + */ + (instancetype)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)textTranslateAnchor; /** The `MGLTextTranslateAnchor` enumeration representation of the value. -*/ + */ @property (readonly) MGLTextTranslateAnchor MGLTextTranslateAnchorValue; -/** - Creates a new value object containing the given `MGLCirclePitchScale` structure. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale; - -/** - The `MGLCirclePitchScale` enumeration representation of the value. -*/ -@property (readonly) MGLCirclePitchScale MGLCirclePitchScaleValue; - -/** - Creates a new value object containing the given `MGLCircleTranslateAnchor` structure. - - @param type The value for the new object. - @return A new value object that contains the style enumeration type. -*/ -+ (instancetype)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor; - -/** - The `MGLCircleTranslateAnchor` enumeration representation of the value. -*/ -@property (readonly) MGLCircleTranslateAnchor MGLCircleTranslateAnchorValue; - @end NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSValue+MGLStyleLayerAdditions.h.ejs b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.h.ejs new file mode 100644 index 0000000000..d998e232ec --- /dev/null +++ b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.h.ejs @@ -0,0 +1,44 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. +<% +const enumPropertiesByLayerType = locals.enumPropertiesByLayerType; +-%> + +#import <Foundation/Foundation.h> + +<% for (let layerType of Object.getOwnPropertyNames(enumPropertiesByLayerType)) { -%> +#import "MGL<%- camelize(layerType) %>StyleLayer.h" +<% } -%> + +NS_ASSUME_NONNULL_BEGIN + +<% for (let layerType in enumPropertiesByLayerType) { -%> +<% if (enumPropertiesByLayerType.hasOwnProperty(layerType)) { -%> +/** + Methods for wrapping an enumeration value for a style layer attribute in an + `MGL<%- camelize(layerType) %>StyleLayer` object and unwrapping its raw value. + */ +@interface NSValue (MGL<%- camelize(layerType) %>StyleLayerAdditions) + +#pragma mark Working with <%- camelize(layerType) %> Style Layer Attribute Values + +<% for (let property of enumPropertiesByLayerType[layerType]) { -%> +/** + Creates a new value object containing the given `MGL<%- camelize(property.name) %>` enumeration. + + @param <%- objCName(property) %> The value for the new object. + @return A new value object that contains the enumeration value. + */ ++ (instancetype)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %>; + +/** + The `MGL<%- camelize(property.name) %>` enumeration representation of the value. + */ +@property (readonly) MGL<%- camelize(property.name) %> MGL<%- camelize(property.name) %>Value; + +<% } -%> +@end + +<% } -%> +<% } -%> +NS_ASSUME_NONNULL_END diff --git a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm index db91408c5a..efa3a01215 100644 --- a/platform/darwin/src/NSValue+MGLStyleEnumAttributeAdditions.mm +++ b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm @@ -1,18 +1,56 @@ // This file is generated. // Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. -#import "NSValue+MGLStyleEnumAttributeAdditions.h" +#import "NSValue+MGLStyleLayerAdditions.h" -@implementation NSValue (MGLStyleEnumAttributeAdditions) +@implementation NSValue (MGLCircleStyleLayerAdditions) + ++ (NSValue *)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale { + return [NSValue value:&circlePitchScale withObjCType:@encode(MGLCirclePitchScale)]; +} + +- (MGLCirclePitchScale)MGLCirclePitchScaleValue { + MGLCirclePitchScale circlePitchScale; + [self getValue:&circlePitchScale]; + return circlePitchScale; +} + ++ (NSValue *)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor { + return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTranslateAnchor)]; +} + +- (MGLCircleTranslateAnchor)MGLCircleTranslateAnchorValue { + MGLCircleTranslateAnchor circleTranslateAnchor; + [self getValue:&circleTranslateAnchor]; + return circleTranslateAnchor; +} + +@end + +@implementation NSValue (MGLFillStyleLayerAdditions) + ++ (NSValue *)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor { + return [NSValue value:&fillTranslateAnchor withObjCType:@encode(MGLFillTranslateAnchor)]; +} + +- (MGLFillTranslateAnchor)MGLFillTranslateAnchorValue { + MGLFillTranslateAnchor fillTranslateAnchor; + [self getValue:&fillTranslateAnchor]; + return fillTranslateAnchor; +} + +@end + +@implementation NSValue (MGLLineStyleLayerAdditions) + (NSValue *)valueWithMGLLineCap:(MGLLineCap)lineCap { return [NSValue value:&lineCap withObjCType:@encode(MGLLineCap)]; } - (MGLLineCap)MGLLineCapValue { - MGLLineCap value; - [self getValue:&value]; - return value; + MGLLineCap lineCap; + [self getValue:&lineCap]; + return lineCap; } + (NSValue *)valueWithMGLLineJoin:(MGLLineJoin)lineJoin { @@ -20,19 +58,33 @@ } - (MGLLineJoin)MGLLineJoinValue { - MGLLineJoin value; - [self getValue:&value]; - return value; + MGLLineJoin lineJoin; + [self getValue:&lineJoin]; + return lineJoin; +} + ++ (NSValue *)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor { + return [NSValue value:&lineTranslateAnchor withObjCType:@encode(MGLLineTranslateAnchor)]; +} + +- (MGLLineTranslateAnchor)MGLLineTranslateAnchorValue { + MGLLineTranslateAnchor lineTranslateAnchor; + [self getValue:&lineTranslateAnchor]; + return lineTranslateAnchor; } +@end + +@implementation NSValue (MGLSymbolStyleLayerAdditions) + + (NSValue *)valueWithMGLIconRotationAlignment:(MGLIconRotationAlignment)iconRotationAlignment { return [NSValue value:&iconRotationAlignment withObjCType:@encode(MGLIconRotationAlignment)]; } - (MGLIconRotationAlignment)MGLIconRotationAlignmentValue { - MGLIconRotationAlignment value; - [self getValue:&value]; - return value; + MGLIconRotationAlignment iconRotationAlignment; + [self getValue:&iconRotationAlignment]; + return iconRotationAlignment; } + (NSValue *)valueWithMGLIconTextFit:(MGLIconTextFit)iconTextFit { @@ -40,9 +92,9 @@ } - (MGLIconTextFit)MGLIconTextFitValue { - MGLIconTextFit value; - [self getValue:&value]; - return value; + MGLIconTextFit iconTextFit; + [self getValue:&iconTextFit]; + return iconTextFit; } + (NSValue *)valueWithMGLSymbolPlacement:(MGLSymbolPlacement)symbolPlacement { @@ -50,9 +102,9 @@ } - (MGLSymbolPlacement)MGLSymbolPlacementValue { - MGLSymbolPlacement value; - [self getValue:&value]; - return value; + MGLSymbolPlacement symbolPlacement; + [self getValue:&symbolPlacement]; + return symbolPlacement; } + (NSValue *)valueWithMGLTextAnchor:(MGLTextAnchor)textAnchor { @@ -60,9 +112,9 @@ } - (MGLTextAnchor)MGLTextAnchorValue { - MGLTextAnchor value; - [self getValue:&value]; - return value; + MGLTextAnchor textAnchor; + [self getValue:&textAnchor]; + return textAnchor; } + (NSValue *)valueWithMGLTextJustification:(MGLTextJustification)textJustification { @@ -70,9 +122,9 @@ } - (MGLTextJustification)MGLTextJustificationValue { - MGLTextJustification value; - [self getValue:&value]; - return value; + MGLTextJustification textJustification; + [self getValue:&textJustification]; + return textJustification; } + (NSValue *)valueWithMGLTextPitchAlignment:(MGLTextPitchAlignment)textPitchAlignment { @@ -80,9 +132,9 @@ } - (MGLTextPitchAlignment)MGLTextPitchAlignmentValue { - MGLTextPitchAlignment value; - [self getValue:&value]; - return value; + MGLTextPitchAlignment textPitchAlignment; + [self getValue:&textPitchAlignment]; + return textPitchAlignment; } + (NSValue *)valueWithMGLTextRotationAlignment:(MGLTextRotationAlignment)textRotationAlignment { @@ -90,9 +142,9 @@ } - (MGLTextRotationAlignment)MGLTextRotationAlignmentValue { - MGLTextRotationAlignment value; - [self getValue:&value]; - return value; + MGLTextRotationAlignment textRotationAlignment; + [self getValue:&textRotationAlignment]; + return textRotationAlignment; } + (NSValue *)valueWithMGLTextTransform:(MGLTextTransform)textTransform { @@ -100,70 +152,30 @@ } - (MGLTextTransform)MGLTextTransformValue { - MGLTextTransform value; - [self getValue:&value]; - return value; -} - -+ (NSValue *)valueWithMGLFillTranslateAnchor:(MGLFillTranslateAnchor)fillTranslateAnchor { -return [NSValue value:&fillTranslateAnchor withObjCType:@encode(MGLFillTranslateAnchor)]; -} - -- (MGLFillTranslateAnchor)MGLFillTranslateAnchorValue { - MGLFillTranslateAnchor value; - [self getValue:&value]; - return value; -} - -+ (NSValue *)valueWithMGLLineTranslateAnchor:(MGLLineTranslateAnchor)lineTranslateAnchor { -return [NSValue value:&lineTranslateAnchor withObjCType:@encode(MGLLineTranslateAnchor)]; -} - -- (MGLLineTranslateAnchor)MGLLineTranslateAnchorValue { - MGLLineTranslateAnchor value; - [self getValue:&value]; - return value; + MGLTextTransform textTransform; + [self getValue:&textTransform]; + return textTransform; } + (NSValue *)valueWithMGLIconTranslateAnchor:(MGLIconTranslateAnchor)iconTranslateAnchor { -return [NSValue value:&iconTranslateAnchor withObjCType:@encode(MGLIconTranslateAnchor)]; + return [NSValue value:&iconTranslateAnchor withObjCType:@encode(MGLIconTranslateAnchor)]; } - (MGLIconTranslateAnchor)MGLIconTranslateAnchorValue { - MGLIconTranslateAnchor value; - [self getValue:&value]; - return value; + MGLIconTranslateAnchor iconTranslateAnchor; + [self getValue:&iconTranslateAnchor]; + return iconTranslateAnchor; } + (NSValue *)valueWithMGLTextTranslateAnchor:(MGLTextTranslateAnchor)textTranslateAnchor { -return [NSValue value:&textTranslateAnchor withObjCType:@encode(MGLTextTranslateAnchor)]; + return [NSValue value:&textTranslateAnchor withObjCType:@encode(MGLTextTranslateAnchor)]; } - (MGLTextTranslateAnchor)MGLTextTranslateAnchorValue { - MGLTextTranslateAnchor value; - [self getValue:&value]; - return value; + MGLTextTranslateAnchor textTranslateAnchor; + [self getValue:&textTranslateAnchor]; + return textTranslateAnchor; } -+ (NSValue *)valueWithMGLCirclePitchScale:(MGLCirclePitchScale)circlePitchScale { -return [NSValue value:&circlePitchScale withObjCType:@encode(MGLCirclePitchScale)]; -} - -- (MGLCirclePitchScale)MGLCirclePitchScaleValue { - MGLCirclePitchScale value; - [self getValue:&value]; - return value; -} - -+ (NSValue *)valueWithMGLCircleTranslateAnchor:(MGLCircleTranslateAnchor)circleTranslateAnchor { -return [NSValue value:&circleTranslateAnchor withObjCType:@encode(MGLCircleTranslateAnchor)]; -} - -- (MGLCircleTranslateAnchor)MGLCircleTranslateAnchorValue { - MGLCircleTranslateAnchor value; - [self getValue:&value]; - return value; -} - - @end + diff --git a/platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm.ejs b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm.ejs new file mode 100644 index 0000000000..758fb66546 --- /dev/null +++ b/platform/darwin/src/NSValue+MGLStyleLayerAdditions.mm.ejs @@ -0,0 +1,28 @@ +// This file is generated. +// Edit platform/darwin/scripts/generate-style-code.js, then run `make style-code-darwin`. +<% +const enumPropertiesByLayerType = locals.enumPropertiesByLayerType; +-%> + +#import "NSValue+MGLStyleLayerAdditions.h" + +<% for (let layerType in enumPropertiesByLayerType) { -%> +<% if (enumPropertiesByLayerType.hasOwnProperty(layerType)) { -%> +@implementation NSValue (MGL<%- camelize(layerType) %>StyleLayerAdditions) + +<% for (let property of enumPropertiesByLayerType[layerType]) { -%> ++ (NSValue *)valueWithMGL<%- camelize(property.name) %>:(MGL<%- camelize(property.name) %>)<%- objCName(property) %> { + return [NSValue value:&<%- objCName(property) %> withObjCType:@encode(MGL<%- camelize(property.name) %>)]; +} + +- (MGL<%- camelize(property.name) %>)MGL<%- camelize(property.name) %>Value { + MGL<%- camelize(property.name) %> <%- objCName(property) %>; + [self getValue:&<%- objCName(property) %>]; + return <%- objCName(property) %>; +} + +<% } -%> +<% } -%> +@end + +<% } -%> |