Use std::optional instead of mbgl::optional (#911)
This commit is contained in:
@@ -87,90 +87,90 @@ std::unique_ptr<Expression> convertTokenStringToExpression(const std::string& so
|
||||
}
|
||||
|
||||
template <class T>
|
||||
optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) {
|
||||
std::optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) {
|
||||
auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType<T>(), value, error, convertTokens);
|
||||
if (!expression) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<T> defaultValue{};
|
||||
std::optional<T> defaultValue{};
|
||||
|
||||
auto defaultValueValue = objectMember(value, "default");
|
||||
if (defaultValueValue) {
|
||||
defaultValue = convert<T>(*defaultValueValue, error);
|
||||
if (!defaultValue) {
|
||||
error.message = R"(wrong type for "default": )" + error.message;
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
return PropertyExpression<T>(std::move(*expression), defaultValue);
|
||||
}
|
||||
|
||||
template optional<PropertyExpression<AlignmentType>>
|
||||
template std::optional<PropertyExpression<AlignmentType>>
|
||||
convertFunctionToExpression<AlignmentType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<bool>>
|
||||
template std::optional<PropertyExpression<bool>>
|
||||
convertFunctionToExpression<bool>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<CirclePitchScaleType>>
|
||||
template std::optional<PropertyExpression<CirclePitchScaleType>>
|
||||
convertFunctionToExpression<CirclePitchScaleType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<float>>
|
||||
template std::optional<PropertyExpression<float>>
|
||||
convertFunctionToExpression<float>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<HillshadeIlluminationAnchorType>>
|
||||
template std::optional<PropertyExpression<HillshadeIlluminationAnchorType>>
|
||||
convertFunctionToExpression<HillshadeIlluminationAnchorType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<IconTextFitType>>
|
||||
template std::optional<PropertyExpression<IconTextFitType>>
|
||||
convertFunctionToExpression<IconTextFitType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<LightAnchorType>>
|
||||
template std::optional<PropertyExpression<LightAnchorType>>
|
||||
convertFunctionToExpression<LightAnchorType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<LineCapType>>
|
||||
template std::optional<PropertyExpression<LineCapType>>
|
||||
convertFunctionToExpression<LineCapType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<LineJoinType>>
|
||||
template std::optional<PropertyExpression<LineJoinType>>
|
||||
convertFunctionToExpression<LineJoinType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<Color>>
|
||||
template std::optional<PropertyExpression<Color>>
|
||||
convertFunctionToExpression<Color>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<Position>>
|
||||
template std::optional<PropertyExpression<Position>>
|
||||
convertFunctionToExpression<Position>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<RasterResamplingType>>
|
||||
template std::optional<PropertyExpression<RasterResamplingType>>
|
||||
convertFunctionToExpression<RasterResamplingType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<std::array<float, 2>>>
|
||||
template std::optional<PropertyExpression<std::array<float, 2>>>
|
||||
convertFunctionToExpression<std::array<float, 2>>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<std::array<float, 4>>>
|
||||
template std::optional<PropertyExpression<std::array<float, 4>>>
|
||||
convertFunctionToExpression<std::array<float, 4>>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<std::string>>
|
||||
template std::optional<PropertyExpression<std::string>>
|
||||
convertFunctionToExpression<std::string>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<std::vector<float>>>
|
||||
template std::optional<PropertyExpression<std::vector<float>>>
|
||||
convertFunctionToExpression<std::vector<float>>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<std::vector<std::string>>>
|
||||
template std::optional<PropertyExpression<std::vector<std::string>>>
|
||||
convertFunctionToExpression<std::vector<std::string>>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<SymbolAnchorType>>
|
||||
template std::optional<PropertyExpression<SymbolAnchorType>>
|
||||
convertFunctionToExpression<SymbolAnchorType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<std::vector<TextVariableAnchorType>>>
|
||||
template std::optional<PropertyExpression<std::vector<TextVariableAnchorType>>>
|
||||
convertFunctionToExpression<std::vector<TextVariableAnchorType>>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<SymbolPlacementType>>
|
||||
template std::optional<PropertyExpression<SymbolPlacementType>>
|
||||
convertFunctionToExpression<SymbolPlacementType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<SymbolZOrderType>>
|
||||
template std::optional<PropertyExpression<SymbolZOrderType>>
|
||||
convertFunctionToExpression<SymbolZOrderType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<TextJustifyType>>
|
||||
template std::optional<PropertyExpression<TextJustifyType>>
|
||||
convertFunctionToExpression<TextJustifyType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<TextTransformType>>
|
||||
template std::optional<PropertyExpression<TextTransformType>>
|
||||
convertFunctionToExpression<TextTransformType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<TranslateAnchorType>>
|
||||
template std::optional<PropertyExpression<TranslateAnchorType>>
|
||||
convertFunctionToExpression<TranslateAnchorType>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<Formatted>>
|
||||
template std::optional<PropertyExpression<Formatted>>
|
||||
convertFunctionToExpression<Formatted>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<std::vector<TextWritingModeType>>>
|
||||
template std::optional<PropertyExpression<std::vector<TextWritingModeType>>>
|
||||
convertFunctionToExpression<std::vector<TextWritingModeType>>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<Image>> convertFunctionToExpression<Image>(const Convertible&, Error&, bool);
|
||||
template optional<PropertyExpression<Rotation>> convertFunctionToExpression<Rotation>(const Convertible&, Error&, bool);
|
||||
template std::optional<PropertyExpression<Image>> convertFunctionToExpression<Image>(const Convertible&, Error&, bool);
|
||||
template std::optional<PropertyExpression<Rotation>> convertFunctionToExpression<Rotation>(const Convertible&, Error&, bool);
|
||||
|
||||
// Ad-hoc Converters for double and int64_t. We should replace float with double wholesale,
|
||||
// and promote the int64_t Converter to general use (and it should check that the input is
|
||||
// an integer).
|
||||
template <>
|
||||
struct Converter<double> {
|
||||
optional<double> operator()(const Convertible& value, Error& error) const {
|
||||
std::optional<double> operator()(const Convertible& value, Error& error) const {
|
||||
auto converted = convert<float>(value, error);
|
||||
if (!converted) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return *converted;
|
||||
}
|
||||
@@ -178,10 +178,10 @@ struct Converter<double> {
|
||||
|
||||
template <>
|
||||
struct Converter<int64_t> {
|
||||
optional<int64_t> operator()(const Convertible& value, Error& error) const {
|
||||
std::optional<int64_t> operator()(const Convertible& value, Error& error) const {
|
||||
auto converted = convert<float>(value, error);
|
||||
if (!converted) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return static_cast<int64_t>(*converted);
|
||||
}
|
||||
@@ -212,135 +212,135 @@ static bool interpolatable(type::Type type) {
|
||||
);
|
||||
}
|
||||
|
||||
static optional<std::unique_ptr<Expression>> convertLiteral(type::Type type, const Convertible& value, Error& error, bool convertTokens = false) {
|
||||
static std::optional<std::unique_ptr<Expression>> convertLiteral(type::Type type, const Convertible& value, Error& error, bool convertTokens = false) {
|
||||
return type.match(
|
||||
[&](const type::NumberType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::NumberType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
auto result = convert<float>(value, error);
|
||||
if (!result) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return literal(static_cast<double>(*result));
|
||||
},
|
||||
[&](const type::BooleanType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::BooleanType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
auto result = convert<bool>(value, error);
|
||||
if (!result) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return literal(*result);
|
||||
},
|
||||
[&](const type::StringType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::StringType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
auto result = convert<std::string>(value, error);
|
||||
if (!result) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return convertTokens ? convertTokenStringToExpression(*result) : literal(*result);
|
||||
},
|
||||
[&](const type::ColorType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::ColorType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
auto result = convert<Color>(value, error);
|
||||
if (!result) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return literal(*result);
|
||||
},
|
||||
[&](const type::Array& array) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::Array& array) -> std::optional<std::unique_ptr<Expression>> {
|
||||
if (!isArray(value)) {
|
||||
error.message = "value must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
if (array.N && arrayLength(value) != *array.N) {
|
||||
error.message = "value must be an array of length " + util::toString(*array.N);
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return array.itemType.match(
|
||||
[&] (const type::NumberType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&] (const type::NumberType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
std::vector<expression::Value> result;
|
||||
result.reserve(arrayLength(value));
|
||||
for (std::size_t i = 0; i < arrayLength(value); ++i) {
|
||||
optional<float> number = toNumber(arrayMember(value, i));
|
||||
std::optional<float> number = toNumber(arrayMember(value, i));
|
||||
if (!number) {
|
||||
error.message = "value must be an array of numbers";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
result.emplace_back(static_cast<double>(*number));
|
||||
}
|
||||
return literal(result);
|
||||
},
|
||||
[&] (const type::StringType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&] (const type::StringType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
std::vector<expression::Value> result;
|
||||
result.reserve(arrayLength(value));
|
||||
for (std::size_t i = 0; i < arrayLength(value); ++i) {
|
||||
optional<std::string> string = toString(arrayMember(value, i));
|
||||
std::optional<std::string> string = toString(arrayMember(value, i));
|
||||
if (!string) {
|
||||
error.message = "value must be an array of strings";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
result.emplace_back(*string);
|
||||
}
|
||||
return literal(result);
|
||||
},
|
||||
[&] (const auto&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&] (const auto&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
);
|
||||
},
|
||||
[&](const type::NullType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::NullType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
},
|
||||
[&](const type::ObjectType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::ObjectType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
},
|
||||
[&](const type::ErrorType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::ErrorType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
},
|
||||
[&](const type::ValueType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::ValueType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
},
|
||||
[&](const type::CollatorType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::CollatorType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
},
|
||||
[&](const type::FormattedType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::FormattedType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
auto result = convert<std::string>(value, error);
|
||||
if (!result) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return convertTokens ?
|
||||
convertTokenStringToFormatExpression(*result) :
|
||||
literal(Formatted(result->c_str()));
|
||||
},
|
||||
[&](const type::ImageType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::ImageType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
auto result = convert<std::string>(value, error);
|
||||
if (!result) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return convertTokens ? std::make_unique<ImageExpression>(convertTokenStringToImageExpression(*result))
|
||||
: literal(Image(result->c_str()));
|
||||
});
|
||||
}
|
||||
|
||||
static optional<std::map<double, std::unique_ptr<Expression>>> convertStops(const type::Type& type,
|
||||
static std::optional<std::map<double, std::unique_ptr<Expression>>> convertStops(const type::Type& type,
|
||||
const Convertible& value,
|
||||
Error& error,
|
||||
bool convertTokens) {
|
||||
auto stopsValue = objectMember(value, "stops");
|
||||
if (!stopsValue) {
|
||||
error.message = "function value must specify stops";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!isArray(*stopsValue)) {
|
||||
error.message = "function stops must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(*stopsValue) == 0) {
|
||||
error.message = "function must have at least one stop";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::map<double, std::unique_ptr<Expression>> stops;
|
||||
@@ -349,22 +349,22 @@ static optional<std::map<double, std::unique_ptr<Expression>>> convertStops(cons
|
||||
|
||||
if (!isArray(stopValue)) {
|
||||
error.message = "function stop must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(stopValue) != 2) {
|
||||
error.message = "function stop must have two elements";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<float> t = convert<float>(arrayMember(stopValue, 0), error);
|
||||
std::optional<float> t = convert<float>(arrayMember(stopValue, 0), error);
|
||||
if (!t) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<std::unique_ptr<Expression>> e = convertLiteral(type, arrayMember(stopValue, 1), error, convertTokens);
|
||||
std::optional<std::unique_ptr<Expression>> e = convertLiteral(type, arrayMember(stopValue, 1), error, convertTokens);
|
||||
if (!e) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
stops.emplace(*t, std::move(*e));
|
||||
@@ -385,23 +385,23 @@ static void omitFirstStop(std::map<double, std::unique_ptr<Expression>>& stops)
|
||||
}
|
||||
|
||||
template <class T>
|
||||
optional<std::map<T, std::unique_ptr<Expression>>> convertBranches(const type::Type& type,
|
||||
std::optional<std::map<T, std::unique_ptr<Expression>>> convertBranches(const type::Type& type,
|
||||
const Convertible& value,
|
||||
Error& error) {
|
||||
auto stopsValue = objectMember(value, "stops");
|
||||
if (!stopsValue) {
|
||||
error.message = "function value must specify stops";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!isArray(*stopsValue)) {
|
||||
error.message = "function stops must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(*stopsValue) == 0) {
|
||||
error.message = "function must have at least one stop";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
std::map<T, std::unique_ptr<Expression>> stops;
|
||||
@@ -410,22 +410,22 @@ optional<std::map<T, std::unique_ptr<Expression>>> convertBranches(const type::T
|
||||
|
||||
if (!isArray(stopValue)) {
|
||||
error.message = "function stop must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(stopValue) != 2) {
|
||||
error.message = "function stop must have two elements";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<T> t = convert<T>(arrayMember(stopValue, 0), error);
|
||||
std::optional<T> t = convert<T>(arrayMember(stopValue, 0), error);
|
||||
if (!t) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<std::unique_ptr<Expression>> e = convertLiteral(type, arrayMember(stopValue, 1), error);
|
||||
std::optional<std::unique_ptr<Expression>> e = convertLiteral(type, arrayMember(stopValue, 1), error);
|
||||
if (!e) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
stops.emplace(*t, std::move(*e));
|
||||
@@ -434,7 +434,7 @@ optional<std::map<T, std::unique_ptr<Expression>>> convertBranches(const type::T
|
||||
return { std::move(stops) };
|
||||
}
|
||||
|
||||
static optional<double> convertBase(const Convertible& value, Error& error) {
|
||||
static std::optional<double> convertBase(const Convertible& value, Error& error) {
|
||||
auto baseValue = objectMember(value, "base");
|
||||
|
||||
if (!baseValue) {
|
||||
@@ -444,7 +444,7 @@ static optional<double> convertBase(const Convertible& value, Error& error) {
|
||||
auto base = toNumber(*baseValue);
|
||||
if (!base) {
|
||||
error.message = "function base must be a number";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return *base;
|
||||
@@ -518,7 +518,7 @@ static std::unique_ptr<Expression> numberOrDefault(const type::Type& type,
|
||||
return std::make_unique<Case>(type, std::move(branches), std::move(def));
|
||||
}
|
||||
|
||||
static optional<std::unique_ptr<Expression>> convertIntervalFunction(
|
||||
static std::optional<std::unique_ptr<Expression>> convertIntervalFunction(
|
||||
const type::Type& type,
|
||||
const Convertible& value,
|
||||
Error& error,
|
||||
@@ -527,7 +527,7 @@ static optional<std::unique_ptr<Expression>> convertIntervalFunction(
|
||||
bool convertTokens = false) {
|
||||
auto stops = convertStops(type, value, error, convertTokens);
|
||||
if (!stops) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
omitFirstStop(*stops);
|
||||
|
||||
@@ -537,7 +537,7 @@ static optional<std::unique_ptr<Expression>> convertIntervalFunction(
|
||||
std::move(def));
|
||||
}
|
||||
|
||||
static optional<std::unique_ptr<Expression>> convertExponentialFunction(
|
||||
static std::optional<std::unique_ptr<Expression>> convertExponentialFunction(
|
||||
const type::Type& type,
|
||||
const Convertible& value,
|
||||
Error& error,
|
||||
@@ -546,11 +546,11 @@ static optional<std::unique_ptr<Expression>> convertExponentialFunction(
|
||||
bool convertTokens = false) {
|
||||
auto stops = convertStops(type, value, error, convertTokens);
|
||||
if (!stops) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
auto base = convertBase(value, error);
|
||||
if (!base) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return numberOrDefault(type,
|
||||
@@ -559,7 +559,7 @@ static optional<std::unique_ptr<Expression>> convertExponentialFunction(
|
||||
std::move(def));
|
||||
}
|
||||
|
||||
static optional<std::unique_ptr<Expression>> convertCategoricalFunction(const type::Type& type,
|
||||
static std::optional<std::unique_ptr<Expression>> convertCategoricalFunction(const type::Type& type,
|
||||
const Convertible& value,
|
||||
Error& err,
|
||||
const std::string& property,
|
||||
@@ -567,35 +567,35 @@ static optional<std::unique_ptr<Expression>> convertCategoricalFunction(const ty
|
||||
auto stopsValue = objectMember(value, "stops");
|
||||
if (!stopsValue) {
|
||||
err.message = "function value must specify stops";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!isArray(*stopsValue)) {
|
||||
err.message = "function stops must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(*stopsValue) == 0) {
|
||||
err.message = "function must have at least one stop";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto& first = arrayMember(*stopsValue, 0);
|
||||
|
||||
if (!isArray(first)) {
|
||||
err.message = "function stop must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(first) != 2) {
|
||||
err.message = "function stop must have two elements";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (toBool(arrayMember(first, 0))) {
|
||||
auto branches = convertBranches<bool>(type, value, err);
|
||||
if (!branches) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return categorical(type, property, std::move(*branches), std::move(def));
|
||||
}
|
||||
@@ -603,7 +603,7 @@ static optional<std::unique_ptr<Expression>> convertCategoricalFunction(const ty
|
||||
if (toNumber(arrayMember(first, 0))) {
|
||||
auto branches = convertBranches<int64_t>(type, value, err);
|
||||
if (!branches) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return categorical(type, property, std::move(*branches), std::move(def));
|
||||
}
|
||||
@@ -611,23 +611,23 @@ static optional<std::unique_ptr<Expression>> convertCategoricalFunction(const ty
|
||||
if (toString(arrayMember(first, 0))) {
|
||||
auto branches = convertBranches<std::string>(type, value, err);
|
||||
if (!branches) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
return categorical(type, property, std::move(*branches), std::move(def));
|
||||
}
|
||||
|
||||
err.message = "stop domain value must be a number, string, or boolean";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
template <class T, class Fn>
|
||||
optional<std::unique_ptr<Expression>> composite(type::Type type,
|
||||
std::optional<std::unique_ptr<Expression>> composite(type::Type type,
|
||||
const Convertible& value,
|
||||
Error& error,
|
||||
const Fn& makeInnerExpression) {
|
||||
auto base = convertBase(value, error);
|
||||
if (!base) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto stopsValue = objectMember(value, "stops");
|
||||
@@ -643,46 +643,46 @@ optional<std::unique_ptr<Expression>> composite(type::Type type,
|
||||
|
||||
if (!isArray(stopValue)) {
|
||||
error.message = "function stop must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(stopValue) != 2) {
|
||||
error.message = "function stop must have two elements";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto& stopInput = arrayMember(stopValue, 0);
|
||||
|
||||
if (!isObject(stopInput)) {
|
||||
error.message = "stop input must be an object";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto zoomValue = objectMember(stopInput, "zoom");
|
||||
if (!zoomValue) {
|
||||
error.message = "stop input must specify zoom";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto sourceValue = objectMember(stopInput, "value");
|
||||
if (!sourceValue) {
|
||||
error.message = "stop input must specify value";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<float> z = convert<float>(*zoomValue, error);
|
||||
std::optional<float> z = convert<float>(*zoomValue, error);
|
||||
if (!z) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<T> d = convert<T>(*sourceValue, error);
|
||||
std::optional<T> d = convert<T>(*sourceValue, error);
|
||||
if (!d) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
optional<std::unique_ptr<Expression>> r = convertLiteral(type, arrayMember(stopValue, 1), error);
|
||||
std::optional<std::unique_ptr<Expression>> r = convertLiteral(type, arrayMember(stopValue, 1), error);
|
||||
if (!r) {
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
map[*z].emplace(*d, std::move(*r));
|
||||
@@ -701,13 +701,13 @@ optional<std::unique_ptr<Expression>> composite(type::Type type,
|
||||
}
|
||||
}
|
||||
|
||||
optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type type,
|
||||
std::optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type type,
|
||||
const Convertible& value,
|
||||
Error& err,
|
||||
bool convertTokens) {
|
||||
if (!isObject(value)) {
|
||||
err.message = "function must be an object";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
FunctionType functionType = FunctionType::Invalid;
|
||||
@@ -716,7 +716,7 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
if (!typeValue) {
|
||||
functionType = interpolatable(type) ? FunctionType::Exponential : FunctionType::Interval;
|
||||
} else {
|
||||
optional<std::string> string = toString(*typeValue);
|
||||
auto string = toString(*typeValue);
|
||||
if (string) {
|
||||
if (*string == "interval")
|
||||
functionType = FunctionType::Interval;
|
||||
@@ -749,77 +749,77 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
return convertExponentialFunction(type, value, err, [](bool) { return zoom(); }, defaultExpr(), convertTokens);
|
||||
default:
|
||||
err.message = "unsupported function type";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
auto propertyValue = objectMember(value, "property");
|
||||
if (!propertyValue) {
|
||||
err.message = "function must specify property";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
auto property = toString(*propertyValue);
|
||||
if (!property) {
|
||||
err.message = "function property must be a string";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (functionType == FunctionType::Identity) {
|
||||
return type.match(
|
||||
[&](const type::StringType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::StringType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
return string(get(literal(*property)), defaultExpr());
|
||||
},
|
||||
[&](const type::NumberType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::NumberType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
return number(get(literal(*property)), defaultExpr());
|
||||
},
|
||||
[&](const type::BooleanType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::BooleanType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
return boolean(get(literal(*property)), defaultExpr());
|
||||
},
|
||||
[&](const type::ColorType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::ColorType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
return toColor(get(literal(*property)), defaultExpr());
|
||||
},
|
||||
[&](const type::Array& array) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::Array& array) -> std::optional<std::unique_ptr<Expression>> {
|
||||
return assertion(array, get(literal(*property)), defaultExpr());
|
||||
},
|
||||
[&](const type::FormattedType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::FormattedType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
return toFormatted(get(literal(*property)), defaultExpr());
|
||||
},
|
||||
[&](const type::ImageType&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const type::ImageType&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
return toImage(get(literal(*property)), defaultExpr());
|
||||
},
|
||||
[&](const auto&) -> optional<std::unique_ptr<Expression>> {
|
||||
[&](const auto&) -> std::optional<std::unique_ptr<Expression>> {
|
||||
assert(false); // No properties use this type.
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
});
|
||||
}
|
||||
|
||||
auto stopsValue = objectMember(value, "stops");
|
||||
if (!stopsValue) {
|
||||
err.message = "function value must specify stops";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (!isArray(*stopsValue)) {
|
||||
err.message = "function stops must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(*stopsValue) == 0) {
|
||||
err.message = "function must have at least one stop";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto& first = arrayMember(*stopsValue, 0);
|
||||
|
||||
if (!isArray(first)) {
|
||||
err.message = "function stop must be an array";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (arrayLength(first) != 2) {
|
||||
err.message = "function stop must have two elements";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
const auto& stop = arrayMember(first, 0);
|
||||
@@ -843,14 +843,14 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
return convertCategoricalFunction(type, value, err, *property, defaultExpr());
|
||||
default:
|
||||
err.message = "unsupported function type";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
} else {
|
||||
// Composite function.
|
||||
auto sourceValue = objectMember(stop, "value");
|
||||
if (!sourceValue) {
|
||||
err.message = "stop must specify value";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
if (toBool(*sourceValue)) {
|
||||
@@ -865,7 +865,7 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
});
|
||||
default:
|
||||
err.message = "unsupported function type";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -903,7 +903,7 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
});
|
||||
default:
|
||||
err.message = "unsupported function type";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -919,12 +919,12 @@ optional<std::unique_ptr<Expression>> convertFunctionToExpression(type::Type typ
|
||||
});
|
||||
default:
|
||||
err.message = "unsupported function type";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
err.message = "stop domain value must be a number, string, or boolean";
|
||||
return nullopt;
|
||||
return std::nullopt;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user