Skip to content
This repository has been archived by the owner on Aug 8, 2023. It is now read-only.

Commit

Permalink
Fixes for code review
Browse files Browse the repository at this point in the history
- Fix whitespace and remove unneeded namespace
- Only add MBGL_DEFINE_ENUMs for classes that have enum properties
- Move style value transformer back to MGLStyleValueTransformer
- Move setter in to translator
- Add to umbrella header and make public
- Fix up category typos
- Add enumeration props to category
- Move non null assumption below end
- Add route line example
  • Loading branch information
boundsj committed Nov 22, 2016
1 parent e330840 commit 10ee43b
Show file tree
Hide file tree
Showing 18 changed files with 505 additions and 614 deletions.
3 changes: 3 additions & 0 deletions platform/darwin/scripts/generate-style-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,9 @@ for (var layer of layers) {
allLayoutProperties.push(layer.layoutProperties);
allPaintProperties.push(layer.paintProperties);
allTypes.push(layer.type);
const containsEnumerationProperties = _.filter(layer.layoutProperties, function(property){ return property["type"] === "enum"; }).length || _.filter(layer.paintProperties, function(property){ return property["type"] === "enum"; }).length;
layer.containsEnumerationProperties = containsEnumerationProperties;

fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.h`, duplicatePlatformDecls(layerH(layer)));
fs.writeFileSync(`platform/darwin/src/${prefix}${camelize(layer.type)}${suffix}.mm`, layerM(layer));
fs.writeFileSync(`platform/darwin/test/${prefix}${camelize(layer.type)}${suffix}Tests.m`, testLayers(layer));
Expand Down
8 changes: 0 additions & 8 deletions platform/darwin/src/MGLBackgroundStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

#include <mbgl/style/layers/background_layer.hpp>

namespace mbgl {

using namespace style;


}

@interface MGLBackgroundStyleLayer ()

Expand All @@ -38,8 +32,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier
return self;
}



#pragma mark - Adding to and removing from a map view

- (void)addToMapView:(MGLMapView *)mapView
Expand Down
65 changes: 12 additions & 53 deletions platform/darwin/src/MGLCircleStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,16 @@

namespace mbgl {

using namespace style;


MBGL_DEFINE_ENUM(MGLCircleTranslateAnchor, {
{ MGLCircleTranslateAnchorMap, "map" },
{ MGLCircleTranslateAnchorViewport, "viewport" },
});

MBGL_DEFINE_ENUM(MGLCirclePitchScale, {
{ MGLCirclePitchScaleMap, "map" },
{ MGLCirclePitchScaleViewport, "viewport" },
});

}

@interface MGLCircleStyleLayer ()
Expand All @@ -45,8 +44,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so
}
return self;
}


- (NSString *)sourceLayerIdentifier
{
auto layerID = _rawLayer->getSourceLayer();
Expand All @@ -67,8 +64,6 @@ - (NSPredicate *)predicate
{
return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()];
}


#pragma mark - Adding to and removing from a map view

- (void)addToMapView:(MGLMapView *)mapView
Expand Down Expand Up @@ -146,65 +141,29 @@ - (void)setCircleTranslate:(MGLStyleValue<NSValue *> *)circleTranslate {
}

- (void)setCircleTranslateAnchor:(MGLStyleValue<NSValue *> *)circleTranslateAnchor {
if ([circleTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) {
MGLStyleFunction<NSValue *> *function = (MGLStyleFunction<NSValue *> *)circleTranslateAnchor;
__block std::vector<std::pair<float, mbgl::style::TranslateAnchorType>> mbglStops;
[function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<NSValue *> * _Nonnull stopValue, BOOL * _Nonnull stop) {
id value = [(MGLStyleConstantValue<NSValue *> *)stopValue rawValue];
MGLCircleTranslateAnchor circleTranslateAnchorValue;
[value getValue:&circleTranslateAnchorValue];
auto str = mbgl::Enum<MGLCircleTranslateAnchor>::toString(circleTranslateAnchorValue);
auto mbglValue = mbgl::Enum<mbgl::style::TranslateAnchorType>::toEnum(str).value_or(_rawLayer->getDefaultCircleTranslateAnchor().asConstant());
auto mbglStopValue = mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>(mbglValue);
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
auto func = mbgl::style::Function<mbgl::style::TranslateAnchorType>({{mbglStops}}, function.base);
_rawLayer->setCircleTranslateAnchor(func);
return;
}
id value = [(MGLStyleConstantValue<NSValue *> *)circleTranslateAnchor rawValue];
MGLCircleTranslateAnchor circleTranslateAnchorValue;
[value getValue:&circleTranslateAnchorValue];
auto str = mbgl::Enum<MGLCircleTranslateAnchor>::toString(circleTranslateAnchorValue);
auto mbglValue = mbgl::Enum<mbgl::style::TranslateAnchorType>::toEnum(str).value_or(_rawLayer->getDefaultCircleTranslateAnchor().asConstant());
auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType,
NSValue *,
mbgl::style::TranslateAnchorType,
MGLCircleTranslateAnchor>().toEnumPropertyValue(circleTranslateAnchor);
_rawLayer->setCircleTranslateAnchor(mbglValue);
}

- (MGLStyleValue<NSValue *> *)circleTranslateAnchor {
auto propertyValue = _rawLayer->getCircleTranslateAnchor() ?: _rawLayer->getDefaultCircleTranslateAnchor();

return MGLStyleEnumerationValueTransformer<mbgl::style::TranslateAnchorType, MGLCircleTranslateAnchor>().propertyValueMGLStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLCircleTranslateAnchor>().toEnumStyleValue(propertyValue);
}

- (void)setCirclePitchScale:(MGLStyleValue<NSValue *> *)circlePitchScale {
if ([circlePitchScale isKindOfClass:[MGLStyleFunction class]]) {
MGLStyleFunction<NSValue *> *function = (MGLStyleFunction<NSValue *> *)circlePitchScale;
__block std::vector<std::pair<float, mbgl::style::CirclePitchScaleType>> mbglStops;
[function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<NSValue *> * _Nonnull stopValue, BOOL * _Nonnull stop) {
id value = [(MGLStyleConstantValue<NSValue *> *)stopValue rawValue];
MGLCirclePitchScale circlePitchScaleValue;
[value getValue:&circlePitchScaleValue];
auto str = mbgl::Enum<MGLCirclePitchScale>::toString(circlePitchScaleValue);
auto mbglValue = mbgl::Enum<mbgl::style::CirclePitchScaleType>::toEnum(str).value_or(_rawLayer->getDefaultCirclePitchScale().asConstant());
auto mbglStopValue = mbgl::style::PropertyValue<mbgl::style::CirclePitchScaleType>(mbglValue);
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
auto func = mbgl::style::Function<mbgl::style::CirclePitchScaleType>({{mbglStops}}, function.base);
_rawLayer->setCirclePitchScale(func);
return;
}
id value = [(MGLStyleConstantValue<NSValue *> *)circlePitchScale rawValue];
MGLCirclePitchScale circlePitchScaleValue;
[value getValue:&circlePitchScaleValue];
auto str = mbgl::Enum<MGLCirclePitchScale>::toString(circlePitchScaleValue);
auto mbglValue = mbgl::Enum<mbgl::style::CirclePitchScaleType>::toEnum(str).value_or(_rawLayer->getDefaultCirclePitchScale().asConstant());
auto mbglValue = MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType,
NSValue *,
mbgl::style::CirclePitchScaleType,
MGLCirclePitchScale>().toEnumPropertyValue(circlePitchScale);
_rawLayer->setCirclePitchScale(mbglValue);
}

- (MGLStyleValue<NSValue *> *)circlePitchScale {
auto propertyValue = _rawLayer->getCirclePitchScale() ?: _rawLayer->getDefaultCirclePitchScale();

return MGLStyleEnumerationValueTransformer<mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().propertyValueMGLStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::CirclePitchScaleType, NSValue *, mbgl::style::CirclePitchScaleType, MGLCirclePitchScale>().toEnumStyleValue(propertyValue);
}


Expand Down
36 changes: 6 additions & 30 deletions platform/darwin/src/MGLFillStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,11 @@

namespace mbgl {

using namespace style;


MBGL_DEFINE_ENUM(MGLFillTranslateAnchor, {
{ MGLFillTranslateAnchorMap, "map" },
{ MGLFillTranslateAnchorViewport, "viewport" },
});

}

@interface MGLFillStyleLayer ()
Expand All @@ -41,8 +39,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so
}
return self;
}


- (NSString *)sourceLayerIdentifier
{
auto layerID = _rawLayer->getSourceLayer();
Expand All @@ -63,8 +59,6 @@ - (NSPredicate *)predicate
{
return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()];
}


#pragma mark - Adding to and removing from a map view

- (void)addToMapView:(MGLMapView *)mapView
Expand Down Expand Up @@ -142,34 +136,16 @@ - (void)setFillTranslate:(MGLStyleValue<NSValue *> *)fillTranslate {
}

- (void)setFillTranslateAnchor:(MGLStyleValue<NSValue *> *)fillTranslateAnchor {
if ([fillTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) {
MGLStyleFunction<NSValue *> *function = (MGLStyleFunction<NSValue *> *)fillTranslateAnchor;
__block std::vector<std::pair<float, mbgl::style::TranslateAnchorType>> mbglStops;
[function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<NSValue *> * _Nonnull stopValue, BOOL * _Nonnull stop) {
id value = [(MGLStyleConstantValue<NSValue *> *)stopValue rawValue];
MGLFillTranslateAnchor fillTranslateAnchorValue;
[value getValue:&fillTranslateAnchorValue];
auto str = mbgl::Enum<MGLFillTranslateAnchor>::toString(fillTranslateAnchorValue);
auto mbglValue = mbgl::Enum<mbgl::style::TranslateAnchorType>::toEnum(str).value_or(_rawLayer->getDefaultFillTranslateAnchor().asConstant());
auto mbglStopValue = mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>(mbglValue);
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
auto func = mbgl::style::Function<mbgl::style::TranslateAnchorType>({{mbglStops}}, function.base);
_rawLayer->setFillTranslateAnchor(func);
return;
}
id value = [(MGLStyleConstantValue<NSValue *> *)fillTranslateAnchor rawValue];
MGLFillTranslateAnchor fillTranslateAnchorValue;
[value getValue:&fillTranslateAnchorValue];
auto str = mbgl::Enum<MGLFillTranslateAnchor>::toString(fillTranslateAnchorValue);
auto mbglValue = mbgl::Enum<mbgl::style::TranslateAnchorType>::toEnum(str).value_or(_rawLayer->getDefaultFillTranslateAnchor().asConstant());
auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType,
NSValue *,
mbgl::style::TranslateAnchorType,
MGLFillTranslateAnchor>().toEnumPropertyValue(fillTranslateAnchor);
_rawLayer->setFillTranslateAnchor(mbglValue);
}

- (MGLStyleValue<NSValue *> *)fillTranslateAnchor {
auto propertyValue = _rawLayer->getFillTranslateAnchor() ?: _rawLayer->getDefaultFillTranslateAnchor();

return MGLStyleEnumerationValueTransformer<mbgl::style::TranslateAnchorType, MGLFillTranslateAnchor>().propertyValueMGLStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLFillTranslateAnchor>().toEnumStyleValue(propertyValue);
}

- (void)setFillPattern:(MGLStyleValue<NSString *> *)fillPattern {
Expand Down
92 changes: 17 additions & 75 deletions platform/darwin/src/MGLLineStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,12 @@

namespace mbgl {

using namespace style;

MBGL_DEFINE_ENUM(MGLLineCap, {
{ MGLLineCapButt, "butt" },
{ MGLLineCapRound, "round" },
{ MGLLineCapSquare, "square" },
});

MBGL_DEFINE_ENUM(MGLLineJoin, {
{ MGLLineJoinBevel, "bevel" },
{ MGLLineJoinRound, "round" },
Expand All @@ -29,6 +28,7 @@
{ MGLLineTranslateAnchorMap, "map" },
{ MGLLineTranslateAnchorViewport, "viewport" },
});

}

@interface MGLLineStyleLayer ()
Expand All @@ -51,8 +51,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so
}
return self;
}


- (NSString *)sourceLayerIdentifier
{
auto layerID = _rawLayer->getSourceLayer();
Expand All @@ -73,8 +71,6 @@ - (NSPredicate *)predicate
{
return [NSPredicate mgl_predicateWithFilter:_rawLayer->getFilter()];
}


#pragma mark - Adding to and removing from a map view

- (void)addToMapView:(MGLMapView *)mapView
Expand Down Expand Up @@ -102,65 +98,29 @@ - (void)removeFromMapView:(MGLMapView *)mapView
#pragma mark - Accessing the Layout Attributes

- (void)setLineCap:(MGLStyleValue<NSValue *> *)lineCap {
if ([lineCap isKindOfClass:[MGLStyleFunction class]]) {
MGLStyleFunction<NSValue *> *function = (MGLStyleFunction<NSValue *> *)lineCap;
__block std::vector<std::pair<float, mbgl::style::LineCapType>> mbglStops;
[function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<NSValue *> * _Nonnull stopValue, BOOL * _Nonnull stop) {
id value = [(MGLStyleConstantValue<NSValue *> *)stopValue rawValue];
MGLLineCap lineCapValue;
[value getValue:&lineCapValue];
auto str = mbgl::Enum<MGLLineCap>::toString(lineCapValue);
auto mbglValue = mbgl::Enum<mbgl::style::LineCapType>::toEnum(str).value_or(_rawLayer->getDefaultLineCap().asConstant());
auto mbglStopValue = mbgl::style::PropertyValue<mbgl::style::LineCapType>(mbglValue);
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
auto func = mbgl::style::Function<mbgl::style::LineCapType>({{mbglStops}}, function.base);
_rawLayer->setLineCap(func);
return;
}
id value = [(MGLStyleConstantValue<NSValue *> *)lineCap rawValue];
MGLLineCap lineCapValue;
[value getValue:&lineCapValue];
auto str = mbgl::Enum<MGLLineCap>::toString(lineCapValue);
auto mbglValue = mbgl::Enum<mbgl::style::LineCapType>::toEnum(str).value_or(_rawLayer->getDefaultLineCap().asConstant());
auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineCapType,
NSValue *,
mbgl::style::LineCapType,
MGLLineCap>().toEnumPropertyValue(lineCap);
_rawLayer->setLineCap(mbglValue);
}

- (MGLStyleValue<NSValue *> *)lineCap {
auto propertyValue = _rawLayer->getLineCap() ?: _rawLayer->getDefaultLineCap();

return MGLStyleEnumerationValueTransformer<mbgl::style::LineCapType, MGLLineCap>().propertyValueMGLStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::LineCapType, NSValue *, mbgl::style::LineCapType, MGLLineCap>().toEnumStyleValue(propertyValue);
}

- (void)setLineJoin:(MGLStyleValue<NSValue *> *)lineJoin {
if ([lineJoin isKindOfClass:[MGLStyleFunction class]]) {
MGLStyleFunction<NSValue *> *function = (MGLStyleFunction<NSValue *> *)lineJoin;
__block std::vector<std::pair<float, mbgl::style::LineJoinType>> mbglStops;
[function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<NSValue *> * _Nonnull stopValue, BOOL * _Nonnull stop) {
id value = [(MGLStyleConstantValue<NSValue *> *)stopValue rawValue];
MGLLineJoin lineJoinValue;
[value getValue:&lineJoinValue];
auto str = mbgl::Enum<MGLLineJoin>::toString(lineJoinValue);
auto mbglValue = mbgl::Enum<mbgl::style::LineJoinType>::toEnum(str).value_or(_rawLayer->getDefaultLineJoin().asConstant());
auto mbglStopValue = mbgl::style::PropertyValue<mbgl::style::LineJoinType>(mbglValue);
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
auto func = mbgl::style::Function<mbgl::style::LineJoinType>({{mbglStops}}, function.base);
_rawLayer->setLineJoin(func);
return;
}
id value = [(MGLStyleConstantValue<NSValue *> *)lineJoin rawValue];
MGLLineJoin lineJoinValue;
[value getValue:&lineJoinValue];
auto str = mbgl::Enum<MGLLineJoin>::toString(lineJoinValue);
auto mbglValue = mbgl::Enum<mbgl::style::LineJoinType>::toEnum(str).value_or(_rawLayer->getDefaultLineJoin().asConstant());
auto mbglValue = MGLStyleValueTransformer<mbgl::style::LineJoinType,
NSValue *,
mbgl::style::LineJoinType,
MGLLineJoin>().toEnumPropertyValue(lineJoin);
_rawLayer->setLineJoin(mbglValue);
}

- (MGLStyleValue<NSValue *> *)lineJoin {
auto propertyValue = _rawLayer->getLineJoin() ?: _rawLayer->getDefaultLineJoin();

return MGLStyleEnumerationValueTransformer<mbgl::style::LineJoinType, MGLLineJoin>().propertyValueMGLStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::LineJoinType, NSValue *, mbgl::style::LineJoinType, MGLLineJoin>().toEnumStyleValue(propertyValue);
}

- (void)setLineMiterLimit:(MGLStyleValue<NSNumber *> *)lineMiterLimit {
Expand Down Expand Up @@ -216,34 +176,16 @@ - (void)setLineTranslate:(MGLStyleValue<NSValue *> *)lineTranslate {
}

- (void)setLineTranslateAnchor:(MGLStyleValue<NSValue *> *)lineTranslateAnchor {
if ([lineTranslateAnchor isKindOfClass:[MGLStyleFunction class]]) {
MGLStyleFunction<NSValue *> *function = (MGLStyleFunction<NSValue *> *)lineTranslateAnchor;
__block std::vector<std::pair<float, mbgl::style::TranslateAnchorType>> mbglStops;
[function.stops enumerateKeysAndObjectsUsingBlock:^(NSNumber * _Nonnull zoomKey, MGLStyleValue<NSValue *> * _Nonnull stopValue, BOOL * _Nonnull stop) {
id value = [(MGLStyleConstantValue<NSValue *> *)stopValue rawValue];
MGLLineTranslateAnchor lineTranslateAnchorValue;
[value getValue:&lineTranslateAnchorValue];
auto str = mbgl::Enum<MGLLineTranslateAnchor>::toString(lineTranslateAnchorValue);
auto mbglValue = mbgl::Enum<mbgl::style::TranslateAnchorType>::toEnum(str).value_or(_rawLayer->getDefaultLineTranslateAnchor().asConstant());
auto mbglStopValue = mbgl::style::PropertyValue<mbgl::style::TranslateAnchorType>(mbglValue);
mbglStops.emplace_back(zoomKey.floatValue, mbglStopValue.asConstant());
}];
auto func = mbgl::style::Function<mbgl::style::TranslateAnchorType>({{mbglStops}}, function.base);
_rawLayer->setLineTranslateAnchor(func);
return;
}
id value = [(MGLStyleConstantValue<NSValue *> *)lineTranslateAnchor rawValue];
MGLLineTranslateAnchor lineTranslateAnchorValue;
[value getValue:&lineTranslateAnchorValue];
auto str = mbgl::Enum<MGLLineTranslateAnchor>::toString(lineTranslateAnchorValue);
auto mbglValue = mbgl::Enum<mbgl::style::TranslateAnchorType>::toEnum(str).value_or(_rawLayer->getDefaultLineTranslateAnchor().asConstant());
auto mbglValue = MGLStyleValueTransformer<mbgl::style::TranslateAnchorType,
NSValue *,
mbgl::style::TranslateAnchorType,
MGLLineTranslateAnchor>().toEnumPropertyValue(lineTranslateAnchor);
_rawLayer->setLineTranslateAnchor(mbglValue);
}

- (MGLStyleValue<NSValue *> *)lineTranslateAnchor {
auto propertyValue = _rawLayer->getLineTranslateAnchor() ?: _rawLayer->getDefaultLineTranslateAnchor();

return MGLStyleEnumerationValueTransformer<mbgl::style::TranslateAnchorType, MGLLineTranslateAnchor>().propertyValueMGLStyleValue(propertyValue);
return MGLStyleValueTransformer<mbgl::style::TranslateAnchorType, NSValue *, mbgl::style::TranslateAnchorType, MGLLineTranslateAnchor>().toEnumStyleValue(propertyValue);
}

- (void)setLineWidth:(MGLStyleValue<NSNumber *> *)lineWidth {
Expand Down
9 changes: 0 additions & 9 deletions platform/darwin/src/MGLRasterStyleLayer.mm
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@

#include <mbgl/style/layers/raster_layer.hpp>

namespace mbgl {

using namespace style;


}

@interface MGLRasterStyleLayer ()

Expand All @@ -37,9 +31,6 @@ - (instancetype)initWithIdentifier:(NSString *)identifier source:(MGLSource *)so
}
return self;
}



#pragma mark - Adding to and removing from a map view

- (void)addToMapView:(MGLMapView *)mapView
Expand Down
Loading

0 comments on commit 10ee43b

Please sign in to comment.