[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 {
|
||||
@@ -242,112 +243,163 @@ TransitionOptions HeatmapLayer::getHeatmapOpacityTransition() const {
|
||||
using namespace conversion;
|
||||
|
||||
optional<Error> 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<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setHeatmapRadius(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "heatmap-radius-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(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<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, true, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setHeatmapWeight(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "heatmap-weight-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(value, error);
|
||||
if (!transition) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setHeatmapWeightTransition(*transition);
|
||||
return nullopt;
|
||||
}
|
||||
|
||||
if (name == "heatmap-intensity") {
|
||||
if (property == Property::HeatmapIntensity || property == Property::HeatmapOpacity) {
|
||||
Error error;
|
||||
optional<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setHeatmapIntensity(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "heatmap-intensity-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(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<ColorRampPropertyValue> typedValue = convert<ColorRampPropertyValue>(value, error, false, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
setHeatmapColor(*typedValue);
|
||||
return nullopt;
|
||||
|
||||
}
|
||||
if (name == "heatmap-color-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::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<PropertyValue<float>> typedValue = convert<PropertyValue<float>>(value, error, false, false);
|
||||
if (!typedValue) {
|
||||
return error;
|
||||
}
|
||||
|
||||
setHeatmapOpacity(*typedValue);
|
||||
return nullopt;
|
||||
}
|
||||
if (name == "heatmap-opacity-transition") {
|
||||
Error error;
|
||||
optional<TransitionOptions> transition = convert<TransitionOptions>(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<Error> 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" };
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user