Use std::optional instead of mbgl::optional (#911)

This commit is contained in:
Bart Louwers
2023-03-17 12:51:59 +01:00
committed by GitHub
parent 36846439c6
commit 15ad65dd3d
482 changed files with 2605 additions and 2652 deletions

View File

@@ -42,37 +42,37 @@ public:
return {};
}
static optional<MockConvertible> objectMember(const MockConvertible&, const char *) {
return nullopt;
static std::optional<MockConvertible> objectMember(const MockConvertible&, const char *) {
return std::nullopt;
}
template <class Fn>
static optional<Error> eachMember(const MockConvertible&, Fn&&) {
return nullopt;
static std::optional<Error> eachMember(const MockConvertible&, Fn&&) {
return std::nullopt;
}
static optional<bool> toBool(const MockConvertible&) {
return nullopt;
static std::optional<bool> toBool(const MockConvertible&) {
return std::nullopt;
}
static optional<float> toNumber(const MockConvertible&) {
return nullopt;
static std::optional<float> toNumber(const MockConvertible&) {
return std::nullopt;
}
static optional<double> toDouble(const MockConvertible&) {
return nullopt;
static std::optional<double> toDouble(const MockConvertible&) {
return std::nullopt;
}
static optional<std::string> toString(const MockConvertible&) {
return nullopt;
static std::optional<std::string> toString(const MockConvertible&) {
return std::nullopt;
}
static optional<mbgl::Value> toValue(const MockConvertible&) {
return nullopt;
static std::optional<mbgl::Value> toValue(const MockConvertible&) {
return std::nullopt;
}
static optional<GeoJSON> toGeoJSON(const MockConvertible&, Error&) {
return nullopt;
static std::optional<GeoJSON> toGeoJSON(const MockConvertible&, Error&) {
return std::nullopt;
}
};

View File

@@ -10,13 +10,13 @@ using namespace mbgl::style::conversion;
TEST(GeoJSONOptions, Basic) {
Error error;
mbgl::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>("{}", error);
std::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>("{}", error);
ASSERT_TRUE((bool) converted);
}
TEST(GeoJSONOptions, ErrorHandling) {
Error error;
mbgl::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>(R"JSON({
std::optional<GeoJSONOptions> converted = convertJSON<GeoJSONOptions>(R"JSON({
"maxzoom": "should not be a string"
})JSON", error);
ASSERT_FALSE((bool) converted);

View File

@@ -10,13 +10,13 @@ using namespace mbgl::style::conversion;
TEST(Tileset, Empty) {
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>("{}", error);
std::optional<Tileset> converted = convertJSON<Tileset>("{}", error);
EXPECT_FALSE((bool) converted);
}
TEST(Tileset, ErrorHandling) {
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": "should not be a string"
})JSON", error);
EXPECT_FALSE((bool) converted);
@@ -25,7 +25,7 @@ TEST(Tileset, ErrorHandling) {
TEST(Tileset, InvalidBounds) {
{
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": ["http://mytiles"],
"bounds": [73, -180, -73, -120]
})JSON", error);
@@ -34,7 +34,7 @@ TEST(Tileset, InvalidBounds) {
}
{
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": ["http://mytiles"],
"bounds": [-120]
})JSON", error);
@@ -43,7 +43,7 @@ TEST(Tileset, InvalidBounds) {
}
{
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": ["http://mytiles"],
"bounds": "should not be a string"
})JSON", error);
@@ -54,7 +54,7 @@ TEST(Tileset, InvalidBounds) {
TEST(Tileset, ValidWorldBounds) {
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": ["http://mytiles"],
"bounds": [-180, -90, 180, 90]
})JSON", error);
@@ -64,7 +64,7 @@ TEST(Tileset, ValidWorldBounds) {
TEST(Tileset, PointBounds) {
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": ["http://mytiles"],
"bounds": [0, 0, 0, 0]
})JSON", error);
@@ -74,7 +74,7 @@ TEST(Tileset, PointBounds) {
TEST(Tileset, BoundsAreClamped) {
Error error;
mbgl::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
std::optional<Tileset> converted = convertJSON<Tileset>(R"JSON({
"tiles": ["http://mytiles"],
"bounds": [-181.0000005,-90.000000006,180.00000000000006,91]
})JSON", error);

View File

@@ -26,7 +26,7 @@ bool filter(const char * json,
GeometryCollection featureGeometry = {},
float zoom = 0.0f) {
conversion::Error error;
optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
std::optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
EXPECT_TRUE(bool(filter));
EXPECT_EQ(error.message, "");
@@ -38,7 +38,7 @@ bool filter(const char * json,
void invalidFilter(const char * json) {
conversion::Error error;
optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
std::optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
EXPECT_FALSE(bool(filter));
EXPECT_NE(error.message, "");
}
@@ -67,7 +67,7 @@ void writeJSON(rapidjson::Writer<rapidjson::StringBuffer>& writer, const Value&
std::string stringifyFilter(const char * json) {
conversion::Error error;
optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
std::optional<Filter> filter = conversion::convertJSON<Filter>(json, error);
EXPECT_TRUE(bool(filter));
EXPECT_EQ(error.message, "");
@@ -238,7 +238,7 @@ TEST(Filter, Serialize) {
TEST(Filter, ExpressionLegacyMix) {
conversion::Error error;
optional<Filter> filter = conversion::convertJSON<Filter>(R"(["any", ["all", ["==", ["geometry-type"], "LineString"]], ["==", "x", 1]])", error);
std::optional<Filter> filter = conversion::convertJSON<Filter>(R"(["any", ["all", ["==", ["geometry-type"], "LineString"]], ["==", "x", 1]])", error);
EXPECT_FALSE(bool(filter));
EXPECT_TRUE(error.message.size() > 0);
}
@@ -259,6 +259,6 @@ TEST(Filter, Short) {
TEST(Filter, LegacyExpressionInvalidType) {
const JSValue value("string");
conversion::Error error;
optional<Filter> result = conversion::convert<Filter>(conversion::Convertible(&value), error);
std::optional<Filter> result = conversion::convert<Filter>(conversion::Convertible(&value), error);
EXPECT_FALSE(result);
}

View File

@@ -63,11 +63,11 @@ TEST(PropertyExpression, Expression) {
}
TEST(PropertyExpression, Defaults) {
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0)
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0f)
.evaluate(oneInteger, 2.0f));
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0)
EXPECT_EQ(1.0f, PropertyExpression<float>(number(get("property")), 0.0f)
.evaluate(oneDouble, 2.0f));
EXPECT_EQ(0.0f, PropertyExpression<float>(number(get("property")), 0.0)
EXPECT_EQ(0.0f, PropertyExpression<float>(number(get("property")), 0.0f)
.evaluate(oneString, 2.0f));
EXPECT_EQ(2.0f, PropertyExpression<float>(number(get("property")))
.evaluate(oneString, 2.0f));

View File

@@ -34,7 +34,6 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/logging.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/tileset.hpp>
#include <mbgl/util/timer.hpp>
@@ -47,6 +46,7 @@
#include <mbgl/text/glyph_manager.hpp>
#include <cstdint>
#include <optional>
#include <gmock/gmock.h>
using namespace mbgl;
@@ -466,7 +466,7 @@ TEST(Source, RasterTileCancel) {
test.fileSource->tileResponse = [&] (const Resource&) {
test.end();
return optional<Response>();
return std::optional<Response>();
};
RasterLayer layer("id", "source");
@@ -499,7 +499,7 @@ TEST(Source, RasterDEMTileCancel) {
test.fileSource->tileResponse = [&] (const Resource&) {
test.end();
return optional<Response>();
return std::optional<Response>();
};
HillshadeLayer layer("id", "source");
@@ -532,7 +532,7 @@ TEST(Source, VectorTileCancel) {
test.fileSource->tileResponse = [&] (const Resource&) {
test.end();
return optional<Response>();
return std::optional<Response>();
};
LineLayer layer("id", "source");
@@ -780,7 +780,7 @@ public:
[&](const OverscaledTileID& tileID) { return std::make_unique<FakeTile>(*this, tileID); });
}
const optional<Tileset>& getTileset() const override {
const std::optional<Tileset>& getTileset() const override {
return static_cast<const style::VectorSource::Impl&>(*baseImpl).tileset;
}
};
@@ -877,7 +877,7 @@ TEST(Source, RenderTileSetSourceUpdate) {
mockedUpdateInternal();
}
const optional<Tileset>& getTileset() const override {
const std::optional<Tileset>& getTileset() const override {
return static_cast<const style::VectorSource::Impl&>(*baseImpl).tileset;
}
};
@@ -957,7 +957,7 @@ TEST(Source, SetMaxParentOverscaleFactor) {
tileset.tiles = {"tiles"};
RasterSource source("source", tileset, 512);
ASSERT_EQ(nullopt, source.getMaxOverscaleFactorForParentTiles());
ASSERT_EQ(std::nullopt, source.getMaxOverscaleFactorForParentTiles());
source.setMaxOverscaleFactorForParentTiles(3);
ASSERT_EQ(3, *source.getMaxOverscaleFactorForParentTiles());
source.loadDescription(*test.fileSource);

View File

@@ -47,7 +47,7 @@ TEST(Style, Properties) {
style.loadJSON(R"STYLE({})STYLE");
ASSERT_EQ(Milliseconds(300), *style.getTransitionOptions().duration);
ASSERT_EQ(optional<Duration> {}, style.getTransitionOptions().delay);
ASSERT_EQ(std::optional<Duration>{}, style.getTransitionOptions().delay);
style.loadJSON(R"STYLE({"transition": { "duration": 500, "delay": 50 }})STYLE");
ASSERT_EQ(Milliseconds(500), *style.getTransitionOptions().duration);

View File

@@ -340,7 +340,7 @@ void testHasOverrides(LayoutType& layout) {
// Constant, overridden text-color.
auto formatted = Formatted("");
formatted.sections.emplace_back("section text"s, nullopt, nullopt, Color::green());
formatted.sections.emplace_back("section text"s, std::nullopt, std::nullopt, Color::green());
layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(formatted));
EXPECT_TRUE(MockOverrides::hasOverrides(layout.template get<TextField>()));
@@ -352,7 +352,7 @@ void testHasOverrides(LayoutType& layout) {
// Expression, overridden text-color.
FormatExpressionSection section(literal(""));
section.setTextSectionOptions(nullopt, nullopt, toColor(literal("red")));
section.setTextSectionOptions(std::nullopt, std::nullopt, toColor(literal("red")));
auto formatExprOverride = std::make_unique<FormatExpression>(std::vector<FormatExpressionSection>{section});
PropertyExpression<Formatted> propExprOverride(std::move(formatExprOverride));
layout.template get<TextField>() = PropertyValueType<Formatted>(std::move(propExprOverride));
@@ -361,7 +361,7 @@ void testHasOverrides(LayoutType& layout) {
// Nested expressions, overridden text-color.
auto formattedExpr1 = format("first paragraph");
FormatExpressionSection secondParagraph(literal("second paragraph"));
secondParagraph.setTextSectionOptions(nullopt, nullopt, toColor(literal("blue")));
secondParagraph.setTextSectionOptions(std::nullopt, std::nullopt, toColor(literal("blue")));
std::vector<FormatExpressionSection> sections{{std::move(secondParagraph)}};
auto formattedExpr2 = std::make_unique<FormatExpression>(std::move(sections));
std::unordered_map<std::string, std::shared_ptr<Expression>> branches{ { "1st", std::move(formattedExpr1) },
@@ -399,7 +399,7 @@ TEST(Layer, SymbolLayerOverrides) {
// Constant, overridden text-color.
auto formatted = Formatted("");
formatted.sections.emplace_back("section text"s, nullopt, nullopt, Color::green());
formatted.sections.emplace_back("section text"s, std::nullopt, std::nullopt, Color::green());
layout.get<TextField>() = PossiblyEvaluatedPropertyValue<Formatted>(std::move(formatted));
paint.get<TextColor>() = PossiblyEvaluatedPropertyValue<Color>{Color::red()};
EXPECT_TRUE(paint.get<TextColor>().isConstant());

View File

@@ -44,7 +44,7 @@ TEST_P(StyleParserTest, ParseStyle) {
auto error = parser.parse(util::read_file(base + ".style.json"));
if (error) {
Log::Error(Event::ParseStyle, "Failed to parse style: %s", util::toString(error).c_str());
Log::Error(Event::ParseStyle, "Failed to parse style: " + util::toString(error));
}
ASSERT_TRUE(infoDoc.IsObject());