From d4d12fb8a51decc11342ace1015161ca304048d0 Mon Sep 17 00:00:00 2001 From: Mikhail Pozdnyakov Date: Wed, 19 Dec 2018 16:15:20 +0200 Subject: [core] Use eternal::hash_map in style::Layers --- src/mbgl/style/layers/background_layer.cpp | 70 +--- src/mbgl/style/layers/circle_layer.cpp | 166 ++------- src/mbgl/style/layers/fill_extrusion_layer.cpp | 130 ++----- src/mbgl/style/layers/fill_layer.cpp | 118 ++----- src/mbgl/style/layers/heatmap_layer.cpp | 94 ++--- src/mbgl/style/layers/hillshade_layer.cpp | 106 ++---- src/mbgl/style/layers/layer.cpp.ejs | 54 ++- src/mbgl/style/layers/line_layer.cpp | 195 +++-------- src/mbgl/style/layers/raster_layer.cpp | 130 ++----- src/mbgl/style/layers/symbol_layer.cpp | 462 +++++-------------------- 10 files changed, 311 insertions(+), 1214 deletions(-) diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index eb3c7a2666..89b367b632 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -145,8 +146,7 @@ TransitionOptions BackgroundLayer::getBackgroundOpacityTransition() const { using namespace conversion; optional BackgroundLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { BackgroundColor, BackgroundPattern, BackgroundOpacity, @@ -155,45 +155,22 @@ optional BackgroundLayer::setPaintProperty(const std::string& name, const BackgroundOpacityTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("background-color"): - if (name == "background-color") { - property = Property::BackgroundColor; - } - break; - case util::hashFNV1a("background-color-transition"): - if (name == "background-color-transition") { - property = Property::BackgroundColorTransition; - } - break; - case util::hashFNV1a("background-pattern"): - if (name == "background-pattern") { - property = Property::BackgroundPattern; - } - break; - case util::hashFNV1a("background-pattern-transition"): - if (name == "background-pattern-transition") { - property = Property::BackgroundPatternTransition; - } - break; - case util::hashFNV1a("background-opacity"): - if (name == "background-opacity") { - property = Property::BackgroundOpacity; - } - break; - case util::hashFNV1a("background-opacity-transition"): - if (name == "background-opacity-transition") { - property = Property::BackgroundOpacityTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "background-color", static_cast(Property::BackgroundColor) }, + { "background-pattern", static_cast(Property::BackgroundPattern) }, + { "background-opacity", static_cast(Property::BackgroundOpacity) }, + { "background-color-transition", static_cast(Property::BackgroundColorTransition) }, + { "background-pattern-transition", static_cast(Property::BackgroundPatternTransition) }, + { "background-opacity-transition", static_cast(Property::BackgroundOpacityTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::BackgroundColor) { Error error; @@ -262,21 +239,6 @@ optional BackgroundLayer::setLayoutProperty(const std::string& name, cons return Layer::setVisibility(value); } - enum class Property { - Unknown, - }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - } - - if (property == Property::Unknown) { - return Error { "layer doesn't support this property" }; - } - - - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index 92327a57e0..18f9a62f74 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -361,8 +362,7 @@ TransitionOptions CircleLayer::getCircleStrokeOpacityTransition() const { using namespace conversion; optional CircleLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { CircleRadius, CircleColor, CircleBlur, @@ -387,125 +387,38 @@ optional CircleLayer::setPaintProperty(const std::string& name, const Con CircleStrokeOpacityTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("circle-radius"): - if (name == "circle-radius") { - property = Property::CircleRadius; - } - break; - case util::hashFNV1a("circle-radius-transition"): - if (name == "circle-radius-transition") { - property = Property::CircleRadiusTransition; - } - break; - case util::hashFNV1a("circle-color"): - if (name == "circle-color") { - property = Property::CircleColor; - } - break; - case util::hashFNV1a("circle-color-transition"): - if (name == "circle-color-transition") { - property = Property::CircleColorTransition; - } - break; - case util::hashFNV1a("circle-blur"): - if (name == "circle-blur") { - property = Property::CircleBlur; - } - break; - case util::hashFNV1a("circle-blur-transition"): - if (name == "circle-blur-transition") { - property = Property::CircleBlurTransition; - } - break; - case util::hashFNV1a("circle-opacity"): - if (name == "circle-opacity") { - property = Property::CircleOpacity; - } - break; - case util::hashFNV1a("circle-opacity-transition"): - if (name == "circle-opacity-transition") { - property = Property::CircleOpacityTransition; - } - break; - case util::hashFNV1a("circle-translate"): - if (name == "circle-translate") { - property = Property::CircleTranslate; - } - break; - case util::hashFNV1a("circle-translate-transition"): - if (name == "circle-translate-transition") { - property = Property::CircleTranslateTransition; - } - break; - case util::hashFNV1a("circle-translate-anchor"): - if (name == "circle-translate-anchor") { - property = Property::CircleTranslateAnchor; - } - break; - case util::hashFNV1a("circle-translate-anchor-transition"): - if (name == "circle-translate-anchor-transition") { - property = Property::CircleTranslateAnchorTransition; - } - break; - case util::hashFNV1a("circle-pitch-scale"): - if (name == "circle-pitch-scale") { - property = Property::CirclePitchScale; - } - break; - case util::hashFNV1a("circle-pitch-scale-transition"): - if (name == "circle-pitch-scale-transition") { - property = Property::CirclePitchScaleTransition; - } - break; - case util::hashFNV1a("circle-pitch-alignment"): - if (name == "circle-pitch-alignment") { - property = Property::CirclePitchAlignment; - } - break; - case util::hashFNV1a("circle-pitch-alignment-transition"): - if (name == "circle-pitch-alignment-transition") { - property = Property::CirclePitchAlignmentTransition; - } - break; - case util::hashFNV1a("circle-stroke-width"): - if (name == "circle-stroke-width") { - property = Property::CircleStrokeWidth; - } - break; - case util::hashFNV1a("circle-stroke-width-transition"): - if (name == "circle-stroke-width-transition") { - property = Property::CircleStrokeWidthTransition; - } - break; - case util::hashFNV1a("circle-stroke-color"): - if (name == "circle-stroke-color") { - property = Property::CircleStrokeColor; - } - break; - case util::hashFNV1a("circle-stroke-color-transition"): - if (name == "circle-stroke-color-transition") { - property = Property::CircleStrokeColorTransition; - } - break; - case util::hashFNV1a("circle-stroke-opacity"): - if (name == "circle-stroke-opacity") { - property = Property::CircleStrokeOpacity; - } - break; - case util::hashFNV1a("circle-stroke-opacity-transition"): - if (name == "circle-stroke-opacity-transition") { - property = Property::CircleStrokeOpacityTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "circle-radius", static_cast(Property::CircleRadius) }, + { "circle-color", static_cast(Property::CircleColor) }, + { "circle-blur", static_cast(Property::CircleBlur) }, + { "circle-opacity", static_cast(Property::CircleOpacity) }, + { "circle-translate", static_cast(Property::CircleTranslate) }, + { "circle-translate-anchor", static_cast(Property::CircleTranslateAnchor) }, + { "circle-pitch-scale", static_cast(Property::CirclePitchScale) }, + { "circle-pitch-alignment", static_cast(Property::CirclePitchAlignment) }, + { "circle-stroke-width", static_cast(Property::CircleStrokeWidth) }, + { "circle-stroke-color", static_cast(Property::CircleStrokeColor) }, + { "circle-stroke-opacity", static_cast(Property::CircleStrokeOpacity) }, + { "circle-radius-transition", static_cast(Property::CircleRadiusTransition) }, + { "circle-color-transition", static_cast(Property::CircleColorTransition) }, + { "circle-blur-transition", static_cast(Property::CircleBlurTransition) }, + { "circle-opacity-transition", static_cast(Property::CircleOpacityTransition) }, + { "circle-translate-transition", static_cast(Property::CircleTranslateTransition) }, + { "circle-translate-anchor-transition", static_cast(Property::CircleTranslateAnchorTransition) }, + { "circle-pitch-scale-transition", static_cast(Property::CirclePitchScaleTransition) }, + { "circle-pitch-alignment-transition", static_cast(Property::CirclePitchAlignmentTransition) }, + { "circle-stroke-width-transition", static_cast(Property::CircleStrokeWidthTransition) }, + { "circle-stroke-color-transition", static_cast(Property::CircleStrokeColorTransition) }, + { "circle-stroke-opacity-transition", static_cast(Property::CircleStrokeOpacityTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::CircleRadius || property == Property::CircleBlur || property == Property::CircleOpacity || property == Property::CircleStrokeWidth || property == Property::CircleStrokeOpacity) { Error error; @@ -679,21 +592,6 @@ optional CircleLayer::setLayoutProperty(const std::string& name, const Co return Layer::setVisibility(value); } - enum class Property { - Unknown, - }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - } - - if (property == Property::Unknown) { - return Error { "layer doesn't support this property" }; - } - - - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index 74fd4ad757..3bbaebfe6d 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -280,8 +281,7 @@ TransitionOptions FillExtrusionLayer::getFillExtrusionVerticalGradientTransition using namespace conversion; optional FillExtrusionLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { FillExtrusionOpacity, FillExtrusionColor, FillExtrusionTranslate, @@ -300,95 +300,32 @@ optional FillExtrusionLayer::setPaintProperty(const std::string& name, co FillExtrusionVerticalGradientTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("fill-extrusion-opacity"): - if (name == "fill-extrusion-opacity") { - property = Property::FillExtrusionOpacity; - } - break; - case util::hashFNV1a("fill-extrusion-opacity-transition"): - if (name == "fill-extrusion-opacity-transition") { - property = Property::FillExtrusionOpacityTransition; - } - break; - case util::hashFNV1a("fill-extrusion-color"): - if (name == "fill-extrusion-color") { - property = Property::FillExtrusionColor; - } - break; - case util::hashFNV1a("fill-extrusion-color-transition"): - if (name == "fill-extrusion-color-transition") { - property = Property::FillExtrusionColorTransition; - } - break; - case util::hashFNV1a("fill-extrusion-translate"): - if (name == "fill-extrusion-translate") { - property = Property::FillExtrusionTranslate; - } - break; - case util::hashFNV1a("fill-extrusion-translate-transition"): - if (name == "fill-extrusion-translate-transition") { - property = Property::FillExtrusionTranslateTransition; - } - break; - case util::hashFNV1a("fill-extrusion-translate-anchor"): - if (name == "fill-extrusion-translate-anchor") { - property = Property::FillExtrusionTranslateAnchor; - } - break; - case util::hashFNV1a("fill-extrusion-translate-anchor-transition"): - if (name == "fill-extrusion-translate-anchor-transition") { - property = Property::FillExtrusionTranslateAnchorTransition; - } - break; - case util::hashFNV1a("fill-extrusion-pattern"): - if (name == "fill-extrusion-pattern") { - property = Property::FillExtrusionPattern; - } - break; - case util::hashFNV1a("fill-extrusion-pattern-transition"): - if (name == "fill-extrusion-pattern-transition") { - property = Property::FillExtrusionPatternTransition; - } - break; - case util::hashFNV1a("fill-extrusion-height"): - if (name == "fill-extrusion-height") { - property = Property::FillExtrusionHeight; - } - break; - case util::hashFNV1a("fill-extrusion-height-transition"): - if (name == "fill-extrusion-height-transition") { - property = Property::FillExtrusionHeightTransition; - } - break; - case util::hashFNV1a("fill-extrusion-base"): - if (name == "fill-extrusion-base") { - property = Property::FillExtrusionBase; - } - break; - case util::hashFNV1a("fill-extrusion-base-transition"): - if (name == "fill-extrusion-base-transition") { - property = Property::FillExtrusionBaseTransition; - } - break; - case util::hashFNV1a("fill-extrusion-vertical-gradient"): - if (name == "fill-extrusion-vertical-gradient") { - property = Property::FillExtrusionVerticalGradient; - } - break; - case util::hashFNV1a("fill-extrusion-vertical-gradient-transition"): - if (name == "fill-extrusion-vertical-gradient-transition") { - property = Property::FillExtrusionVerticalGradientTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "fill-extrusion-opacity", static_cast(Property::FillExtrusionOpacity) }, + { "fill-extrusion-color", static_cast(Property::FillExtrusionColor) }, + { "fill-extrusion-translate", static_cast(Property::FillExtrusionTranslate) }, + { "fill-extrusion-translate-anchor", static_cast(Property::FillExtrusionTranslateAnchor) }, + { "fill-extrusion-pattern", static_cast(Property::FillExtrusionPattern) }, + { "fill-extrusion-height", static_cast(Property::FillExtrusionHeight) }, + { "fill-extrusion-base", static_cast(Property::FillExtrusionBase) }, + { "fill-extrusion-vertical-gradient", static_cast(Property::FillExtrusionVerticalGradient) }, + { "fill-extrusion-opacity-transition", static_cast(Property::FillExtrusionOpacityTransition) }, + { "fill-extrusion-color-transition", static_cast(Property::FillExtrusionColorTransition) }, + { "fill-extrusion-translate-transition", static_cast(Property::FillExtrusionTranslateTransition) }, + { "fill-extrusion-translate-anchor-transition", static_cast(Property::FillExtrusionTranslateAnchorTransition) }, + { "fill-extrusion-pattern-transition", static_cast(Property::FillExtrusionPatternTransition) }, + { "fill-extrusion-height-transition", static_cast(Property::FillExtrusionHeightTransition) }, + { "fill-extrusion-base-transition", static_cast(Property::FillExtrusionBaseTransition) }, + { "fill-extrusion-vertical-gradient-transition", static_cast(Property::FillExtrusionVerticalGradientTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::FillExtrusionOpacity) { Error error; @@ -537,21 +474,6 @@ optional FillExtrusionLayer::setLayoutProperty(const std::string& name, c return Layer::setVisibility(value); } - enum class Property { - Unknown, - }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - } - - if (property == Property::Unknown) { - return Error { "layer doesn't support this property" }; - } - - - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index 55b5d9c8cb..6f3c163825 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -253,8 +254,7 @@ TransitionOptions FillLayer::getFillPatternTransition() const { using namespace conversion; optional FillLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { FillAntialias, FillOpacity, FillColor, @@ -271,85 +271,30 @@ optional FillLayer::setPaintProperty(const std::string& name, const Conve FillPatternTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("fill-antialias"): - if (name == "fill-antialias") { - property = Property::FillAntialias; - } - break; - case util::hashFNV1a("fill-antialias-transition"): - if (name == "fill-antialias-transition") { - property = Property::FillAntialiasTransition; - } - break; - case util::hashFNV1a("fill-opacity"): - if (name == "fill-opacity") { - property = Property::FillOpacity; - } - break; - case util::hashFNV1a("fill-opacity-transition"): - if (name == "fill-opacity-transition") { - property = Property::FillOpacityTransition; - } - break; - case util::hashFNV1a("fill-color"): - if (name == "fill-color") { - property = Property::FillColor; - } - break; - case util::hashFNV1a("fill-color-transition"): - if (name == "fill-color-transition") { - property = Property::FillColorTransition; - } - break; - case util::hashFNV1a("fill-outline-color"): - if (name == "fill-outline-color") { - property = Property::FillOutlineColor; - } - break; - case util::hashFNV1a("fill-outline-color-transition"): - if (name == "fill-outline-color-transition") { - property = Property::FillOutlineColorTransition; - } - break; - case util::hashFNV1a("fill-translate"): - if (name == "fill-translate") { - property = Property::FillTranslate; - } - break; - case util::hashFNV1a("fill-translate-transition"): - if (name == "fill-translate-transition") { - property = Property::FillTranslateTransition; - } - break; - case util::hashFNV1a("fill-translate-anchor"): - if (name == "fill-translate-anchor") { - property = Property::FillTranslateAnchor; - } - break; - case util::hashFNV1a("fill-translate-anchor-transition"): - if (name == "fill-translate-anchor-transition") { - property = Property::FillTranslateAnchorTransition; - } - break; - case util::hashFNV1a("fill-pattern"): - if (name == "fill-pattern") { - property = Property::FillPattern; - } - break; - case util::hashFNV1a("fill-pattern-transition"): - if (name == "fill-pattern-transition") { - property = Property::FillPatternTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "fill-antialias", static_cast(Property::FillAntialias) }, + { "fill-opacity", static_cast(Property::FillOpacity) }, + { "fill-color", static_cast(Property::FillColor) }, + { "fill-outline-color", static_cast(Property::FillOutlineColor) }, + { "fill-translate", static_cast(Property::FillTranslate) }, + { "fill-translate-anchor", static_cast(Property::FillTranslateAnchor) }, + { "fill-pattern", static_cast(Property::FillPattern) }, + { "fill-antialias-transition", static_cast(Property::FillAntialiasTransition) }, + { "fill-opacity-transition", static_cast(Property::FillOpacityTransition) }, + { "fill-color-transition", static_cast(Property::FillColorTransition) }, + { "fill-outline-color-transition", static_cast(Property::FillOutlineColorTransition) }, + { "fill-translate-transition", static_cast(Property::FillTranslateTransition) }, + { "fill-translate-anchor-transition", static_cast(Property::FillTranslateAnchorTransition) }, + { "fill-pattern-transition", static_cast(Property::FillPatternTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::FillAntialias) { Error error; @@ -481,21 +426,6 @@ optional FillLayer::setLayoutProperty(const std::string& name, const Conv return Layer::setVisibility(value); } - enum class Property { - Unknown, - }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - } - - if (property == Property::Unknown) { - return Error { "layer doesn't support this property" }; - } - - - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index 29c5fc5e4e..d548ee9b74 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -201,8 +202,7 @@ TransitionOptions HeatmapLayer::getHeatmapOpacityTransition() const { using namespace conversion; optional HeatmapLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { HeatmapRadius, HeatmapWeight, HeatmapIntensity, @@ -215,65 +215,26 @@ optional HeatmapLayer::setPaintProperty(const std::string& name, const Co HeatmapOpacityTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("heatmap-radius"): - if (name == "heatmap-radius") { - property = Property::HeatmapRadius; - } - break; - case util::hashFNV1a("heatmap-radius-transition"): - if (name == "heatmap-radius-transition") { - property = Property::HeatmapRadiusTransition; - } - break; - case util::hashFNV1a("heatmap-weight"): - if (name == "heatmap-weight") { - property = Property::HeatmapWeight; - } - break; - case util::hashFNV1a("heatmap-weight-transition"): - if (name == "heatmap-weight-transition") { - property = Property::HeatmapWeightTransition; - } - break; - case util::hashFNV1a("heatmap-intensity"): - if (name == "heatmap-intensity") { - property = Property::HeatmapIntensity; - } - break; - case util::hashFNV1a("heatmap-intensity-transition"): - if (name == "heatmap-intensity-transition") { - property = Property::HeatmapIntensityTransition; - } - break; - case util::hashFNV1a("heatmap-color"): - if (name == "heatmap-color") { - property = Property::HeatmapColor; - } - break; - case util::hashFNV1a("heatmap-color-transition"): - if (name == "heatmap-color-transition") { - property = Property::HeatmapColorTransition; - } - break; - case util::hashFNV1a("heatmap-opacity"): - if (name == "heatmap-opacity") { - property = Property::HeatmapOpacity; - } - break; - case util::hashFNV1a("heatmap-opacity-transition"): - if (name == "heatmap-opacity-transition") { - property = Property::HeatmapOpacityTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "heatmap-radius", static_cast(Property::HeatmapRadius) }, + { "heatmap-weight", static_cast(Property::HeatmapWeight) }, + { "heatmap-intensity", static_cast(Property::HeatmapIntensity) }, + { "heatmap-color", static_cast(Property::HeatmapColor) }, + { "heatmap-opacity", static_cast(Property::HeatmapOpacity) }, + { "heatmap-radius-transition", static_cast(Property::HeatmapRadiusTransition) }, + { "heatmap-weight-transition", static_cast(Property::HeatmapWeightTransition) }, + { "heatmap-intensity-transition", static_cast(Property::HeatmapIntensityTransition) }, + { "heatmap-color-transition", static_cast(Property::HeatmapColorTransition) }, + { "heatmap-opacity-transition", static_cast(Property::HeatmapOpacityTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::HeatmapRadius || property == Property::HeatmapWeight) { Error error; @@ -366,21 +327,6 @@ optional HeatmapLayer::setLayoutProperty(const std::string& name, const C return Layer::setVisibility(value); } - enum class Property { - Unknown, - }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - } - - if (property == Property::Unknown) { - return Error { "layer doesn't support this property" }; - } - - - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 0ae63b18c6..49d3217a3b 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -226,8 +227,7 @@ TransitionOptions HillshadeLayer::getHillshadeAccentColorTransition() const { using namespace conversion; optional HillshadeLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { HillshadeIlluminationDirection, HillshadeIlluminationAnchor, HillshadeExaggeration, @@ -242,75 +242,28 @@ optional HillshadeLayer::setPaintProperty(const std::string& name, const HillshadeAccentColorTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("hillshade-illumination-direction"): - if (name == "hillshade-illumination-direction") { - property = Property::HillshadeIlluminationDirection; - } - break; - case util::hashFNV1a("hillshade-illumination-direction-transition"): - if (name == "hillshade-illumination-direction-transition") { - property = Property::HillshadeIlluminationDirectionTransition; - } - break; - case util::hashFNV1a("hillshade-illumination-anchor"): - if (name == "hillshade-illumination-anchor") { - property = Property::HillshadeIlluminationAnchor; - } - break; - case util::hashFNV1a("hillshade-illumination-anchor-transition"): - if (name == "hillshade-illumination-anchor-transition") { - property = Property::HillshadeIlluminationAnchorTransition; - } - break; - case util::hashFNV1a("hillshade-exaggeration"): - if (name == "hillshade-exaggeration") { - property = Property::HillshadeExaggeration; - } - break; - case util::hashFNV1a("hillshade-exaggeration-transition"): - if (name == "hillshade-exaggeration-transition") { - property = Property::HillshadeExaggerationTransition; - } - break; - case util::hashFNV1a("hillshade-shadow-color"): - if (name == "hillshade-shadow-color") { - property = Property::HillshadeShadowColor; - } - break; - case util::hashFNV1a("hillshade-shadow-color-transition"): - if (name == "hillshade-shadow-color-transition") { - property = Property::HillshadeShadowColorTransition; - } - break; - case util::hashFNV1a("hillshade-highlight-color"): - if (name == "hillshade-highlight-color") { - property = Property::HillshadeHighlightColor; - } - break; - case util::hashFNV1a("hillshade-highlight-color-transition"): - if (name == "hillshade-highlight-color-transition") { - property = Property::HillshadeHighlightColorTransition; - } - break; - case util::hashFNV1a("hillshade-accent-color"): - if (name == "hillshade-accent-color") { - property = Property::HillshadeAccentColor; - } - break; - case util::hashFNV1a("hillshade-accent-color-transition"): - if (name == "hillshade-accent-color-transition") { - property = Property::HillshadeAccentColorTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "hillshade-illumination-direction", static_cast(Property::HillshadeIlluminationDirection) }, + { "hillshade-illumination-anchor", static_cast(Property::HillshadeIlluminationAnchor) }, + { "hillshade-exaggeration", static_cast(Property::HillshadeExaggeration) }, + { "hillshade-shadow-color", static_cast(Property::HillshadeShadowColor) }, + { "hillshade-highlight-color", static_cast(Property::HillshadeHighlightColor) }, + { "hillshade-accent-color", static_cast(Property::HillshadeAccentColor) }, + { "hillshade-illumination-direction-transition", static_cast(Property::HillshadeIlluminationDirectionTransition) }, + { "hillshade-illumination-anchor-transition", static_cast(Property::HillshadeIlluminationAnchorTransition) }, + { "hillshade-exaggeration-transition", static_cast(Property::HillshadeExaggerationTransition) }, + { "hillshade-shadow-color-transition", static_cast(Property::HillshadeShadowColorTransition) }, + { "hillshade-highlight-color-transition", static_cast(Property::HillshadeHighlightColorTransition) }, + { "hillshade-accent-color-transition", static_cast(Property::HillshadeAccentColorTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::HillshadeIlluminationDirection || property == Property::HillshadeExaggeration) { Error error; @@ -413,21 +366,6 @@ optional HillshadeLayer::setLayoutProperty(const std::string& name, const return Layer::setVisibility(value); } - enum class Property { - Unknown, - }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - } - - if (property == Property::Unknown) { - return Error { "layer doesn't support this property" }; - } - - - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index e34386fc20..fcae615fe0 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -14,7 +14,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -170,8 +171,7 @@ TransitionOptions <%- camelize(type) %>Layer::get<%- camelize(property.name) %>T using namespace conversion; optional <%- camelize(type) %>Layer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { <% for (const property of paintProperties) { -%> <%- camelize(property.name) %>, <% } -%> @@ -180,26 +180,18 @@ optional <%- camelize(type) %>Layer::setPaintProperty(const std::string& <% } -%> }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - <% for (const property of paintProperties) { -%> -case util::hashFNV1a("<%- property.name %>"): - if (name == "<%- property.name %>") { - property = Property::<%- camelize(property.name) %>; - } - break; - case util::hashFNV1a("<%- property.name %>-transition"): - if (name == "<%- property.name %>-transition") { - property = Property::<%- camelize(property.name) %>Transition; - } - break; - <% } %> - } + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + <%- paintProperties.map(p => `{ "${p.name}", static_cast(Property::${camelize(p.name)}) }`).join(',\n ') %>, + <%- paintProperties.map(p => `{ "${p.name}-transition", static_cast(Property::${camelize(p.name)}Transition) }`).join(',\n ') %> + }); - if (property == Property::Unknown) { + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + <% const paintConversions = {}; for (const property of paintProperties) { @@ -250,29 +242,23 @@ optional <%- camelize(type) %>Layer::setLayoutProperty(const std::string& if (name == "visibility") { return Layer::setVisibility(value); } - +<% if (layoutProperties.length) { -%> enum class Property { - Unknown, <% for (const property of layoutProperties) { -%> <%- camelize(property.name) %>, <% } -%> }; + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + <%- layoutProperties.map(p => `{ "${p.name}", static_cast(Property::${camelize(p.name)}) }`).join(',\n ') %> + }); - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - <% for (const property of layoutProperties) { %> - case util::hashFNV1a("<%- property.name %>"): - if (name == "<%- property.name %>") { - property = Property::<%- camelize(property.name) %>; - } - break; - <% } %> - } - - if (property == Property::Unknown) { + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + <% const layoutConversions = {}; for (const property of layoutProperties) { @@ -303,7 +289,7 @@ optional <%- camelize(type) %>Layer::setLayoutProperty(const std::string& <% } %> } <% } %> - +<% } /* if (layoutProperties.length) */ %> return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index 9b101a1948..643c294edf 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -426,8 +427,7 @@ TransitionOptions LineLayer::getLineGradientTransition() const { using namespace conversion; optional LineLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { LineOpacity, LineColor, LineTranslate, @@ -452,125 +452,38 @@ optional LineLayer::setPaintProperty(const std::string& name, const Conve LineGradientTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("line-opacity"): - if (name == "line-opacity") { - property = Property::LineOpacity; - } - break; - case util::hashFNV1a("line-opacity-transition"): - if (name == "line-opacity-transition") { - property = Property::LineOpacityTransition; - } - break; - case util::hashFNV1a("line-color"): - if (name == "line-color") { - property = Property::LineColor; - } - break; - case util::hashFNV1a("line-color-transition"): - if (name == "line-color-transition") { - property = Property::LineColorTransition; - } - break; - case util::hashFNV1a("line-translate"): - if (name == "line-translate") { - property = Property::LineTranslate; - } - break; - case util::hashFNV1a("line-translate-transition"): - if (name == "line-translate-transition") { - property = Property::LineTranslateTransition; - } - break; - case util::hashFNV1a("line-translate-anchor"): - if (name == "line-translate-anchor") { - property = Property::LineTranslateAnchor; - } - break; - case util::hashFNV1a("line-translate-anchor-transition"): - if (name == "line-translate-anchor-transition") { - property = Property::LineTranslateAnchorTransition; - } - break; - case util::hashFNV1a("line-width"): - if (name == "line-width") { - property = Property::LineWidth; - } - break; - case util::hashFNV1a("line-width-transition"): - if (name == "line-width-transition") { - property = Property::LineWidthTransition; - } - break; - case util::hashFNV1a("line-gap-width"): - if (name == "line-gap-width") { - property = Property::LineGapWidth; - } - break; - case util::hashFNV1a("line-gap-width-transition"): - if (name == "line-gap-width-transition") { - property = Property::LineGapWidthTransition; - } - break; - case util::hashFNV1a("line-offset"): - if (name == "line-offset") { - property = Property::LineOffset; - } - break; - case util::hashFNV1a("line-offset-transition"): - if (name == "line-offset-transition") { - property = Property::LineOffsetTransition; - } - break; - case util::hashFNV1a("line-blur"): - if (name == "line-blur") { - property = Property::LineBlur; - } - break; - case util::hashFNV1a("line-blur-transition"): - if (name == "line-blur-transition") { - property = Property::LineBlurTransition; - } - break; - case util::hashFNV1a("line-dasharray"): - if (name == "line-dasharray") { - property = Property::LineDasharray; - } - break; - case util::hashFNV1a("line-dasharray-transition"): - if (name == "line-dasharray-transition") { - property = Property::LineDasharrayTransition; - } - break; - case util::hashFNV1a("line-pattern"): - if (name == "line-pattern") { - property = Property::LinePattern; - } - break; - case util::hashFNV1a("line-pattern-transition"): - if (name == "line-pattern-transition") { - property = Property::LinePatternTransition; - } - break; - case util::hashFNV1a("line-gradient"): - if (name == "line-gradient") { - property = Property::LineGradient; - } - break; - case util::hashFNV1a("line-gradient-transition"): - if (name == "line-gradient-transition") { - property = Property::LineGradientTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "line-opacity", static_cast(Property::LineOpacity) }, + { "line-color", static_cast(Property::LineColor) }, + { "line-translate", static_cast(Property::LineTranslate) }, + { "line-translate-anchor", static_cast(Property::LineTranslateAnchor) }, + { "line-width", static_cast(Property::LineWidth) }, + { "line-gap-width", static_cast(Property::LineGapWidth) }, + { "line-offset", static_cast(Property::LineOffset) }, + { "line-blur", static_cast(Property::LineBlur) }, + { "line-dasharray", static_cast(Property::LineDasharray) }, + { "line-pattern", static_cast(Property::LinePattern) }, + { "line-gradient", static_cast(Property::LineGradient) }, + { "line-opacity-transition", static_cast(Property::LineOpacityTransition) }, + { "line-color-transition", static_cast(Property::LineColorTransition) }, + { "line-translate-transition", static_cast(Property::LineTranslateTransition) }, + { "line-translate-anchor-transition", static_cast(Property::LineTranslateAnchorTransition) }, + { "line-width-transition", static_cast(Property::LineWidthTransition) }, + { "line-gap-width-transition", static_cast(Property::LineGapWidthTransition) }, + { "line-offset-transition", static_cast(Property::LineOffsetTransition) }, + { "line-blur-transition", static_cast(Property::LineBlurTransition) }, + { "line-dasharray-transition", static_cast(Property::LineDasharrayTransition) }, + { "line-pattern-transition", static_cast(Property::LinePatternTransition) }, + { "line-gradient-transition", static_cast(Property::LineGradientTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::LineOpacity || property == Property::LineWidth || property == Property::LineGapWidth || property == Property::LineOffset || property == Property::LineBlur) { Error error; @@ -748,48 +661,26 @@ optional LineLayer::setLayoutProperty(const std::string& name, const Conv if (name == "visibility") { return Layer::setVisibility(value); } - enum class Property { - Unknown, LineCap, LineJoin, LineMiterLimit, LineRoundLimit, }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - case util::hashFNV1a("line-cap"): - if (name == "line-cap") { - property = Property::LineCap; - } - break; - - case util::hashFNV1a("line-join"): - if (name == "line-join") { - property = Property::LineJoin; - } - break; - - case util::hashFNV1a("line-miter-limit"): - if (name == "line-miter-limit") { - property = Property::LineMiterLimit; - } - break; - - case util::hashFNV1a("line-round-limit"): - if (name == "line-round-limit") { - property = Property::LineRoundLimit; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "line-cap", static_cast(Property::LineCap) }, + { "line-join", static_cast(Property::LineJoin) }, + { "line-miter-limit", static_cast(Property::LineMiterLimit) }, + { "line-round-limit", static_cast(Property::LineRoundLimit) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::LineCap) { Error error; diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index ea3ec3e31c..b0820456e1 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -280,8 +281,7 @@ TransitionOptions RasterLayer::getRasterFadeDurationTransition() const { using namespace conversion; optional RasterLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { RasterOpacity, RasterHueRotate, RasterBrightnessMin, @@ -300,95 +300,32 @@ optional RasterLayer::setPaintProperty(const std::string& name, const Con RasterFadeDurationTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("raster-opacity"): - if (name == "raster-opacity") { - property = Property::RasterOpacity; - } - break; - case util::hashFNV1a("raster-opacity-transition"): - if (name == "raster-opacity-transition") { - property = Property::RasterOpacityTransition; - } - break; - case util::hashFNV1a("raster-hue-rotate"): - if (name == "raster-hue-rotate") { - property = Property::RasterHueRotate; - } - break; - case util::hashFNV1a("raster-hue-rotate-transition"): - if (name == "raster-hue-rotate-transition") { - property = Property::RasterHueRotateTransition; - } - break; - case util::hashFNV1a("raster-brightness-min"): - if (name == "raster-brightness-min") { - property = Property::RasterBrightnessMin; - } - break; - case util::hashFNV1a("raster-brightness-min-transition"): - if (name == "raster-brightness-min-transition") { - property = Property::RasterBrightnessMinTransition; - } - break; - case util::hashFNV1a("raster-brightness-max"): - if (name == "raster-brightness-max") { - property = Property::RasterBrightnessMax; - } - break; - case util::hashFNV1a("raster-brightness-max-transition"): - if (name == "raster-brightness-max-transition") { - property = Property::RasterBrightnessMaxTransition; - } - break; - case util::hashFNV1a("raster-saturation"): - if (name == "raster-saturation") { - property = Property::RasterSaturation; - } - break; - case util::hashFNV1a("raster-saturation-transition"): - if (name == "raster-saturation-transition") { - property = Property::RasterSaturationTransition; - } - break; - case util::hashFNV1a("raster-contrast"): - if (name == "raster-contrast") { - property = Property::RasterContrast; - } - break; - case util::hashFNV1a("raster-contrast-transition"): - if (name == "raster-contrast-transition") { - property = Property::RasterContrastTransition; - } - break; - case util::hashFNV1a("raster-resampling"): - if (name == "raster-resampling") { - property = Property::RasterResampling; - } - break; - case util::hashFNV1a("raster-resampling-transition"): - if (name == "raster-resampling-transition") { - property = Property::RasterResamplingTransition; - } - break; - case util::hashFNV1a("raster-fade-duration"): - if (name == "raster-fade-duration") { - property = Property::RasterFadeDuration; - } - break; - case util::hashFNV1a("raster-fade-duration-transition"): - if (name == "raster-fade-duration-transition") { - property = Property::RasterFadeDurationTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "raster-opacity", static_cast(Property::RasterOpacity) }, + { "raster-hue-rotate", static_cast(Property::RasterHueRotate) }, + { "raster-brightness-min", static_cast(Property::RasterBrightnessMin) }, + { "raster-brightness-max", static_cast(Property::RasterBrightnessMax) }, + { "raster-saturation", static_cast(Property::RasterSaturation) }, + { "raster-contrast", static_cast(Property::RasterContrast) }, + { "raster-resampling", static_cast(Property::RasterResampling) }, + { "raster-fade-duration", static_cast(Property::RasterFadeDuration) }, + { "raster-opacity-transition", static_cast(Property::RasterOpacityTransition) }, + { "raster-hue-rotate-transition", static_cast(Property::RasterHueRotateTransition) }, + { "raster-brightness-min-transition", static_cast(Property::RasterBrightnessMinTransition) }, + { "raster-brightness-max-transition", static_cast(Property::RasterBrightnessMaxTransition) }, + { "raster-saturation-transition", static_cast(Property::RasterSaturationTransition) }, + { "raster-contrast-transition", static_cast(Property::RasterContrastTransition) }, + { "raster-resampling-transition", static_cast(Property::RasterResamplingTransition) }, + { "raster-fade-duration-transition", static_cast(Property::RasterFadeDurationTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::RasterOpacity || property == Property::RasterHueRotate || property == Property::RasterBrightnessMin || property == Property::RasterBrightnessMax || property == Property::RasterSaturation || property == Property::RasterContrast || property == Property::RasterFadeDuration) { Error error; @@ -502,21 +439,6 @@ optional RasterLayer::setLayoutProperty(const std::string& name, const Co return Layer::setVisibility(value); } - enum class Property { - Unknown, - }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - } - - if (property == Property::Unknown) { - return Error { "layer doesn't support this property" }; - } - - - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index be25594f54..75ed881058 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -9,7 +9,8 @@ #include #include #include -#include + +#include namespace mbgl { namespace style { @@ -1035,8 +1036,7 @@ TransitionOptions SymbolLayer::getTextTranslateAnchorTransition() const { using namespace conversion; optional SymbolLayer::setPaintProperty(const std::string& name, const Convertible& value) { - enum class Property { - Unknown, + enum class Property : uint8_t { IconOpacity, IconColor, IconHaloColor, @@ -1067,155 +1067,44 @@ optional SymbolLayer::setPaintProperty(const std::string& name, const Con TextTranslateAnchorTransition, }; - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - case util::hashFNV1a("icon-opacity"): - if (name == "icon-opacity") { - property = Property::IconOpacity; - } - break; - case util::hashFNV1a("icon-opacity-transition"): - if (name == "icon-opacity-transition") { - property = Property::IconOpacityTransition; - } - break; - case util::hashFNV1a("icon-color"): - if (name == "icon-color") { - property = Property::IconColor; - } - break; - case util::hashFNV1a("icon-color-transition"): - if (name == "icon-color-transition") { - property = Property::IconColorTransition; - } - break; - case util::hashFNV1a("icon-halo-color"): - if (name == "icon-halo-color") { - property = Property::IconHaloColor; - } - break; - case util::hashFNV1a("icon-halo-color-transition"): - if (name == "icon-halo-color-transition") { - property = Property::IconHaloColorTransition; - } - break; - case util::hashFNV1a("icon-halo-width"): - if (name == "icon-halo-width") { - property = Property::IconHaloWidth; - } - break; - case util::hashFNV1a("icon-halo-width-transition"): - if (name == "icon-halo-width-transition") { - property = Property::IconHaloWidthTransition; - } - break; - case util::hashFNV1a("icon-halo-blur"): - if (name == "icon-halo-blur") { - property = Property::IconHaloBlur; - } - break; - case util::hashFNV1a("icon-halo-blur-transition"): - if (name == "icon-halo-blur-transition") { - property = Property::IconHaloBlurTransition; - } - break; - case util::hashFNV1a("icon-translate"): - if (name == "icon-translate") { - property = Property::IconTranslate; - } - break; - case util::hashFNV1a("icon-translate-transition"): - if (name == "icon-translate-transition") { - property = Property::IconTranslateTransition; - } - break; - case util::hashFNV1a("icon-translate-anchor"): - if (name == "icon-translate-anchor") { - property = Property::IconTranslateAnchor; - } - break; - case util::hashFNV1a("icon-translate-anchor-transition"): - if (name == "icon-translate-anchor-transition") { - property = Property::IconTranslateAnchorTransition; - } - break; - case util::hashFNV1a("text-opacity"): - if (name == "text-opacity") { - property = Property::TextOpacity; - } - break; - case util::hashFNV1a("text-opacity-transition"): - if (name == "text-opacity-transition") { - property = Property::TextOpacityTransition; - } - break; - case util::hashFNV1a("text-color"): - if (name == "text-color") { - property = Property::TextColor; - } - break; - case util::hashFNV1a("text-color-transition"): - if (name == "text-color-transition") { - property = Property::TextColorTransition; - } - break; - case util::hashFNV1a("text-halo-color"): - if (name == "text-halo-color") { - property = Property::TextHaloColor; - } - break; - case util::hashFNV1a("text-halo-color-transition"): - if (name == "text-halo-color-transition") { - property = Property::TextHaloColorTransition; - } - break; - case util::hashFNV1a("text-halo-width"): - if (name == "text-halo-width") { - property = Property::TextHaloWidth; - } - break; - case util::hashFNV1a("text-halo-width-transition"): - if (name == "text-halo-width-transition") { - property = Property::TextHaloWidthTransition; - } - break; - case util::hashFNV1a("text-halo-blur"): - if (name == "text-halo-blur") { - property = Property::TextHaloBlur; - } - break; - case util::hashFNV1a("text-halo-blur-transition"): - if (name == "text-halo-blur-transition") { - property = Property::TextHaloBlurTransition; - } - break; - case util::hashFNV1a("text-translate"): - if (name == "text-translate") { - property = Property::TextTranslate; - } - break; - case util::hashFNV1a("text-translate-transition"): - if (name == "text-translate-transition") { - property = Property::TextTranslateTransition; - } - break; - case util::hashFNV1a("text-translate-anchor"): - if (name == "text-translate-anchor") { - property = Property::TextTranslateAnchor; - } - break; - case util::hashFNV1a("text-translate-anchor-transition"): - if (name == "text-translate-anchor-transition") { - property = Property::TextTranslateAnchorTransition; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "icon-opacity", static_cast(Property::IconOpacity) }, + { "icon-color", static_cast(Property::IconColor) }, + { "icon-halo-color", static_cast(Property::IconHaloColor) }, + { "icon-halo-width", static_cast(Property::IconHaloWidth) }, + { "icon-halo-blur", static_cast(Property::IconHaloBlur) }, + { "icon-translate", static_cast(Property::IconTranslate) }, + { "icon-translate-anchor", static_cast(Property::IconTranslateAnchor) }, + { "text-opacity", static_cast(Property::TextOpacity) }, + { "text-color", static_cast(Property::TextColor) }, + { "text-halo-color", static_cast(Property::TextHaloColor) }, + { "text-halo-width", static_cast(Property::TextHaloWidth) }, + { "text-halo-blur", static_cast(Property::TextHaloBlur) }, + { "text-translate", static_cast(Property::TextTranslate) }, + { "text-translate-anchor", static_cast(Property::TextTranslateAnchor) }, + { "icon-opacity-transition", static_cast(Property::IconOpacityTransition) }, + { "icon-color-transition", static_cast(Property::IconColorTransition) }, + { "icon-halo-color-transition", static_cast(Property::IconHaloColorTransition) }, + { "icon-halo-width-transition", static_cast(Property::IconHaloWidthTransition) }, + { "icon-halo-blur-transition", static_cast(Property::IconHaloBlurTransition) }, + { "icon-translate-transition", static_cast(Property::IconTranslateTransition) }, + { "icon-translate-anchor-transition", static_cast(Property::IconTranslateAnchorTransition) }, + { "text-opacity-transition", static_cast(Property::TextOpacityTransition) }, + { "text-color-transition", static_cast(Property::TextColorTransition) }, + { "text-halo-color-transition", static_cast(Property::TextHaloColorTransition) }, + { "text-halo-width-transition", static_cast(Property::TextHaloWidthTransition) }, + { "text-halo-blur-transition", static_cast(Property::TextHaloBlurTransition) }, + { "text-translate-transition", static_cast(Property::TextTranslateTransition) }, + { "text-translate-anchor-transition", static_cast(Property::TextTranslateAnchorTransition) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::IconOpacity || property == Property::IconHaloWidth || property == Property::IconHaloBlur || property == Property::TextOpacity || property == Property::TextHaloWidth || property == Property::TextHaloBlur) { Error error; @@ -1408,9 +1297,7 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co if (name == "visibility") { return Layer::setVisibility(value); } - enum class Property { - Unknown, SymbolPlacement, SymbolSpacing, SymbolAvoidEdges, @@ -1449,238 +1336,53 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co TextIgnorePlacement, TextOptional, }; - - Property property = Property::Unknown; - switch (util::hashFNV1a(name.c_str())) { - - case util::hashFNV1a("symbol-placement"): - if (name == "symbol-placement") { - property = Property::SymbolPlacement; - } - break; - - case util::hashFNV1a("symbol-spacing"): - if (name == "symbol-spacing") { - property = Property::SymbolSpacing; - } - break; - - case util::hashFNV1a("symbol-avoid-edges"): - if (name == "symbol-avoid-edges") { - property = Property::SymbolAvoidEdges; - } - break; - - case util::hashFNV1a("symbol-z-order"): - if (name == "symbol-z-order") { - property = Property::SymbolZOrder; - } - break; - - case util::hashFNV1a("icon-allow-overlap"): - if (name == "icon-allow-overlap") { - property = Property::IconAllowOverlap; - } - break; - - case util::hashFNV1a("icon-ignore-placement"): - if (name == "icon-ignore-placement") { - property = Property::IconIgnorePlacement; - } - break; - - case util::hashFNV1a("icon-optional"): - if (name == "icon-optional") { - property = Property::IconOptional; - } - break; - - case util::hashFNV1a("icon-rotation-alignment"): - if (name == "icon-rotation-alignment") { - property = Property::IconRotationAlignment; - } - break; - - case util::hashFNV1a("icon-size"): - if (name == "icon-size") { - property = Property::IconSize; - } - break; - - case util::hashFNV1a("icon-text-fit"): - if (name == "icon-text-fit") { - property = Property::IconTextFit; - } - break; - - case util::hashFNV1a("icon-text-fit-padding"): - if (name == "icon-text-fit-padding") { - property = Property::IconTextFitPadding; - } - break; - - case util::hashFNV1a("icon-image"): - if (name == "icon-image") { - property = Property::IconImage; - } - break; - - case util::hashFNV1a("icon-rotate"): - if (name == "icon-rotate") { - property = Property::IconRotate; - } - break; - - case util::hashFNV1a("icon-padding"): - if (name == "icon-padding") { - property = Property::IconPadding; - } - break; - - case util::hashFNV1a("icon-keep-upright"): - if (name == "icon-keep-upright") { - property = Property::IconKeepUpright; - } - break; - - case util::hashFNV1a("icon-offset"): - if (name == "icon-offset") { - property = Property::IconOffset; - } - break; - - case util::hashFNV1a("icon-anchor"): - if (name == "icon-anchor") { - property = Property::IconAnchor; - } - break; - - case util::hashFNV1a("icon-pitch-alignment"): - if (name == "icon-pitch-alignment") { - property = Property::IconPitchAlignment; - } - break; - - case util::hashFNV1a("text-pitch-alignment"): - if (name == "text-pitch-alignment") { - property = Property::TextPitchAlignment; - } - break; - - case util::hashFNV1a("text-rotation-alignment"): - if (name == "text-rotation-alignment") { - property = Property::TextRotationAlignment; - } - break; - - case util::hashFNV1a("text-field"): - if (name == "text-field") { - property = Property::TextField; - } - break; - - case util::hashFNV1a("text-font"): - if (name == "text-font") { - property = Property::TextFont; - } - break; - - case util::hashFNV1a("text-size"): - if (name == "text-size") { - property = Property::TextSize; - } - break; - - case util::hashFNV1a("text-max-width"): - if (name == "text-max-width") { - property = Property::TextMaxWidth; - } - break; - - case util::hashFNV1a("text-line-height"): - if (name == "text-line-height") { - property = Property::TextLineHeight; - } - break; - - case util::hashFNV1a("text-letter-spacing"): - if (name == "text-letter-spacing") { - property = Property::TextLetterSpacing; - } - break; - - case util::hashFNV1a("text-justify"): - if (name == "text-justify") { - property = Property::TextJustify; - } - break; - - case util::hashFNV1a("text-anchor"): - if (name == "text-anchor") { - property = Property::TextAnchor; - } - break; - - case util::hashFNV1a("text-max-angle"): - if (name == "text-max-angle") { - property = Property::TextMaxAngle; - } - break; - - case util::hashFNV1a("text-rotate"): - if (name == "text-rotate") { - property = Property::TextRotate; - } - break; - - case util::hashFNV1a("text-padding"): - if (name == "text-padding") { - property = Property::TextPadding; - } - break; - - case util::hashFNV1a("text-keep-upright"): - if (name == "text-keep-upright") { - property = Property::TextKeepUpright; - } - break; - - case util::hashFNV1a("text-transform"): - if (name == "text-transform") { - property = Property::TextTransform; - } - break; - - case util::hashFNV1a("text-offset"): - if (name == "text-offset") { - property = Property::TextOffset; - } - break; - - case util::hashFNV1a("text-allow-overlap"): - if (name == "text-allow-overlap") { - property = Property::TextAllowOverlap; - } - break; - - case util::hashFNV1a("text-ignore-placement"): - if (name == "text-ignore-placement") { - property = Property::TextIgnorePlacement; - } - break; - - case util::hashFNV1a("text-optional"): - if (name == "text-optional") { - property = Property::TextOptional; - } - break; - - } - - if (property == Property::Unknown) { + MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map({ + { "symbol-placement", static_cast(Property::SymbolPlacement) }, + { "symbol-spacing", static_cast(Property::SymbolSpacing) }, + { "symbol-avoid-edges", static_cast(Property::SymbolAvoidEdges) }, + { "symbol-z-order", static_cast(Property::SymbolZOrder) }, + { "icon-allow-overlap", static_cast(Property::IconAllowOverlap) }, + { "icon-ignore-placement", static_cast(Property::IconIgnorePlacement) }, + { "icon-optional", static_cast(Property::IconOptional) }, + { "icon-rotation-alignment", static_cast(Property::IconRotationAlignment) }, + { "icon-size", static_cast(Property::IconSize) }, + { "icon-text-fit", static_cast(Property::IconTextFit) }, + { "icon-text-fit-padding", static_cast(Property::IconTextFitPadding) }, + { "icon-image", static_cast(Property::IconImage) }, + { "icon-rotate", static_cast(Property::IconRotate) }, + { "icon-padding", static_cast(Property::IconPadding) }, + { "icon-keep-upright", static_cast(Property::IconKeepUpright) }, + { "icon-offset", static_cast(Property::IconOffset) }, + { "icon-anchor", static_cast(Property::IconAnchor) }, + { "icon-pitch-alignment", static_cast(Property::IconPitchAlignment) }, + { "text-pitch-alignment", static_cast(Property::TextPitchAlignment) }, + { "text-rotation-alignment", static_cast(Property::TextRotationAlignment) }, + { "text-field", static_cast(Property::TextField) }, + { "text-font", static_cast(Property::TextFont) }, + { "text-size", static_cast(Property::TextSize) }, + { "text-max-width", static_cast(Property::TextMaxWidth) }, + { "text-line-height", static_cast(Property::TextLineHeight) }, + { "text-letter-spacing", static_cast(Property::TextLetterSpacing) }, + { "text-justify", static_cast(Property::TextJustify) }, + { "text-anchor", static_cast(Property::TextAnchor) }, + { "text-max-angle", static_cast(Property::TextMaxAngle) }, + { "text-rotate", static_cast(Property::TextRotate) }, + { "text-padding", static_cast(Property::TextPadding) }, + { "text-keep-upright", static_cast(Property::TextKeepUpright) }, + { "text-transform", static_cast(Property::TextTransform) }, + { "text-offset", static_cast(Property::TextOffset) }, + { "text-allow-overlap", static_cast(Property::TextAllowOverlap) }, + { "text-ignore-placement", static_cast(Property::TextIgnorePlacement) }, + { "text-optional", static_cast(Property::TextOptional) } + }); + + const auto it = properties.find(name.c_str()); + if (it == properties.end()) { return Error { "layer doesn't support this property" }; } + Property property = static_cast(it->second); + if (property == Property::SymbolPlacement) { Error error; -- cgit v1.2.1