diff --git a/cmake/core-files.cmake b/cmake/core-files.cmake index d35e2c66c..e875f5b14 100644 --- a/cmake/core-files.cmake +++ b/cmake/core-files.cmake @@ -707,6 +707,7 @@ set(MBGL_CORE_FILES src/mbgl/util/dtoa.cpp src/mbgl/util/dtoa.hpp src/mbgl/util/event.cpp + src/mbgl/util/fnv_hash.hpp src/mbgl/util/font_stack.cpp src/mbgl/util/geo.cpp src/mbgl/util/geojson_impl.cpp diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 837d55772..88e175cb7 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -158,70 +159,115 @@ TransitionOptions BackgroundLayer::getBackgroundOpacityTransition() const { using namespace conversion; optional BackgroundLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + BackgroundColor, + BackgroundPattern, + BackgroundOpacity, + BackgroundColorTransition, + BackgroundPatternTransition, + 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 (name == "background-color") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::BackgroundColor) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundColor(*typedValue); return nullopt; - } - if (name == "background-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setBackgroundColorTransition(*transition); - return nullopt; + } - if (name == "background-pattern") { + if (property == Property::BackgroundPattern) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundPattern(*typedValue); return nullopt; - } - if (name == "background-pattern-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setBackgroundPatternTransition(*transition); - return nullopt; + } - if (name == "background-opacity") { + if (property == Property::BackgroundOpacity) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setBackgroundOpacity(*typedValue); return nullopt; + } - if (name == "background-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::BackgroundColorTransition) { + setBackgroundColorTransition(*transition); + return nullopt; + } + + if (property == Property::BackgroundPatternTransition) { + setBackgroundPatternTransition(*transition); + return nullopt; + } + + if (property == Property::BackgroundOpacityTransition) { setBackgroundOpacityTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -242,7 +288,21 @@ optional BackgroundLayer::setLayoutProperty(const std::string& name, cons return nullopt; } + 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 3f769e935..eb3227da3 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -402,238 +403,316 @@ TransitionOptions CircleLayer::getCircleStrokeOpacityTransition() const { using namespace conversion; optional CircleLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + CircleRadius, + CircleColor, + CircleBlur, + CircleOpacity, + CircleTranslate, + CircleTranslateAnchor, + CirclePitchScale, + CirclePitchAlignment, + CircleStrokeWidth, + CircleStrokeColor, + CircleStrokeOpacity, + CircleRadiusTransition, + CircleColorTransition, + CircleBlurTransition, + CircleOpacityTransition, + CircleTranslateTransition, + CircleTranslateAnchorTransition, + CirclePitchScaleTransition, + CirclePitchAlignmentTransition, + CircleStrokeWidthTransition, + CircleStrokeColorTransition, + 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 (name == "circle-radius") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::CircleRadius || property == Property::CircleBlur || property == Property::CircleOpacity || property == Property::CircleStrokeWidth || property == Property::CircleStrokeOpacity) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setCircleRadius(*typedValue); - return nullopt; - } - if (name == "circle-radius-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::CircleRadius) { + setCircleRadius(*typedValue); + return nullopt; } - - setCircleRadiusTransition(*transition); - return nullopt; + + if (property == Property::CircleBlur) { + setCircleBlur(*typedValue); + return nullopt; + } + + if (property == Property::CircleOpacity) { + setCircleOpacity(*typedValue); + return nullopt; + } + + if (property == Property::CircleStrokeWidth) { + setCircleStrokeWidth(*typedValue); + return nullopt; + } + + if (property == Property::CircleStrokeOpacity) { + setCircleStrokeOpacity(*typedValue); + return nullopt; + } + } - if (name == "circle-color") { + if (property == Property::CircleColor || property == Property::CircleStrokeColor) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setCircleColor(*typedValue); - return nullopt; - } - if (name == "circle-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::CircleColor) { + setCircleColor(*typedValue); + return nullopt; } - - setCircleColorTransition(*transition); - return nullopt; + + if (property == Property::CircleStrokeColor) { + setCircleStrokeColor(*typedValue); + return nullopt; + } + } - if (name == "circle-blur") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleBlur(*typedValue); - return nullopt; - } - if (name == "circle-blur-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setCircleBlurTransition(*transition); - return nullopt; - } - - if (name == "circle-opacity") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleOpacity(*typedValue); - return nullopt; - } - if (name == "circle-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setCircleOpacityTransition(*transition); - return nullopt; - } - - if (name == "circle-translate") { + if (property == Property::CircleTranslate) { Error error; optional>> typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setCircleTranslate(*typedValue); return nullopt; - } - if (name == "circle-translate-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setCircleTranslateTransition(*transition); - return nullopt; + } - if (name == "circle-translate-anchor") { + if (property == Property::CircleTranslateAnchor) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setCircleTranslateAnchor(*typedValue); return nullopt; - } - if (name == "circle-translate-anchor-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setCircleTranslateAnchorTransition(*transition); - return nullopt; + } - if (name == "circle-pitch-scale") { + if (property == Property::CirclePitchScale) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setCirclePitchScale(*typedValue); return nullopt; - } - if (name == "circle-pitch-scale-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setCirclePitchScaleTransition(*transition); - return nullopt; + } - if (name == "circle-pitch-alignment") { + if (property == Property::CirclePitchAlignment) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setCirclePitchAlignment(*typedValue); return nullopt; + } - if (name == "circle-pitch-alignment-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::CircleRadiusTransition) { + setCircleRadiusTransition(*transition); + return nullopt; + } + + if (property == Property::CircleColorTransition) { + setCircleColorTransition(*transition); + return nullopt; + } + + if (property == Property::CircleBlurTransition) { + setCircleBlurTransition(*transition); + return nullopt; + } + + if (property == Property::CircleOpacityTransition) { + setCircleOpacityTransition(*transition); + return nullopt; + } + + if (property == Property::CircleTranslateTransition) { + setCircleTranslateTransition(*transition); + return nullopt; + } + + if (property == Property::CircleTranslateAnchorTransition) { + setCircleTranslateAnchorTransition(*transition); + return nullopt; + } + + if (property == Property::CirclePitchScaleTransition) { + setCirclePitchScaleTransition(*transition); + return nullopt; + } + + if (property == Property::CirclePitchAlignmentTransition) { setCirclePitchAlignmentTransition(*transition); return nullopt; } - if (name == "circle-stroke-width") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleStrokeWidth(*typedValue); - return nullopt; - } - if (name == "circle-stroke-width-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::CircleStrokeWidthTransition) { setCircleStrokeWidthTransition(*transition); return nullopt; } - if (name == "circle-stroke-color") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleStrokeColor(*typedValue); - return nullopt; - } - if (name == "circle-stroke-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::CircleStrokeColorTransition) { setCircleStrokeColorTransition(*transition); return nullopt; } - if (name == "circle-stroke-opacity") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setCircleStrokeOpacity(*typedValue); - return nullopt; - } - if (name == "circle-stroke-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::CircleStrokeOpacityTransition) { setCircleStrokeOpacityTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -654,7 +733,21 @@ optional CircleLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + 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 b48e51c56..33f5bbe87 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -294,154 +295,226 @@ TransitionOptions FillExtrusionLayer::getFillExtrusionBaseTransition() const { using namespace conversion; optional FillExtrusionLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + FillExtrusionOpacity, + FillExtrusionColor, + FillExtrusionTranslate, + FillExtrusionTranslateAnchor, + FillExtrusionPattern, + FillExtrusionHeight, + FillExtrusionBase, + FillExtrusionOpacityTransition, + FillExtrusionColorTransition, + FillExtrusionTranslateTransition, + FillExtrusionTranslateAnchorTransition, + FillExtrusionPatternTransition, + FillExtrusionHeightTransition, + FillExtrusionBaseTransition, + }; + + 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; - if (name == "fill-extrusion-opacity") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::FillExtrusionOpacity) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionOpacity(*typedValue); return nullopt; - } - if (name == "fill-extrusion-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillExtrusionOpacityTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-color") { + if (property == Property::FillExtrusionColor) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setFillExtrusionColor(*typedValue); return nullopt; - } - if (name == "fill-extrusion-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillExtrusionColorTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-translate") { + if (property == Property::FillExtrusionTranslate) { Error error; optional>> typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionTranslate(*typedValue); return nullopt; - } - if (name == "fill-extrusion-translate-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillExtrusionTranslateTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-translate-anchor") { + if (property == Property::FillExtrusionTranslateAnchor) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionTranslateAnchor(*typedValue); return nullopt; - } - if (name == "fill-extrusion-translate-anchor-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillExtrusionTranslateAnchorTransition(*transition); - return nullopt; + } - if (name == "fill-extrusion-pattern") { + if (property == Property::FillExtrusionPattern) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillExtrusionPattern(*typedValue); return nullopt; + } - if (name == "fill-extrusion-pattern-transition") { + + if (property == Property::FillExtrusionHeight || property == Property::FillExtrusionBase) { Error error; - optional transition = convert(value, error); - if (!transition) { + optional> typedValue = convert>(value, error, true, false); + if (!typedValue) { return error; } + + if (property == Property::FillExtrusionHeight) { + setFillExtrusionHeight(*typedValue); + return nullopt; + } + + if (property == Property::FillExtrusionBase) { + setFillExtrusionBase(*typedValue); + return nullopt; + } + + } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::FillExtrusionOpacityTransition) { + setFillExtrusionOpacityTransition(*transition); + return nullopt; + } + + if (property == Property::FillExtrusionColorTransition) { + setFillExtrusionColorTransition(*transition); + return nullopt; + } + + if (property == Property::FillExtrusionTranslateTransition) { + setFillExtrusionTranslateTransition(*transition); + return nullopt; + } + + if (property == Property::FillExtrusionTranslateAnchorTransition) { + setFillExtrusionTranslateAnchorTransition(*transition); + return nullopt; + } + + if (property == Property::FillExtrusionPatternTransition) { setFillExtrusionPatternTransition(*transition); return nullopt; } - if (name == "fill-extrusion-height") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setFillExtrusionHeight(*typedValue); - return nullopt; - } - if (name == "fill-extrusion-height-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::FillExtrusionHeightTransition) { setFillExtrusionHeightTransition(*transition); return nullopt; } - if (name == "fill-extrusion-base") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setFillExtrusionBase(*typedValue); - return nullopt; - } - if (name == "fill-extrusion-base-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::FillExtrusionBaseTransition) { setFillExtrusionBaseTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -462,7 +535,21 @@ optional FillExtrusionLayer::setLayoutProperty(const std::string& name, c return nullopt; } + 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 04c3bcef3..c2756dc90 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -294,154 +295,226 @@ TransitionOptions FillLayer::getFillPatternTransition() const { using namespace conversion; optional FillLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + FillAntialias, + FillOpacity, + FillColor, + FillOutlineColor, + FillTranslate, + FillTranslateAnchor, + FillPattern, + FillAntialiasTransition, + FillOpacityTransition, + FillColorTransition, + FillOutlineColorTransition, + FillTranslateTransition, + FillTranslateAnchorTransition, + 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 (name == "fill-antialias") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::FillAntialias) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillAntialias(*typedValue); return nullopt; - } - if (name == "fill-antialias-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillAntialiasTransition(*transition); - return nullopt; + } - if (name == "fill-opacity") { + if (property == Property::FillOpacity) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setFillOpacity(*typedValue); return nullopt; - } - if (name == "fill-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillOpacityTransition(*transition); - return nullopt; + } - if (name == "fill-color") { + if (property == Property::FillColor || property == Property::FillOutlineColor) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setFillColor(*typedValue); - return nullopt; - } - if (name == "fill-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::FillColor) { + setFillColor(*typedValue); + return nullopt; } - - setFillColorTransition(*transition); - return nullopt; + + if (property == Property::FillOutlineColor) { + setFillOutlineColor(*typedValue); + return nullopt; + } + } - if (name == "fill-outline-color") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setFillOutlineColor(*typedValue); - return nullopt; - } - if (name == "fill-outline-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillOutlineColorTransition(*transition); - return nullopt; - } - - if (name == "fill-translate") { + if (property == Property::FillTranslate) { Error error; optional>> typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setFillTranslate(*typedValue); return nullopt; - } - if (name == "fill-translate-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillTranslateTransition(*transition); - return nullopt; + } - if (name == "fill-translate-anchor") { + if (property == Property::FillTranslateAnchor) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillTranslateAnchor(*typedValue); return nullopt; - } - if (name == "fill-translate-anchor-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setFillTranslateAnchorTransition(*transition); - return nullopt; + } - if (name == "fill-pattern") { + if (property == Property::FillPattern) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setFillPattern(*typedValue); return nullopt; + } - if (name == "fill-pattern-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::FillAntialiasTransition) { + setFillAntialiasTransition(*transition); + return nullopt; + } + + if (property == Property::FillOpacityTransition) { + setFillOpacityTransition(*transition); + return nullopt; + } + + if (property == Property::FillColorTransition) { + setFillColorTransition(*transition); + return nullopt; + } + + if (property == Property::FillOutlineColorTransition) { + setFillOutlineColorTransition(*transition); + return nullopt; + } + + if (property == Property::FillTranslateTransition) { + setFillTranslateTransition(*transition); + return nullopt; + } + + if (property == Property::FillTranslateAnchorTransition) { + setFillTranslateAnchorTransition(*transition); + return nullopt; + } + + if (property == Property::FillPatternTransition) { setFillPatternTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -462,7 +535,21 @@ optional FillLayer::setLayoutProperty(const std::string& name, const Conv return nullopt; } + 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 443b94c2c..69499e7d4 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -242,112 +243,163 @@ TransitionOptions HeatmapLayer::getHeatmapOpacityTransition() const { using namespace conversion; optional HeatmapLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + HeatmapRadius, + HeatmapWeight, + HeatmapIntensity, + HeatmapColor, + HeatmapOpacity, + HeatmapRadiusTransition, + HeatmapWeightTransition, + HeatmapIntensityTransition, + HeatmapColorTransition, + 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 (name == "heatmap-radius") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::HeatmapRadius || property == Property::HeatmapWeight) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setHeatmapRadius(*typedValue); - return nullopt; - } - if (name == "heatmap-radius-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::HeatmapRadius) { + setHeatmapRadius(*typedValue); + return nullopt; } - - setHeatmapRadiusTransition(*transition); - return nullopt; + + if (property == Property::HeatmapWeight) { + setHeatmapWeight(*typedValue); + return nullopt; + } + } - if (name == "heatmap-weight") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setHeatmapWeight(*typedValue); - return nullopt; - } - if (name == "heatmap-weight-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setHeatmapWeightTransition(*transition); - return nullopt; - } - - if (name == "heatmap-intensity") { + if (property == Property::HeatmapIntensity || property == Property::HeatmapOpacity) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - - setHeatmapIntensity(*typedValue); - return nullopt; - } - if (name == "heatmap-intensity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::HeatmapIntensity) { + setHeatmapIntensity(*typedValue); + return nullopt; } - - setHeatmapIntensityTransition(*transition); - return nullopt; + + if (property == Property::HeatmapOpacity) { + setHeatmapOpacity(*typedValue); + return nullopt; + } + } - if (name == "heatmap-color") { + if (property == Property::HeatmapColor) { Error error; optional typedValue = convert(value, error, false, false); if (!typedValue) { return error; } - + setHeatmapColor(*typedValue); return nullopt; + } - if (name == "heatmap-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::HeatmapRadiusTransition) { + setHeatmapRadiusTransition(*transition); + return nullopt; + } + + if (property == Property::HeatmapWeightTransition) { + setHeatmapWeightTransition(*transition); + return nullopt; + } + + if (property == Property::HeatmapIntensityTransition) { + setHeatmapIntensityTransition(*transition); + return nullopt; + } + + if (property == Property::HeatmapColorTransition) { setHeatmapColorTransition(*transition); return nullopt; } - if (name == "heatmap-opacity") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHeatmapOpacity(*typedValue); - return nullopt; - } - if (name == "heatmap-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::HeatmapOpacityTransition) { setHeatmapOpacityTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -368,7 +420,21 @@ optional HeatmapLayer::setLayoutProperty(const std::string& name, const C return nullopt; } + 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_properties.hpp b/src/mbgl/style/layers/heatmap_layer_properties.hpp index fe7257a78..4d49a52c7 100644 --- a/src/mbgl/style/layers/heatmap_layer_properties.hpp +++ b/src/mbgl/style/layers/heatmap_layer_properties.hpp @@ -24,7 +24,8 @@ struct HeatmapIntensity : PaintProperty { static float defaultValue() { return 1; } }; -using HeatmapColor = ColorRampProperty; +struct HeatmapColor : ColorRampProperty { +}; struct HeatmapOpacity : PaintProperty { static float defaultValue() { return 1; } diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 2d8c837ba..9ccdd1567 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -245,133 +246,185 @@ TransitionOptions HillshadeLayer::getHillshadeAccentColorTransition() const { using namespace conversion; optional HillshadeLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + HillshadeIlluminationDirection, + HillshadeIlluminationAnchor, + HillshadeExaggeration, + HillshadeShadowColor, + HillshadeHighlightColor, + HillshadeAccentColor, + HillshadeIlluminationDirectionTransition, + HillshadeIlluminationAnchorTransition, + HillshadeExaggerationTransition, + HillshadeShadowColorTransition, + HillshadeHighlightColorTransition, + 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 (name == "hillshade-illumination-direction") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::HillshadeIlluminationDirection || property == Property::HillshadeExaggeration) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - - setHillshadeIlluminationDirection(*typedValue); - return nullopt; - } - if (name == "hillshade-illumination-direction-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::HillshadeIlluminationDirection) { + setHillshadeIlluminationDirection(*typedValue); + return nullopt; } - - setHillshadeIlluminationDirectionTransition(*transition); - return nullopt; + + if (property == Property::HillshadeExaggeration) { + setHillshadeExaggeration(*typedValue); + return nullopt; + } + } - if (name == "hillshade-illumination-anchor") { + if (property == Property::HillshadeIlluminationAnchor) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setHillshadeIlluminationAnchor(*typedValue); return nullopt; + } - if (name == "hillshade-illumination-anchor-transition") { + + if (property == Property::HillshadeShadowColor || property == Property::HillshadeHighlightColor || property == Property::HillshadeAccentColor) { Error error; - optional transition = convert(value, error); - if (!transition) { + optional> typedValue = convert>(value, error, false, false); + if (!typedValue) { return error; } + + if (property == Property::HillshadeShadowColor) { + setHillshadeShadowColor(*typedValue); + return nullopt; + } + + if (property == Property::HillshadeHighlightColor) { + setHillshadeHighlightColor(*typedValue); + return nullopt; + } + + if (property == Property::HillshadeAccentColor) { + setHillshadeAccentColor(*typedValue); + return nullopt; + } + + } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::HillshadeIlluminationDirectionTransition) { + setHillshadeIlluminationDirectionTransition(*transition); + return nullopt; + } + + if (property == Property::HillshadeIlluminationAnchorTransition) { setHillshadeIlluminationAnchorTransition(*transition); return nullopt; } - if (name == "hillshade-exaggeration") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHillshadeExaggeration(*typedValue); - return nullopt; - } - if (name == "hillshade-exaggeration-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::HillshadeExaggerationTransition) { setHillshadeExaggerationTransition(*transition); return nullopt; } - if (name == "hillshade-shadow-color") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHillshadeShadowColor(*typedValue); - return nullopt; - } - if (name == "hillshade-shadow-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::HillshadeShadowColorTransition) { setHillshadeShadowColorTransition(*transition); return nullopt; } - if (name == "hillshade-highlight-color") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHillshadeHighlightColor(*typedValue); - return nullopt; - } - if (name == "hillshade-highlight-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::HillshadeHighlightColorTransition) { setHillshadeHighlightColorTransition(*transition); return nullopt; } - if (name == "hillshade-accent-color") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setHillshadeAccentColor(*typedValue); - return nullopt; - } - if (name == "hillshade-accent-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::HillshadeAccentColorTransition) { setHillshadeAccentColorTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -392,7 +445,21 @@ optional HillshadeLayer::setLayoutProperty(const std::string& name, const return nullopt; } + 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 7555054bd..8a6db749c 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -14,6 +14,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -178,28 +179,78 @@ TransitionOptions <%- camelize(type) %>Layer::get<%- camelize(property.name) %>T using namespace conversion; optional <%- camelize(type) %>Layer::setPaintProperty(const std::string& name, const Convertible& value) { - <% for (const property of paintProperties) { %> - if (name == "<%- property.name %>") { + enum class Property { + Unknown, +<% for (const property of paintProperties) { -%> + <%- camelize(property.name) %>, +<% } -%> +<% for (const property of paintProperties) { -%> + <%- camelize(property.name) %>Transition, +<% } -%> + }; + + 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; + <% } %> + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + <% + const paintConversions = {}; + for (const property of paintProperties) { + const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; + const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; + const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; + paintConversions[conversion] = paintConversions[conversion] || []; + paintConversions[conversion].push(property); + } + -%> + <% for (const key in paintConversions) { + const properties = paintConversions[key]; + %> + if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) { Error error; - optional<<%- propertyValueType(property) %>> typedValue = convert<<%- propertyValueType(property) %>>(value, error, <%- property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven' %>, <%- property.name === 'icon-image' || property.name === 'text-field' %>); + <%- key %>; if (!typedValue) { return error; } - - set<%- camelize(property.name) %>(*typedValue); + <% if (properties.length == 1) { %> + set<%- camelize(properties[0].name) %>(*typedValue); return nullopt; - } - if (name == "<%- property.name %>-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + <% } else for (const property of properties) { %> + if (property == Property::<%- camelize(property.name) %>) { + set<%- camelize(property.name) %>(*typedValue); + return nullopt; } + <% } %> + } + <% } %> + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + <% for (const property of paintProperties) { %> + if (property == Property::<%- camelize(property.name) %>Transition) { set<%- camelize(property.name) %>Transition(*transition); return nullopt; } - <% } -%> + <% } %> return Error { "layer doesn't support this property" }; } @@ -221,18 +272,58 @@ optional <%- camelize(type) %>Layer::setLayoutProperty(const std::string& return nullopt; } + enum class Property { + Unknown, +<% for (const property of layoutProperties) { -%> + <%- camelize(property.name) %>, +<% } -%> + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { <% for (const property of layoutProperties) { %> - if (name == "<%- property.name %>") { + case util::hashFNV1a("<%- property.name %>"): + if (name == "<%- property.name %>") { + property = Property::<%- camelize(property.name) %>; + } + break; + <% } %> + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + <% + const layoutConversions = {}; + for (const property of layoutProperties) { + const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; + const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; + const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; + layoutConversions[conversion] = layoutConversions[conversion] || []; + layoutConversions[conversion].push(property); + } + -%> + <% for (const key in layoutConversions) { + const properties = layoutConversions[key]; + %> + if (<%- properties.map(p => `property == Property::${camelize(p.name)}`).join(' || ') %>) { Error error; - optional<<%- propertyValueType(property) %>> typedValue = convert<<%- propertyValueType(property) %>>(value, error, <%- property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven' %>, <%- property.name === 'icon-image' || property.name === 'text-field' %>); + <%- key %>; if (!typedValue) { return error; } - - set<%- camelize(property.name) %>(*typedValue); + <% if (properties.length == 1) { %> + set<%- camelize(properties[0].name) %>(*typedValue); return nullopt; + <% } else for (const property of properties) { %> + if (property == Property::<%- camelize(property.name) %>) { + set<%- camelize(property.name) %>(*typedValue); + return nullopt; + } + <% } %> } - <% } -%> + <% } %> return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/layer_properties.hpp.ejs b/src/mbgl/style/layers/layer_properties.hpp.ejs index 5b774933a..694d9a62b 100644 --- a/src/mbgl/style/layers/layer_properties.hpp.ejs +++ b/src/mbgl/style/layers/layer_properties.hpp.ejs @@ -26,7 +26,8 @@ struct <%- camelize(property.name) %> : <%- layoutPropertyType(property, type) % <% } -%> <% for (const property of paintProperties) { -%> <% if (property['property-type'] === 'color-ramp') { -%> -using <%- camelize(property.name) %> = ColorRampProperty; +struct <%- camelize(property.name) %> : ColorRampProperty { +}; <% } else { -%> struct <%- camelize(property.name) %> : <%- paintPropertyType(property, type) %> { static <%- evaluatedType(property) %> defaultValue() { return <%- defaultValue(property) %>; } diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index c3203f84e..cc6bfdde3 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -440,217 +441,292 @@ TransitionOptions LineLayer::getLinePatternTransition() const { using namespace conversion; optional LineLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + LineOpacity, + LineColor, + LineTranslate, + LineTranslateAnchor, + LineWidth, + LineGapWidth, + LineOffset, + LineBlur, + LineDasharray, + LinePattern, + LineOpacityTransition, + LineColorTransition, + LineTranslateTransition, + LineTranslateAnchorTransition, + LineWidthTransition, + LineGapWidthTransition, + LineOffsetTransition, + LineBlurTransition, + LineDasharrayTransition, + LinePatternTransition, + }; + + 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; - if (name == "line-opacity") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::LineOpacity || property == Property::LineWidth || property == Property::LineGapWidth || property == Property::LineOffset || property == Property::LineBlur) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setLineOpacity(*typedValue); - return nullopt; - } - if (name == "line-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::LineOpacity) { + setLineOpacity(*typedValue); + return nullopt; } - - setLineOpacityTransition(*transition); - return nullopt; + + if (property == Property::LineWidth) { + setLineWidth(*typedValue); + return nullopt; + } + + if (property == Property::LineGapWidth) { + setLineGapWidth(*typedValue); + return nullopt; + } + + if (property == Property::LineOffset) { + setLineOffset(*typedValue); + return nullopt; + } + + if (property == Property::LineBlur) { + setLineBlur(*typedValue); + return nullopt; + } + } - if (name == "line-color") { + if (property == Property::LineColor) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setLineColor(*typedValue); return nullopt; - } - if (name == "line-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineColorTransition(*transition); - return nullopt; + } - if (name == "line-translate") { + if (property == Property::LineTranslate) { Error error; optional>> typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setLineTranslate(*typedValue); return nullopt; - } - if (name == "line-translate-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineTranslateTransition(*transition); - return nullopt; + } - if (name == "line-translate-anchor") { + if (property == Property::LineTranslateAnchor) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setLineTranslateAnchor(*typedValue); return nullopt; - } - if (name == "line-translate-anchor-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineTranslateAnchorTransition(*transition); - return nullopt; + } - if (name == "line-width") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineWidth(*typedValue); - return nullopt; - } - if (name == "line-width-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineWidthTransition(*transition); - return nullopt; - } - - if (name == "line-gap-width") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineGapWidth(*typedValue); - return nullopt; - } - if (name == "line-gap-width-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineGapWidthTransition(*transition); - return nullopt; - } - - if (name == "line-offset") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineOffset(*typedValue); - return nullopt; - } - if (name == "line-offset-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineOffsetTransition(*transition); - return nullopt; - } - - if (name == "line-blur") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setLineBlur(*typedValue); - return nullopt; - } - if (name == "line-blur-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineBlurTransition(*transition); - return nullopt; - } - - if (name == "line-dasharray") { + if (property == Property::LineDasharray) { Error error; optional>> typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setLineDasharray(*typedValue); return nullopt; - } - if (name == "line-dasharray-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setLineDasharrayTransition(*transition); - return nullopt; + } - if (name == "line-pattern") { + if (property == Property::LinePattern) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setLinePattern(*typedValue); return nullopt; + } - if (name == "line-pattern-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::LineOpacityTransition) { + setLineOpacityTransition(*transition); + return nullopt; + } + + if (property == Property::LineColorTransition) { + setLineColorTransition(*transition); + return nullopt; + } + + if (property == Property::LineTranslateTransition) { + setLineTranslateTransition(*transition); + return nullopt; + } + + if (property == Property::LineTranslateAnchorTransition) { + setLineTranslateAnchorTransition(*transition); + return nullopt; + } + + if (property == Property::LineWidthTransition) { + setLineWidthTransition(*transition); + return nullopt; + } + + if (property == Property::LineGapWidthTransition) { + setLineGapWidthTransition(*transition); + return nullopt; + } + + if (property == Property::LineOffsetTransition) { + setLineOffsetTransition(*transition); + return nullopt; + } + + if (property == Property::LineBlurTransition) { + setLineBlurTransition(*transition); + return nullopt; + } + + if (property == Property::LineDasharrayTransition) { + setLineDasharrayTransition(*transition); + return nullopt; + } + + if (property == Property::LinePatternTransition) { setLinePatternTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -671,51 +747,92 @@ optional LineLayer::setLayoutProperty(const std::string& name, const Conv return nullopt; } + enum class Property { + Unknown, + LineCap, + LineJoin, + LineMiterLimit, + LineRoundLimit, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { - if (name == "line-cap") { + 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) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::LineCap) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setLineCap(*typedValue); return nullopt; + } - if (name == "line-join") { + if (property == Property::LineJoin) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setLineJoin(*typedValue); return nullopt; + } - if (name == "line-miter-limit") { + if (property == Property::LineMiterLimit || property == Property::LineRoundLimit) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - - setLineMiterLimit(*typedValue); - return nullopt; - } - - if (name == "line-round-limit") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::LineMiterLimit) { + setLineMiterLimit(*typedValue); + return nullopt; } - - setLineRoundLimit(*typedValue); - return nullopt; + + if (property == Property::LineRoundLimit) { + setLineRoundLimit(*typedValue); + return nullopt; + } + } + return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 0eba8ef88..da3f7f8a1 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -299,175 +300,220 @@ TransitionOptions RasterLayer::getRasterFadeDurationTransition() const { using namespace conversion; optional RasterLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + RasterOpacity, + RasterHueRotate, + RasterBrightnessMin, + RasterBrightnessMax, + RasterSaturation, + RasterContrast, + RasterResampling, + RasterFadeDuration, + RasterOpacityTransition, + RasterHueRotateTransition, + RasterBrightnessMinTransition, + RasterBrightnessMaxTransition, + RasterSaturationTransition, + RasterContrastTransition, + RasterResamplingTransition, + 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 (name == "raster-opacity") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::RasterOpacity || property == Property::RasterHueRotate || property == Property::RasterBrightnessMin || property == Property::RasterBrightnessMax || property == Property::RasterSaturation || property == Property::RasterContrast || property == Property::RasterFadeDuration) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - - setRasterOpacity(*typedValue); - return nullopt; - } - if (name == "raster-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; + + if (property == Property::RasterOpacity) { + setRasterOpacity(*typedValue); + return nullopt; } - - setRasterOpacityTransition(*transition); - return nullopt; + + if (property == Property::RasterHueRotate) { + setRasterHueRotate(*typedValue); + return nullopt; + } + + if (property == Property::RasterBrightnessMin) { + setRasterBrightnessMin(*typedValue); + return nullopt; + } + + if (property == Property::RasterBrightnessMax) { + setRasterBrightnessMax(*typedValue); + return nullopt; + } + + if (property == Property::RasterSaturation) { + setRasterSaturation(*typedValue); + return nullopt; + } + + if (property == Property::RasterContrast) { + setRasterContrast(*typedValue); + return nullopt; + } + + if (property == Property::RasterFadeDuration) { + setRasterFadeDuration(*typedValue); + return nullopt; + } + } - if (name == "raster-hue-rotate") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterHueRotate(*typedValue); - return nullopt; - } - if (name == "raster-hue-rotate-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setRasterHueRotateTransition(*transition); - return nullopt; - } - - if (name == "raster-brightness-min") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterBrightnessMin(*typedValue); - return nullopt; - } - if (name == "raster-brightness-min-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setRasterBrightnessMinTransition(*transition); - return nullopt; - } - - if (name == "raster-brightness-max") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterBrightnessMax(*typedValue); - return nullopt; - } - if (name == "raster-brightness-max-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setRasterBrightnessMaxTransition(*transition); - return nullopt; - } - - if (name == "raster-saturation") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterSaturation(*typedValue); - return nullopt; - } - if (name == "raster-saturation-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setRasterSaturationTransition(*transition); - return nullopt; - } - - if (name == "raster-contrast") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterContrast(*typedValue); - return nullopt; - } - if (name == "raster-contrast-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - - setRasterContrastTransition(*transition); - return nullopt; - } - - if (name == "raster-resampling") { + if (property == Property::RasterResampling) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setRasterResampling(*typedValue); return nullopt; + } - if (name == "raster-resampling-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::RasterOpacityTransition) { + setRasterOpacityTransition(*transition); + return nullopt; + } + + if (property == Property::RasterHueRotateTransition) { + setRasterHueRotateTransition(*transition); + return nullopt; + } + + if (property == Property::RasterBrightnessMinTransition) { + setRasterBrightnessMinTransition(*transition); + return nullopt; + } + + if (property == Property::RasterBrightnessMaxTransition) { + setRasterBrightnessMaxTransition(*transition); + return nullopt; + } + + if (property == Property::RasterSaturationTransition) { + setRasterSaturationTransition(*transition); + return nullopt; + } + + if (property == Property::RasterContrastTransition) { + setRasterContrastTransition(*transition); + return nullopt; + } + + if (property == Property::RasterResamplingTransition) { setRasterResamplingTransition(*transition); return nullopt; } - if (name == "raster-fade-duration") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setRasterFadeDuration(*typedValue); - return nullopt; - } - if (name == "raster-fade-duration-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::RasterFadeDurationTransition) { setRasterFadeDurationTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -488,7 +534,21 @@ optional RasterLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + 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 bb5b317a3..e7cba19ea 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -1060,301 +1061,372 @@ TransitionOptions SymbolLayer::getTextTranslateAnchorTransition() const { using namespace conversion; optional SymbolLayer::setPaintProperty(const std::string& name, const Convertible& value) { + enum class Property { + Unknown, + IconOpacity, + IconColor, + IconHaloColor, + IconHaloWidth, + IconHaloBlur, + IconTranslate, + IconTranslateAnchor, + TextOpacity, + TextColor, + TextHaloColor, + TextHaloWidth, + TextHaloBlur, + TextTranslate, + TextTranslateAnchor, + IconOpacityTransition, + IconColorTransition, + IconHaloColorTransition, + IconHaloWidthTransition, + IconHaloBlurTransition, + IconTranslateTransition, + IconTranslateAnchorTransition, + TextOpacityTransition, + TextColorTransition, + TextHaloColorTransition, + TextHaloWidthTransition, + TextHaloBlurTransition, + TextTranslateTransition, + 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 (name == "icon-opacity") { + } + + if (property == Property::Unknown) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::IconOpacity || property == Property::IconHaloWidth || property == Property::IconHaloBlur || property == Property::TextOpacity || property == Property::TextHaloWidth || property == Property::TextHaloBlur) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setIconOpacity(*typedValue); - return nullopt; + + if (property == Property::IconOpacity) { + setIconOpacity(*typedValue); + return nullopt; + } + + if (property == Property::IconHaloWidth) { + setIconHaloWidth(*typedValue); + return nullopt; + } + + if (property == Property::IconHaloBlur) { + setIconHaloBlur(*typedValue); + return nullopt; + } + + if (property == Property::TextOpacity) { + setTextOpacity(*typedValue); + return nullopt; + } + + if (property == Property::TextHaloWidth) { + setTextHaloWidth(*typedValue); + return nullopt; + } + + if (property == Property::TextHaloBlur) { + setTextHaloBlur(*typedValue); + return nullopt; + } + } - if (name == "icon-opacity-transition") { + + if (property == Property::IconColor || property == Property::IconHaloColor || property == Property::TextColor || property == Property::TextHaloColor) { Error error; - optional transition = convert(value, error); - if (!transition) { + optional> typedValue = convert>(value, error, true, false); + if (!typedValue) { return error; } + + if (property == Property::IconColor) { + setIconColor(*typedValue); + return nullopt; + } + + if (property == Property::IconHaloColor) { + setIconHaloColor(*typedValue); + return nullopt; + } + + if (property == Property::TextColor) { + setTextColor(*typedValue); + return nullopt; + } + + if (property == Property::TextHaloColor) { + setTextHaloColor(*typedValue); + return nullopt; + } + + } + + if (property == Property::IconTranslate || property == Property::TextTranslate) { + Error error; + optional>> typedValue = convert>>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconTranslate) { + setIconTranslate(*typedValue); + return nullopt; + } + + if (property == Property::TextTranslate) { + setTextTranslate(*typedValue); + return nullopt; + } + + } + + if (property == Property::IconTranslateAnchor || property == Property::TextTranslateAnchor) { + Error error; + optional> typedValue = convert>(value, error, false, false); + if (!typedValue) { + return error; + } + + if (property == Property::IconTranslateAnchor) { + setIconTranslateAnchor(*typedValue); + return nullopt; + } + + if (property == Property::TextTranslateAnchor) { + setTextTranslateAnchor(*typedValue); + return nullopt; + } + + } + + Error error; + optional transition = convert(value, error); + if (!transition) { + return error; + } + + if (property == Property::IconOpacityTransition) { setIconOpacityTransition(*transition); return nullopt; } - if (name == "icon-color") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setIconColor(*typedValue); - return nullopt; - } - if (name == "icon-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::IconColorTransition) { setIconColorTransition(*transition); return nullopt; } - if (name == "icon-halo-color") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setIconHaloColor(*typedValue); - return nullopt; - } - if (name == "icon-halo-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::IconHaloColorTransition) { setIconHaloColorTransition(*transition); return nullopt; } - if (name == "icon-halo-width") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setIconHaloWidth(*typedValue); - return nullopt; - } - if (name == "icon-halo-width-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::IconHaloWidthTransition) { setIconHaloWidthTransition(*transition); return nullopt; } - if (name == "icon-halo-blur") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setIconHaloBlur(*typedValue); - return nullopt; - } - if (name == "icon-halo-blur-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::IconHaloBlurTransition) { setIconHaloBlurTransition(*transition); return nullopt; } - if (name == "icon-translate") { - Error error; - optional>> typedValue = convert>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTranslate(*typedValue); - return nullopt; - } - if (name == "icon-translate-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::IconTranslateTransition) { setIconTranslateTransition(*transition); return nullopt; } - if (name == "icon-translate-anchor") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconTranslateAnchor(*typedValue); - return nullopt; - } - if (name == "icon-translate-anchor-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::IconTranslateAnchorTransition) { setIconTranslateAnchorTransition(*transition); return nullopt; } - if (name == "text-opacity") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextOpacity(*typedValue); - return nullopt; - } - if (name == "text-opacity-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextOpacityTransition) { setTextOpacityTransition(*transition); return nullopt; } - if (name == "text-color") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextColor(*typedValue); - return nullopt; - } - if (name == "text-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextColorTransition) { setTextColorTransition(*transition); return nullopt; } - if (name == "text-halo-color") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextHaloColor(*typedValue); - return nullopt; - } - if (name == "text-halo-color-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextHaloColorTransition) { setTextHaloColorTransition(*transition); return nullopt; } - if (name == "text-halo-width") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextHaloWidth(*typedValue); - return nullopt; - } - if (name == "text-halo-width-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextHaloWidthTransition) { setTextHaloWidthTransition(*transition); return nullopt; } - if (name == "text-halo-blur") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextHaloBlur(*typedValue); - return nullopt; - } - if (name == "text-halo-blur-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextHaloBlurTransition) { setTextHaloBlurTransition(*transition); return nullopt; } - if (name == "text-translate") { - Error error; - optional>> typedValue = convert>>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextTranslate(*typedValue); - return nullopt; - } - if (name == "text-translate-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextTranslateTransition) { setTextTranslateTransition(*transition); return nullopt; } - if (name == "text-translate-anchor") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextTranslateAnchor(*typedValue); - return nullopt; - } - if (name == "text-translate-anchor-transition") { - Error error; - optional transition = convert(value, error); - if (!transition) { - return error; - } - + if (property == Property::TextTranslateAnchorTransition) { setTextTranslateAnchorTransition(*transition); return nullopt; } + return Error { "layer doesn't support this property" }; } @@ -1375,403 +1447,558 @@ optional SymbolLayer::setLayoutProperty(const std::string& name, const Co return nullopt; } + enum class Property { + Unknown, + SymbolPlacement, + SymbolSpacing, + SymbolAvoidEdges, + IconAllowOverlap, + IconIgnorePlacement, + IconOptional, + IconRotationAlignment, + IconSize, + IconTextFit, + IconTextFitPadding, + IconImage, + IconRotate, + IconPadding, + IconKeepUpright, + IconOffset, + IconAnchor, + IconPitchAlignment, + TextPitchAlignment, + TextRotationAlignment, + TextField, + TextFont, + TextSize, + TextMaxWidth, + TextLineHeight, + TextLetterSpacing, + TextJustify, + TextAnchor, + TextMaxAngle, + TextRotate, + TextPadding, + TextKeepUpright, + TextTransform, + TextOffset, + TextAllowOverlap, + TextIgnorePlacement, + TextOptional, + }; + + Property property = Property::Unknown; + switch (util::hashFNV1a(name.c_str())) { - if (name == "symbol-placement") { + 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("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) { + return Error { "layer doesn't support this property" }; + } + + + if (property == Property::SymbolPlacement) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setSymbolPlacement(*typedValue); return nullopt; + } - if (name == "symbol-spacing") { + if (property == Property::SymbolSpacing || property == Property::IconPadding || property == Property::TextLineHeight || property == Property::TextMaxAngle || property == Property::TextPadding) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - - setSymbolSpacing(*typedValue); - return nullopt; + + if (property == Property::SymbolSpacing) { + setSymbolSpacing(*typedValue); + return nullopt; + } + + if (property == Property::IconPadding) { + setIconPadding(*typedValue); + return nullopt; + } + + if (property == Property::TextLineHeight) { + setTextLineHeight(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxAngle) { + setTextMaxAngle(*typedValue); + return nullopt; + } + + if (property == Property::TextPadding) { + setTextPadding(*typedValue); + return nullopt; + } + } - if (name == "symbol-avoid-edges") { + if (property == Property::SymbolAvoidEdges || property == Property::IconAllowOverlap || property == Property::IconIgnorePlacement || property == Property::IconOptional || property == Property::IconKeepUpright || property == Property::TextKeepUpright || property == Property::TextAllowOverlap || property == Property::TextIgnorePlacement || property == Property::TextOptional) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - - setSymbolAvoidEdges(*typedValue); - return nullopt; - } - - if (name == "icon-allow-overlap") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::SymbolAvoidEdges) { + setSymbolAvoidEdges(*typedValue); + return nullopt; } - - setIconAllowOverlap(*typedValue); - return nullopt; - } - - if (name == "icon-ignore-placement") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::IconAllowOverlap) { + setIconAllowOverlap(*typedValue); + return nullopt; } - - setIconIgnorePlacement(*typedValue); - return nullopt; - } - - if (name == "icon-optional") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::IconIgnorePlacement) { + setIconIgnorePlacement(*typedValue); + return nullopt; } - - setIconOptional(*typedValue); - return nullopt; + + if (property == Property::IconOptional) { + setIconOptional(*typedValue); + return nullopt; + } + + if (property == Property::IconKeepUpright) { + setIconKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::TextKeepUpright) { + setTextKeepUpright(*typedValue); + return nullopt; + } + + if (property == Property::TextAllowOverlap) { + setTextAllowOverlap(*typedValue); + return nullopt; + } + + if (property == Property::TextIgnorePlacement) { + setTextIgnorePlacement(*typedValue); + return nullopt; + } + + if (property == Property::TextOptional) { + setTextOptional(*typedValue); + return nullopt; + } + } - if (name == "icon-rotation-alignment") { + if (property == Property::IconRotationAlignment || property == Property::IconPitchAlignment || property == Property::TextPitchAlignment || property == Property::TextRotationAlignment) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - - setIconRotationAlignment(*typedValue); - return nullopt; + + if (property == Property::IconRotationAlignment) { + setIconRotationAlignment(*typedValue); + return nullopt; + } + + if (property == Property::IconPitchAlignment) { + setIconPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextPitchAlignment) { + setTextPitchAlignment(*typedValue); + return nullopt; + } + + if (property == Property::TextRotationAlignment) { + setTextRotationAlignment(*typedValue); + return nullopt; + } + } - if (name == "icon-size") { + if (property == Property::IconSize || property == Property::IconRotate || property == Property::TextSize || property == Property::TextMaxWidth || property == Property::TextLetterSpacing || property == Property::TextRotate) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setIconSize(*typedValue); - return nullopt; + + if (property == Property::IconSize) { + setIconSize(*typedValue); + return nullopt; + } + + if (property == Property::IconRotate) { + setIconRotate(*typedValue); + return nullopt; + } + + if (property == Property::TextSize) { + setTextSize(*typedValue); + return nullopt; + } + + if (property == Property::TextMaxWidth) { + setTextMaxWidth(*typedValue); + return nullopt; + } + + if (property == Property::TextLetterSpacing) { + setTextLetterSpacing(*typedValue); + return nullopt; + } + + if (property == Property::TextRotate) { + setTextRotate(*typedValue); + return nullopt; + } + } - if (name == "icon-text-fit") { + if (property == Property::IconTextFit) { Error error; optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } - + setIconTextFit(*typedValue); return nullopt; + } - if (name == "icon-text-fit-padding") { + if (property == Property::IconTextFitPadding) { Error error; optional>> typedValue = convert>>(value, error, false, false); if (!typedValue) { return error; } - + setIconTextFitPadding(*typedValue); return nullopt; + } - if (name == "icon-image") { + if (property == Property::IconImage || property == Property::TextField) { Error error; optional> typedValue = convert>(value, error, true, true); if (!typedValue) { return error; } - - setIconImage(*typedValue); - return nullopt; - } - - if (name == "icon-rotate") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; + + if (property == Property::IconImage) { + setIconImage(*typedValue); + return nullopt; } - - setIconRotate(*typedValue); - return nullopt; - } - - if (name == "icon-padding") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::TextField) { + setTextField(*typedValue); + return nullopt; } - - setIconPadding(*typedValue); - return nullopt; + } - if (name == "icon-keep-upright") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setIconKeepUpright(*typedValue); - return nullopt; - } - - if (name == "icon-offset") { + if (property == Property::IconOffset || property == Property::TextOffset) { Error error; optional>> typedValue = convert>>(value, error, true, false); if (!typedValue) { return error; } - - setIconOffset(*typedValue); - return nullopt; + + if (property == Property::IconOffset) { + setIconOffset(*typedValue); + return nullopt; + } + + if (property == Property::TextOffset) { + setTextOffset(*typedValue); + return nullopt; + } + } - if (name == "icon-anchor") { + if (property == Property::IconAnchor || property == Property::TextAnchor) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - - setIconAnchor(*typedValue); - return nullopt; - } - - if (name == "icon-pitch-alignment") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::IconAnchor) { + setIconAnchor(*typedValue); + return nullopt; } - - setIconPitchAlignment(*typedValue); - return nullopt; - } - - if (name == "text-pitch-alignment") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; + + if (property == Property::TextAnchor) { + setTextAnchor(*typedValue); + return nullopt; } - - setTextPitchAlignment(*typedValue); - return nullopt; + } - if (name == "text-rotation-alignment") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextRotationAlignment(*typedValue); - return nullopt; - } - - if (name == "text-field") { - Error error; - optional> typedValue = convert>(value, error, true, true); - if (!typedValue) { - return error; - } - - setTextField(*typedValue); - return nullopt; - } - - if (name == "text-font") { + if (property == Property::TextFont) { Error error; optional>> typedValue = convert>>(value, error, true, false); if (!typedValue) { return error; } - + setTextFont(*typedValue); return nullopt; + } - if (name == "text-size") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextSize(*typedValue); - return nullopt; - } - - if (name == "text-max-width") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextMaxWidth(*typedValue); - return nullopt; - } - - if (name == "text-line-height") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextLineHeight(*typedValue); - return nullopt; - } - - if (name == "text-letter-spacing") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextLetterSpacing(*typedValue); - return nullopt; - } - - if (name == "text-justify") { + if (property == Property::TextJustify) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setTextJustify(*typedValue); return nullopt; + } - if (name == "text-anchor") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextAnchor(*typedValue); - return nullopt; - } - - if (name == "text-max-angle") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextMaxAngle(*typedValue); - return nullopt; - } - - if (name == "text-rotate") { - Error error; - optional> typedValue = convert>(value, error, true, false); - if (!typedValue) { - return error; - } - - setTextRotate(*typedValue); - return nullopt; - } - - if (name == "text-padding") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextPadding(*typedValue); - return nullopt; - } - - if (name == "text-keep-upright") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextKeepUpright(*typedValue); - return nullopt; - } - - if (name == "text-transform") { + if (property == Property::TextTransform) { Error error; optional> typedValue = convert>(value, error, true, false); if (!typedValue) { return error; } - + setTextTransform(*typedValue); return nullopt; + } - if (name == "text-offset") { - Error error; - optional>> typedValue = convert>>(value, error, true, false); - if (!typedValue) { - return error; - } - setTextOffset(*typedValue); - return nullopt; - } - - if (name == "text-allow-overlap") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextAllowOverlap(*typedValue); - return nullopt; - } - - if (name == "text-ignore-placement") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextIgnorePlacement(*typedValue); - return nullopt; - } - - if (name == "text-optional") { - Error error; - optional> typedValue = convert>(value, error, false, false); - if (!typedValue) { - return error; - } - - setTextOptional(*typedValue); - return nullopt; - } - return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/util/fnv_hash.hpp b/src/mbgl/util/fnv_hash.hpp new file mode 100644 index 000000000..87d4661c5 --- /dev/null +++ b/src/mbgl/util/fnv_hash.hpp @@ -0,0 +1,11 @@ +#pragma once + +namespace mbgl { +namespace util { + +inline constexpr uint64_t hashFNV1a(const char * str, uint64_t value = 0xcbf29ce484222325) { + return str[0] ? hashFNV1a(str + 1, (value ^ uint64_t(str[0])) * 0x100000001b3) : value; +} + +} // end namespace util +} // end namespace mbgl