[core] Optimize generated set{Paint,Layout}Property code
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include <mbgl/style/conversion/property_value.hpp>
|
||||
#include <mbgl/style/conversion/transition_options.hpp>
|
||||
#include <mbgl/style/conversion/json.hpp>
|
||||
#include <mbgl/util/fnv_hash.hpp>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -402,238 +403,316 @@ TransitionOptions CircleLayer::getCircleStrokeOpacityTransition() const {
|
||||
using namespace conversion;
|
||||
|
||||
optional<Error> 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<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleRadius(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-radius-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(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<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleColor(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-color-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(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<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleBlur(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-blur-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleBlurTransition(*transition);
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
if (name == "circle-opacity") {
|
||||
Error error;
|
||||
optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleOpacity(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-opacity-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleOpacityTransition(*transition);
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
if (name == "circle-translate") {
|
||||
if (property == Property::CircleTranslate) {
|
||||
Error error;
|
||||
optional<PropertyValue<std::array<float, 2>>> typedValue = convert<PropertyValue<std::array<float, 2>>>(value, error, false, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
setCircleTranslate(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-translate-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleTranslateTransition(*transition);
|
||||
return nullopt;
|
||||
|
||||
}
|
||||
|
||||
if (name == "circle-translate-anchor") {
|
||||
if (property == Property::CircleTranslateAnchor) {
|
||||
Error error;
|
||||
optional<PropertyValue<TranslateAnchorType>> typedValue = convert<PropertyValue<TranslateAnchorType>>(value, error, false, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
setCircleTranslateAnchor(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-translate-anchor-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleTranslateAnchorTransition(*transition);
|
||||
return nullopt;
|
||||
|
||||
}
|
||||
|
||||
if (name == "circle-pitch-scale") {
|
||||
if (property == Property::CirclePitchScale) {
|
||||
Error error;
|
||||
optional<PropertyValue<CirclePitchScaleType>> typedValue = convert<PropertyValue<CirclePitchScaleType>>(value, error, false, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
setCirclePitchScale(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-pitch-scale-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCirclePitchScaleTransition(*transition);
|
||||
return nullopt;
|
||||
|
||||
}
|
||||
|
||||
if (name == "circle-pitch-alignment") {
|
||||
if (property == Property::CirclePitchAlignment) {
|
||||
Error error;
|
||||
optional<PropertyValue<AlignmentType>> typedValue = convert<PropertyValue<AlignmentType>>(value, error, false, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
setCirclePitchAlignment(*typedValue);
|
||||
return nullopt;
|
||||
|
||||
}
|
||||
if (name == "circle-pitch-alignment-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(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<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleStrokeWidth(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-stroke-width-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (property == Property::CircleStrokeWidthTransition) {
|
||||
setCircleStrokeWidthTransition(*transition);
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
if (name == "circle-stroke-color") {
|
||||
Error error;
|
||||
optional<PropertyValue<Color>> typedValue = convert<PropertyValue<Color>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleStrokeColor(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-stroke-color-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
if (property == Property::CircleStrokeColorTransition) {
|
||||
setCircleStrokeColorTransition(*transition);
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
if (name == "circle-stroke-opacity") {
|
||||
Error error;
|
||||
optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setCircleStrokeOpacity(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "circle-stroke-opacity-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(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<Error> 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" };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user