[core] Simplify Value conversions
Use a single template function for each of {to,from}ExpressionValue, always dispatching to ValueConverter.
Remove unused ValueConverter::ExpressionType typedefs.
This commit is contained in:
@@ -241,27 +241,6 @@ optional<T> ValueConverter<T, std::enable_if_t< std::is_enum<T>::value >>::fromE
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Value toExpressionValue(const Value& v) {
|
||||
return v;
|
||||
}
|
||||
|
||||
template <typename T, typename Enable>
|
||||
Value toExpressionValue(const T& value) {
|
||||
return ValueConverter<T>::toExpressionValue(value);
|
||||
}
|
||||
|
||||
optional<Value> fromExpressionValue(const Value& v) {
|
||||
return optional<Value>(v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::enable_if_t< !std::is_convertible<T, Value>::value,
|
||||
optional<T>> fromExpressionValue(const Value& v)
|
||||
{
|
||||
return ValueConverter<T>::fromExpressionValue(v);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
type::Type valueTypeToExpressionType() {
|
||||
return ValueConverter<T>::expressionType();
|
||||
@@ -281,90 +260,64 @@ template <> type::Type valueTypeToExpressionType<std::vector<Value>>() { return
|
||||
template <> type::Type valueTypeToExpressionType<type::ErrorType>() { return type::Error; }
|
||||
|
||||
|
||||
template Value toExpressionValue(const mbgl::Value&);
|
||||
template optional<mbgl::Value> fromExpressionValue<mbgl::Value>(const Value&);
|
||||
|
||||
// for to_rgba expression
|
||||
template type::Type valueTypeToExpressionType<std::array<double, 4>>();
|
||||
template optional<std::array<double, 4>> fromExpressionValue<std::array<double, 4>>(const Value&);
|
||||
template Value toExpressionValue(const std::array<double, 4>&);
|
||||
template struct ValueConverter<std::array<double, 4>>;
|
||||
|
||||
// layout/paint property types
|
||||
template type::Type valueTypeToExpressionType<float>();
|
||||
template optional<float> fromExpressionValue<float>(const Value&);
|
||||
template Value toExpressionValue(const float&);
|
||||
template type::Type valueTypeToExpressionType<Position>();
|
||||
|
||||
template type::Type valueTypeToExpressionType<std::array<float, 2>>();
|
||||
template optional<std::array<float, 2>> fromExpressionValue<std::array<float, 2>>(const Value&);
|
||||
template Value toExpressionValue(const std::array<float, 2>&);
|
||||
template struct ValueConverter<std::array<float, 2>>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<std::array<float, 4>>();
|
||||
template optional<std::array<float, 4>> fromExpressionValue<std::array<float, 4>>(const Value&);
|
||||
template Value toExpressionValue(const std::array<float, 4>&);
|
||||
template struct ValueConverter<std::array<float, 4>>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<std::vector<float>>();
|
||||
template optional<std::vector<float>> fromExpressionValue<std::vector<float>>(const Value&);
|
||||
template Value toExpressionValue(const std::vector<float>&);
|
||||
template struct ValueConverter<std::vector<float>>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<std::vector<std::string>>();
|
||||
template optional<std::vector<std::string>> fromExpressionValue<std::vector<std::string>>(const Value&);
|
||||
template Value toExpressionValue(const std::vector<std::string>&);
|
||||
template struct ValueConverter<std::vector<std::string>>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<AlignmentType>();
|
||||
template optional<AlignmentType> fromExpressionValue<AlignmentType>(const Value&);
|
||||
template Value toExpressionValue(const AlignmentType&);
|
||||
template struct ValueConverter<AlignmentType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<CirclePitchScaleType>();
|
||||
template optional<CirclePitchScaleType> fromExpressionValue<CirclePitchScaleType>(const Value&);
|
||||
template Value toExpressionValue(const CirclePitchScaleType&);
|
||||
template struct ValueConverter<CirclePitchScaleType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<IconTextFitType>();
|
||||
template optional<IconTextFitType> fromExpressionValue<IconTextFitType>(const Value&);
|
||||
template Value toExpressionValue(const IconTextFitType&);
|
||||
template struct ValueConverter<IconTextFitType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<LineCapType>();
|
||||
template optional<LineCapType> fromExpressionValue<LineCapType>(const Value&);
|
||||
template Value toExpressionValue(const LineCapType&);
|
||||
template struct ValueConverter<LineCapType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<LineJoinType>();
|
||||
template optional<LineJoinType> fromExpressionValue<LineJoinType>(const Value&);
|
||||
template Value toExpressionValue(const LineJoinType&);
|
||||
template struct ValueConverter<LineJoinType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<SymbolPlacementType>();
|
||||
template optional<SymbolPlacementType> fromExpressionValue<SymbolPlacementType>(const Value&);
|
||||
template Value toExpressionValue(const SymbolPlacementType&);
|
||||
template struct ValueConverter<SymbolPlacementType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<SymbolAnchorType>();
|
||||
template optional<SymbolAnchorType> fromExpressionValue<SymbolAnchorType>(const Value&);
|
||||
template Value toExpressionValue(const SymbolAnchorType&);
|
||||
template struct ValueConverter<SymbolAnchorType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<TextJustifyType>();
|
||||
template optional<TextJustifyType> fromExpressionValue<TextJustifyType>(const Value&);
|
||||
template Value toExpressionValue(const TextJustifyType&);
|
||||
template struct ValueConverter<TextJustifyType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<TextTransformType>();
|
||||
template optional<TextTransformType> fromExpressionValue<TextTransformType>(const Value&);
|
||||
template Value toExpressionValue(const TextTransformType&);
|
||||
template struct ValueConverter<TextTransformType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<TranslateAnchorType>();
|
||||
template optional<TranslateAnchorType> fromExpressionValue<TranslateAnchorType>(const Value&);
|
||||
template Value toExpressionValue(const TranslateAnchorType&);
|
||||
template struct ValueConverter<TranslateAnchorType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<RasterResamplingType>();
|
||||
template optional<RasterResamplingType> fromExpressionValue<RasterResamplingType>(const Value&);
|
||||
template Value toExpressionValue(const RasterResamplingType&);
|
||||
template struct ValueConverter<RasterResamplingType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<HillshadeIlluminationAnchorType>();
|
||||
template optional<HillshadeIlluminationAnchorType> fromExpressionValue<HillshadeIlluminationAnchorType>(const Value&);
|
||||
template Value toExpressionValue(const HillshadeIlluminationAnchorType&);
|
||||
template struct ValueConverter<HillshadeIlluminationAnchorType>;
|
||||
|
||||
template type::Type valueTypeToExpressionType<LightAnchorType>();
|
||||
template optional<LightAnchorType> fromExpressionValue<LightAnchorType>(const Value&);
|
||||
template Value toExpressionValue(const LightAnchorType&);
|
||||
|
||||
template type::Type valueTypeToExpressionType<Position>();
|
||||
template optional<Position> fromExpressionValue<Position>(const Value&);
|
||||
template Value toExpressionValue(const Position&);
|
||||
template struct ValueConverter<LightAnchorType>;
|
||||
|
||||
} // namespace expression
|
||||
} // namespace style
|
||||
|
||||
Reference in New Issue
Block a user