diff --git a/CMakeLists.txt b/CMakeLists.txt index 713508f77..8de0d0cb3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,7 +281,6 @@ target_sources( ${PROJECT_SOURCE_DIR}/include/mbgl/util/interpolate.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/logging.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/noncopyable.hpp - ${PROJECT_SOURCE_DIR}/include/mbgl/util/optional.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/pass_types.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/platform.hpp ${PROJECT_SOURCE_DIR}/include/mbgl/util/premultiply.hpp diff --git a/benchmark/api/render.benchmark.cpp b/benchmark/api/render.benchmark.cpp index fcebb2e61..e91376e13 100644 --- a/benchmark/api/render.benchmark.cpp +++ b/benchmark/api/render.benchmark.cpp @@ -16,6 +16,7 @@ #include #include +#include using namespace mbgl; @@ -34,7 +35,7 @@ public: util::RunLoop loop; }; -void prepare(Map& map, optional json = nullopt) { +void prepare(Map& map, std::optional json = std::nullopt) { map.getStyle().loadJSON(json ? *json : util::read_file("benchmark/fixtures/api/style.json")); map.jumpTo(CameraOptions().withCenter(LatLng { 40.726989, -73.992857 }).withZoom(15.0)); // Manhattan @@ -42,7 +43,7 @@ void prepare(Map& map, optional json = nullopt) { map.getStyle().addImage(std::make_unique("test-icon", std::move(image), 1.0f)); } -void prepare_map2(Map& map, optional json = nullopt) { +void prepare_map2(Map& map, std::optional json = std::nullopt) { map.getStyle().loadJSON(json ? *json : util::read_file("benchmark/fixtures/api/style.json")); map.jumpTo(CameraOptions().withCenter(LatLng{41.379800, 2.176810}).withZoom(15.0)); // Barcelona diff --git a/benchmark/function/camera_function.benchmark.cpp b/benchmark/function/camera_function.benchmark.cpp index 0ce7d7c76..d152c516a 100644 --- a/benchmark/function/camera_function.benchmark.cpp +++ b/benchmark/function/camera_function.benchmark.cpp @@ -27,7 +27,7 @@ static void Parse_CameraFunction(benchmark::State& state) { state.PauseTiming(); auto doc = createFunctionJSON(stopCount); state.ResumeTiming(); - optional> result = conversion::convertJSON>(doc, error, false, false); + std::optional> result = conversion::convertJSON>(doc, error, false, false); if (!result) { state.SkipWithError(error.message.c_str()); } @@ -39,7 +39,7 @@ static void Evaluate_CameraFunction(benchmark::State& state) { size_t stopCount = state.range(0); auto doc = createFunctionJSON(stopCount); conversion::Error error; - optional> function = conversion::convertJSON>(doc, error, false, false); + std::optional> function = conversion::convertJSON>(doc, error, false, false); if (!function) { state.SkipWithError(error.message.c_str()); } diff --git a/benchmark/function/composite_function.benchmark.cpp b/benchmark/function/composite_function.benchmark.cpp index 8064d548f..4957ae5b4 100644 --- a/benchmark/function/composite_function.benchmark.cpp +++ b/benchmark/function/composite_function.benchmark.cpp @@ -33,7 +33,7 @@ static void Parse_CompositeFunction(benchmark::State& state) { state.PauseTiming(); auto doc = createFunctionJSON(stopCount); state.ResumeTiming(); - optional> result = conversion::convertJSON>(doc, error, true, false); + std::optional> result = conversion::convertJSON>(doc, error, true, false); if (!result) { state.SkipWithError(error.message.c_str()); } @@ -45,7 +45,7 @@ static void Evaluate_CompositeFunction(benchmark::State& state) { size_t stopCount = state.range(0); auto doc = createFunctionJSON(stopCount); conversion::Error error; - optional> function = conversion::convertJSON>(doc, error, true, false); + std::optional> function = conversion::convertJSON>(doc, error, true, false); if (!function) { state.SkipWithError(error.message.c_str()); } diff --git a/benchmark/function/source_function.benchmark.cpp b/benchmark/function/source_function.benchmark.cpp index b75cc143d..2056fe706 100644 --- a/benchmark/function/source_function.benchmark.cpp +++ b/benchmark/function/source_function.benchmark.cpp @@ -28,7 +28,7 @@ static void Parse_SourceFunction(benchmark::State& state) { state.PauseTiming(); auto doc = createFunctionJSON(stopCount); state.ResumeTiming(); - optional> result = conversion::convertJSON>(doc, error, true, false); + std::optional> result = conversion::convertJSON>(doc, error, true, false); if (!result) { state.SkipWithError(error.message.c_str()); } @@ -40,7 +40,7 @@ static void Evaluate_SourceFunction(benchmark::State& state) { size_t stopCount = state.range(0); auto doc = createFunctionJSON(stopCount); conversion::Error error; - optional> function = conversion::convertJSON>(doc, error, true, false); + std::optional> function = conversion::convertJSON>(doc, error, true, false); if (!function) { state.SkipWithError(error.message.c_str()); } diff --git a/benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp b/benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp index b8f2ffb5b..fe19cbb31 100644 --- a/benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp +++ b/benchmark/src/mbgl/benchmark/stub_geometry_tile_feature.hpp @@ -31,8 +31,8 @@ public: return id; } - optional getValue(const std::string& key) const override { - return properties.count(key) ? properties.at(key) : optional(); + std::optional getValue(const std::string& key) const override { + return properties.count(key) ? properties.at(key) : std::optional(); } const GeometryCollection& getGeometries() const override { diff --git a/benchmark/storage/offline_database.benchmark.cpp b/benchmark/storage/offline_database.benchmark.cpp index f2ad2605c..09da8bcb0 100644 --- a/benchmark/storage/offline_database.benchmark.cpp +++ b/benchmark/storage/offline_database.benchmark.cpp @@ -127,7 +127,7 @@ BENCHMARK_F(OfflineDatabase, GetTile)(benchmark::State& state) { while (state.KeepRunning()) { auto res = db.get(Resource::tile("mapbox://tile_ambient" + util::toString(dis(gen)), 1, 0, 0, 0, Tileset::Scheme::XYZ)); - assert(res != nullopt); + assert(res != std::nullopt); } } @@ -177,7 +177,7 @@ BENCHMARK_F(OfflineDatabase, GetTileFromDisabledDatabase)(benchmark::State& stat while (state.KeepRunning()) { auto res = db.get(Resource::tile("mapbox://tile_ambient", 1, 0, 0, 0, Tileset::Scheme::XYZ)); - assert(res == nullopt); + assert(res == std::nullopt); } } diff --git a/bin/offline.cpp b/bin/offline.cpp index 26948c315..d5f9ad708 100644 --- a/bin/offline.cpp +++ b/bin/offline.cpp @@ -126,9 +126,9 @@ int main(int argc, char *argv[]) { std::string style = styleValue ? args::get(styleValue) : mapTilerConfiguration.defaultStyles().at(0).getUrl(); std::cout << " Style: " << style << std::endl; - mbgl::optional mergePath = {}; + std::optional mergePath = std::nullopt; if (mergePathValue) mergePath = args::get(mergePathValue); - mbgl::optional inputDb = {}; + std::optional inputDb = std::nullopt; if (inputValue) inputDb = args::get(inputValue); const double minZoom = minZoomValue ? args::get(minZoomValue) : 0.0; @@ -205,7 +205,7 @@ int main(int argc, char *argv[]) { Observer(OfflineRegion& region_, std::shared_ptr fileSource_, util::RunLoop& loop_, - mbgl::optional mergePath_) + std::optional mergePath_) : region(region_), fileSource(std::move(fileSource_)), loop(loop_), @@ -249,7 +249,7 @@ int main(int argc, char *argv[]) { OfflineRegion& region; std::shared_ptr fileSource; util::RunLoop& loop; - mbgl::optional mergePath; + std::optional mergePath; Timestamp start; }; diff --git a/expression-test/expression_test_parser.cpp b/expression-test/expression_test_parser.cpp index c2c61b3fa..e7b826087 100644 --- a/expression-test/expression_test_parser.cpp +++ b/expression-test/expression_test_parser.cpp @@ -75,7 +75,7 @@ std::string toString(const JSValue& value) { return { value.GetString(), value.GetStringLength() }; } -optional toValue(const JSValue& jsvalue) { +std::optional toValue(const JSValue& jsvalue) { if (jsvalue.IsNull()) { return Value{}; } @@ -105,7 +105,7 @@ optional toValue(const JSValue& jsvalue) { return toValue(Convertible(&jsvalue)); } - return nullopt; + return std::nullopt; } style::expression::type::Type stringToType(const std::string& type) { @@ -133,7 +133,7 @@ style::expression::type::Type stringToType(const std::string& type) { return type::Null; } -optional toExpressionType(const PropertySpec& spec) { +std::optional toExpressionType(const PropertySpec& spec) { using namespace style::expression; if (spec.type == "array") { type::Type itemType = spec.value.empty() ? type::Value : stringToType(spec.value); @@ -147,7 +147,7 @@ optional toExpressionType(const PropertySpec& spe return {type::String}; } - return spec.type.empty() ? nullopt : optional{stringToType(spec.type)}; + return spec.type.empty() ? std::nullopt : std::optional{stringToType(spec.type)}; } void parseCompiled(const JSValue& compiledValue, TestData& data) { @@ -246,7 +246,7 @@ bool parseInputs(const JSValue& inputsValue, TestData& data) { assert(input[1].IsObject()); // Parse evaluation context, zoom. - optional zoom; + std::optional zoom; const auto& evaluationContext = input[0].GetObject(); if (evaluationContext.HasMember("zoom")) { assert(evaluationContext["zoom"].IsNumber()); @@ -254,14 +254,14 @@ bool parseInputs(const JSValue& inputsValue, TestData& data) { } // Parse heatmap density - optional heatmapDensity; + std::optional heatmapDensity; if (evaluationContext.HasMember("heatmapDensity")) { assert(evaluationContext["heatmapDensity"].IsNumber()); heatmapDensity = evaluationContext["heatmapDensity"].GetDouble(); } // Parse canonicalID - optional canonical; + std::optional canonical; if (evaluationContext.HasMember("canonicalID")) { const auto& canonicalIDObject = evaluationContext["canonicalID"]; assert(canonicalIDObject.IsObject()); @@ -344,7 +344,7 @@ std::tuple, bool, uint32_t> pars filesystem::path rootPath {std::string(TEST_RUNNER_ROOT_PATH).append("/maplibre-gl-js/test/integration/expression-tests")}; if (!filesystem::exists(rootPath)) { - Log::Error(Event::General, "Test path '%s' does not exist.", rootPath.string().c_str()); + Log::Error(Event::General, "Test path '" + rootPath.string() + "' does not exist."); exit(3); } @@ -363,7 +363,7 @@ std::tuple, bool, uint32_t> pars testPaths.reserve(paths.size()); for (const auto& path : paths) { if (!filesystem::exists(path)) { - Log::Warning(Event::General, "Provided test folder '%s' does not exist.", path.string().c_str()); + Log::Warning(Event::General, "Provided test folder '" + path.string() + "' does not exist."); continue; } @@ -404,20 +404,20 @@ Ignores parseExpressionIgnores() { return ignores; } -optional parseTestData(const filesystem::path& path) { +std::optional parseTestData(const filesystem::path& path) { TestData data; auto maybeJson = readJson(path.string()); if (!maybeJson.is()) { // NOLINT - Log::Error(Event::General, "Cannot parse test '%s'.", path.string().c_str()); - return nullopt; + mbgl::Log::Error(mbgl::Event::General, "Cannot parse test '" + path.string() + "'."); + return std::nullopt; } data.document = std::move(maybeJson.get()); // Check that mandatory test data members are present. if (!data.document.HasMember("expression") || !data.document.HasMember("expected")) { - Log::Error(Event::General, "Test fixture '%s' does not contain required data.", path.string().c_str()); - return nullopt; + Log::Error(Event::General, "Test fixture '" + path.string() + "' does not contain required data."); + return std::nullopt; } // Parse propertySpec @@ -431,8 +431,8 @@ optional parseTestData(const filesystem::path& path) { // Parse inputs if (data.document.HasMember("inputs") && !parseInputs(data.document["inputs"], data)) { - Log::Error(Event::General,"Can't convert inputs value for '%s'", path.string().c_str()); - return nullopt; + Log::Error(Event::General, std::string("Can't convert inputs value for '") + path.string() + "'"); + return std::nullopt; } return {std::move(data)}; @@ -471,14 +471,14 @@ Value toValue(const Compiled& compiled) { // Serializes native expression types to JS format. // Color and Formatted are exceptions. // TODO: harmonize serialized format to remove this conversion. -optional toValue(const expression::Value& exprValue) { +std::optional toValue(const expression::Value& exprValue) { return exprValue.match( - [](const Color& c) -> optional { + [](const Color& c) -> std::optional { std::vector color { static_cast(c.r), static_cast(c.g), static_cast(c.b), static_cast(c.a) }; return {Value{std::move(color)}}; }, - [](const expression::Formatted& formatted) -> optional { return {formatted.toObject()}; }, - [](const std::vector& values) -> optional { + [](const expression::Formatted& formatted) -> std::optional { return {formatted.toObject()}; }, + [](const std::vector& values) -> std::optional { std::vector mbglValues; for (const auto& value : values) { if (auto converted = expression::fromExpressionValue(value)) { @@ -487,7 +487,7 @@ optional toValue(const expression::Value& exprValue) { } return {Value{std::move(mbglValues)}}; }, - [](const std::unordered_map& valueMap) -> optional { + [](const std::unordered_map& valueMap) -> std::optional { std::unordered_map mbglValueMap; for (const auto& pair : valueMap) { if (auto converted = expression::fromExpressionValue(pair.second)) { @@ -500,9 +500,9 @@ optional toValue(const expression::Value& exprValue) { } std::unique_ptr parseExpression(const JSValue& value, - optional& spec, + std::optional& spec, TestResult& result) { - optional expected = spec ? toExpressionType(*spec) : nullopt; + std::optional expected = spec ? toExpressionType(*spec) : std::nullopt; expression::ParsingContext ctx = expected ? expression::ParsingContext(*expected) : expression::ParsingContext(); Convertible convertible(&value); @@ -538,8 +538,8 @@ std::unique_ptr parseExpression(const JSValue& va return nullptr; } -std::unique_ptr parseExpression(const optional& value, - optional& spec, +std::unique_ptr parseExpression(const std::optional& value, + std::optional& spec, TestResult& result) { assert(value); auto document = toDocument(*value); diff --git a/expression-test/expression_test_parser.hpp b/expression-test/expression_test_parser.hpp index b73dbf053..2c4eaa55a 100644 --- a/expression-test/expression_test_parser.hpp +++ b/expression-test/expression_test_parser.hpp @@ -4,7 +4,6 @@ #include #include -#include #include #include @@ -14,9 +13,9 @@ using namespace mbgl; struct Input { - Input(optional zoom_, - optional heatmapDensity_, - optional canonical_, + Input(std::optional zoom_, + std::optional heatmapDensity_, + std::optional canonical_, std::set availableImages_, Feature feature_) : zoom(std::move(zoom_)), @@ -24,9 +23,9 @@ struct Input { canonical(std::move(canonical_)), availableImages(std::move(availableImages_)), feature(std::move(feature_)) {} - optional zoom; - optional heatmapDensity; - optional canonical; + std::optional zoom; + std::optional heatmapDensity; + std::optional canonical; std::set availableImages; Feature feature; }; @@ -50,9 +49,9 @@ struct Compiled { struct TestResult { Compiled compiled; - optional expression; - optional outputs; - optional serialized; + std::optional expression; + std::optional outputs; + std::optional serialized; }; struct PropertySpec { @@ -60,7 +59,7 @@ struct PropertySpec { std::string value; std::size_t length = 0; bool isDataDriven = false; - optional expression; + std::optional expression; }; class TestData { @@ -69,7 +68,7 @@ public: TestResult expected; TestResult result; TestResult recompiled; - optional spec; + std::optional spec; JSDocument document; }; @@ -87,17 +86,17 @@ Arguments parseArguments(int argc, char** argv); using Ignores = std::vector; Ignores parseExpressionIgnores(); -optional parseTestData(const filesystem::path&); +std::optional parseTestData(const filesystem::path&); std::string toJSON(const Value& value, unsigned indent = 0, bool singleLine = false); JSDocument toDocument(const Value&); Value toValue(const Compiled&); -optional toValue(const style::expression::Value&); +std::optional toValue(const style::expression::Value&); std::unique_ptr parseExpression(const JSValue&, - optional&, + std::optional&, TestResult&); -std::unique_ptr parseExpression(const optional&, - optional&, +std::unique_ptr parseExpression(const std::optional&, + std::optional&, TestResult&); diff --git a/expression-test/main.cpp b/expression-test/main.cpp index 0bc3fd1a6..e1b2d0d77 100644 --- a/expression-test/main.cpp +++ b/expression-test/main.cpp @@ -40,7 +40,7 @@ try { ignoreReason = (*it).reason; } - optional testRun; + std::optional testRun; if (auto testData = parseTestData(path)) { testRun = runExpressionTest(*testData, rootPath.string(), id); } diff --git a/expression-test/test_runner_common.cpp b/expression-test/test_runner_common.cpp index 745ef9fce..dc84ff1e5 100644 --- a/expression-test/test_runner_common.cpp +++ b/expression-test/test_runner_common.cpp @@ -118,7 +118,7 @@ bool deepEqual(const Value& a, const Value& b) { return false; } -bool deepEqual(const optional& a, const optional& b) { +bool deepEqual(const std::optional& a, const std::optional& b) { if ((a && !b) || (!a && b)) { return false; } diff --git a/expression-test/test_runner_common.hpp b/expression-test/test_runner_common.hpp index b30d1a145..8d17427f8 100644 --- a/expression-test/test_runner_common.hpp +++ b/expression-test/test_runner_common.hpp @@ -10,4 +10,4 @@ using namespace mbgl; Value stripPrecision(const Value& value); std::vector tokenize(std::string str); bool deepEqual(const Value& a, const Value& b); -bool deepEqual(const optional& a, const optional& b); +bool deepEqual(const std::optional& a, const std::optional& b); diff --git a/include/mbgl/actor/mailbox.hpp b/include/mbgl/actor/mailbox.hpp index 6277f56f2..37bdf2dca 100644 --- a/include/mbgl/actor/mailbox.hpp +++ b/include/mbgl/actor/mailbox.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include #include #include diff --git a/include/mbgl/actor/message.hpp b/include/mbgl/actor/message.hpp index 52984b221..3167a9f25 100644 --- a/include/mbgl/actor/message.hpp +++ b/include/mbgl/actor/message.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include #include diff --git a/include/mbgl/gl/custom_layer.hpp b/include/mbgl/gl/custom_layer.hpp index f879cda80..ce12aa618 100644 --- a/include/mbgl/gl/custom_layer.hpp +++ b/include/mbgl/gl/custom_layer.hpp @@ -73,8 +73,8 @@ public: Mutable mutableImpl() const; private: - optional setPropertyInternal(const std::string& name, - const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, + const conversion::Convertible& value) final; StyleProperty getProperty(const std::string&) const final; std::unique_ptr cloneRef(const std::string& id) const final; Mutable mutableBaseImpl() const final; diff --git a/include/mbgl/i18n/collator.hpp b/include/mbgl/i18n/collator.hpp index 69afbae7d..b170347d6 100644 --- a/include/mbgl/i18n/collator.hpp +++ b/include/mbgl/i18n/collator.hpp @@ -1,16 +1,15 @@ #pragma once -#include - #include #include +#include namespace mbgl { namespace platform { class Collator { public: - explicit Collator(bool caseSensitive, bool diacriticSensitive, const optional& locale = nullopt); + explicit Collator(bool caseSensitive, bool diacriticSensitive, const std::optional& locale = std::nullopt); int compare(const std::string& lhs, const std::string& rhs) const; std::string resolvedLocale() const; bool operator==(const Collator& other) const; diff --git a/include/mbgl/layermanager/layer_factory.hpp b/include/mbgl/layermanager/layer_factory.hpp index afa25bf92..23de124bd 100644 --- a/include/mbgl/layermanager/layer_factory.hpp +++ b/include/mbgl/layermanager/layer_factory.hpp @@ -36,7 +36,7 @@ public: virtual std::unique_ptr createLayout(const LayoutParameters&, std::unique_ptr, const std::vector>&) noexcept; protected: - optional getSource(const style::conversion::Convertible& value) const noexcept; + std::optional getSource(const style::conversion::Convertible& value) const noexcept; }; } // namespace mbgl diff --git a/include/mbgl/map/bound_options.hpp b/include/mbgl/map/bound_options.hpp index 6a410ad0b..27cba371a 100644 --- a/include/mbgl/map/bound_options.hpp +++ b/include/mbgl/map/bound_options.hpp @@ -1,7 +1,8 @@ #pragma once #include -#include + +#include namespace mbgl { @@ -28,19 +29,19 @@ struct BoundOptions { } /// Constrain the center of the camera to be within these bounds. - optional bounds; + std::optional bounds; /// Maximum zoom level allowed. - optional maxZoom; + std::optional maxZoom; /// Minimum zoom level allowed. - optional minZoom; + std::optional minZoom; /// Maximum pitch allowed in degrees. - optional maxPitch; + std::optional maxPitch; /// Minimum pitch allowed in degrees. - optional minPitch; + std::optional minPitch; }; } // namespace mbgl diff --git a/include/mbgl/map/camera.hpp b/include/mbgl/map/camera.hpp index 5f723db1c..52f08bb2b 100644 --- a/include/mbgl/map/camera.hpp +++ b/include/mbgl/map/camera.hpp @@ -2,10 +2,11 @@ #include #include -#include #include #include +#include + #include namespace mbgl { @@ -16,34 +17,34 @@ namespace mbgl { center point when both are set. */ struct CameraOptions { - CameraOptions& withCenter(const optional& o) { center = o; return *this; } - CameraOptions& withPadding(const optional& p) { padding = p; return *this; } - CameraOptions& withAnchor(const optional& o) { anchor = o; return *this; } - CameraOptions& withZoom(const optional& o) { zoom = o; return *this; } - CameraOptions& withBearing(const optional& o) { bearing = o; return *this; } - CameraOptions& withPitch(const optional& o) { pitch = o; return *this; } + CameraOptions& withCenter(const std::optional& o) { center = o; return *this; } + CameraOptions& withPadding(const std::optional& p) { padding = p; return *this; } + CameraOptions& withAnchor(const std::optional& o) { anchor = o; return *this; } + CameraOptions& withZoom(const std::optional& o) { zoom = o; return *this; } + CameraOptions& withBearing(const std::optional& o) { bearing = o; return *this; } + CameraOptions& withPitch(const std::optional& o) { pitch = o; return *this; } /** Coordinate at the center of the map. */ - optional center; + std::optional center; /** Padding around the interior of the view that affects the frame of reference for `center`. */ - optional padding; + std::optional padding; /** Point of reference for `zoom` and `angle`, assuming an origin at the top-left corner of the view. */ - optional anchor; + std::optional anchor; /** Zero-based zoom level. Constrained to the minimum and maximum zoom levels. */ - optional zoom; + std::optional zoom; /** Bearing, measured in degrees from true north. Wrapped to [0, 360). */ - optional bearing; + std::optional bearing; /** Pitch toward the horizon measured in degrees , with 0 deg resulting in a two-dimensional map. */ - optional pitch; + std::optional pitch; }; constexpr bool operator==(const CameraOptions& a, const CameraOptions& b) { @@ -64,21 +65,21 @@ constexpr bool operator!=(const CameraOptions& a, const CameraOptions& b) { struct is used. */ struct AnimationOptions { /** Time to animate to the viewpoint defined herein. */ - optional duration; + std::optional duration; /** Average velocity of a flyTo() transition, measured in screenfuls per second, assuming a linear timing curve. A screenful is the visible span in pixels. It does not correspond to a fixed physical distance but rather varies by zoom level. */ - optional velocity; + std::optional velocity; /** Zero-based zoom level at the peak of the flyTo() transition’s flight path. */ - optional minZoom; + std::optional minZoom; /** The easing timing curve of the transition. */ - optional easing; + std::optional easing; /** A function that is called on each frame of the transition, just before a screen update, except on the last frame. The first parameter indicates @@ -107,7 +108,7 @@ struct FreeCameraOptions { - Z coordinate is conformal and must respect minimum and maximum zoom values. - Zoom is automatically computed from the altitude (z) */ - optional position = nullopt; + std::optional position = std::nullopt; /** Orientation of the camera represented as a unit quaternion [x, y, z, w]. The default pose of the camera is such that the forward vector is looking up the -Z axis and @@ -119,19 +120,19 @@ struct FreeCameraOptions { Orientation can be set freely but certain constraints still apply - Orientation must be representable with only pitch and bearing. - Pitch has an upper limit */ - optional orientation = nullopt; + std::optional orientation = std::nullopt; /** Helper function for setting the mercator position as Lat&Lng and altitude in meters */ void setLocation(const LatLngAltitude& location); /** Helper function for converting mercator position into Lat&Lng and altitude in meters. This function fails to return a value if `position` is invalid or is not set */ - optional getLocation() const; + std::optional getLocation() const; /** Helper function for setting orientation of the camera by defining a focus point on the map. Up vector is required in certain scenarios where bearing can't be deduced from the viewing direction */ - void lookAtPoint(const LatLng& location, const optional& upVector = nullopt); + void lookAtPoint(const LatLng& location, const std::optional& upVector = std::nullopt); /** Helper function for setting the orientation of the camera as a pitch and a bearing. Both values are in degrees */ diff --git a/include/mbgl/map/map.hpp b/include/mbgl/map/map.hpp index 5eb98f52f..236315637 100644 --- a/include/mbgl/map/map.hpp +++ b/include/mbgl/map/map.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -20,6 +19,7 @@ #include #include #include +#include namespace mbgl { @@ -63,26 +63,26 @@ public: bool isPanning() const; // Camera - CameraOptions getCameraOptions(const optional& = {}) const; + CameraOptions getCameraOptions(const std::optional& = std::nullopt) const; void jumpTo(const CameraOptions&); void easeTo(const CameraOptions&, const AnimationOptions&); void flyTo(const CameraOptions&, const AnimationOptions&); void moveBy(const ScreenCoordinate&, const AnimationOptions& = {}); - void scaleBy(double scale, const optional& anchor, const AnimationOptions& animation = {}); + void scaleBy(double scale, const std::optional& anchor, const AnimationOptions& animation = {}); void pitchBy(double pitch, const AnimationOptions& animation = {}); void rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second, const AnimationOptions& = {}); CameraOptions cameraForLatLngBounds(const LatLngBounds&, const EdgeInsets&, - const optional& bearing = {}, - const optional& pitch = {}) const; + const std::optional& bearing = std::nullopt, + const std::optional& pitch = std::nullopt) const; CameraOptions cameraForLatLngs(const std::vector&, const EdgeInsets&, - const optional& bearing = {}, - const optional& pitch = {}) const; + const std::optional& bearing = std::nullopt, + const std::optional& pitch = std::nullopt) const; CameraOptions cameraForGeometry(const Geometry&, const EdgeInsets&, - const optional& bearing = {}, - const optional& pitch = {}) const; + const std::optional& bearing = std::nullopt, + const std::optional& pitch = std::nullopt) const; LatLngBounds latLngBoundsForCamera(const CameraOptions&) const; LatLngBounds latLngBoundsForCameraUnwrapped(const CameraOptions&) const; diff --git a/include/mbgl/map/projection_mode.hpp b/include/mbgl/map/projection_mode.hpp index 4617371e1..ed04fd82d 100644 --- a/include/mbgl/map/projection_mode.hpp +++ b/include/mbgl/map/projection_mode.hpp @@ -1,8 +1,7 @@ #pragma once -#include - #include +#include namespace mbgl { @@ -18,17 +17,17 @@ struct ProjectionMode { /** * @brief Set to True to enable axonometric rendering, false otherwise. */ - optional axonometric; + std::optional axonometric; /** * @brief The X skew value represents how much to skew on the x-axis. */ - optional xSkew; + std::optional xSkew; /** * @brief The Y skew value represents how much to skew on the y-axis. */ - optional ySkew; + std::optional ySkew; }; } // namespace mbgl diff --git a/include/mbgl/renderer/query.hpp b/include/mbgl/renderer/query.hpp index 7b6e4060f..097214a87 100644 --- a/include/mbgl/renderer/query.hpp +++ b/include/mbgl/renderer/query.hpp @@ -1,10 +1,10 @@ #pragma once -#include #include #include #include +#include namespace mbgl { @@ -13,15 +13,15 @@ namespace mbgl { */ class RenderedQueryOptions { public: - RenderedQueryOptions(optional> layerIDs_ = {}, - optional filter_ = {}) + RenderedQueryOptions(std::optional> layerIDs_ = std::nullopt, + std::optional filter_ = std::nullopt) : layerIDs(std::move(layerIDs_)), filter(std::move(filter_)) {} /** layerIDs to include in the query */ - optional> layerIDs; + std::optional> layerIDs; - optional filter; + std::optional filter; }; /** @@ -29,15 +29,15 @@ public: */ class SourceQueryOptions { public: - SourceQueryOptions(optional> sourceLayers_ = {}, - optional filter_ = {}) + SourceQueryOptions(std::optional> sourceLayers_ = std::nullopt, + std::optional filter_ = std::nullopt) : sourceLayers(std::move(sourceLayers_)), filter(std::move(filter_)) {} /// Required for VectorSource, ignored for GeoJSONSource - optional> sourceLayers; + std::optional> sourceLayers; - optional filter; + std::optional filter; }; } // namespace mbgl diff --git a/include/mbgl/renderer/renderer.hpp b/include/mbgl/renderer/renderer.hpp index 9a008b9ea..6bfdee626 100644 --- a/include/mbgl/renderer/renderer.hpp +++ b/include/mbgl/renderer/renderer.hpp @@ -25,9 +25,9 @@ struct PlacedSymbolData { /// Contents of the label std::u16string key; /// If symbol contains text, text collision box in viewport coordinates - optional> textCollisionBox; + std::optional> textCollisionBox; /// If symbol contains icon, icon collision box in viewport coordinates - optional> iconCollisionBox; + std::optional> iconCollisionBox; /// Symbol text was placed bool textPlaced; /// Symbol icon was placed @@ -42,7 +42,7 @@ struct PlacedSymbolData { class Renderer { public: - Renderer(gfx::RendererBackend&, float pixelRatio_, const optional& localFontFamily = {}); + Renderer(gfx::RendererBackend&, float pixelRatio_, const std::optional& localFontFamily = std::nullopt); ~Renderer(); void markContextLost(); @@ -65,20 +65,20 @@ public: const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args = {}) const; + const std::optional>& args = std::nullopt) const; - void setFeatureState(const std::string& sourceID, const optional& sourceLayerID, + void setFeatureState(const std::string& sourceID, const std::optional& sourceLayerID, const std::string& featureID, const FeatureState& state); void getFeatureState(FeatureState& state, const std::string& sourceID, - const optional& sourceLayerID, + const std::optional& sourceLayerID, const std::string& featureID) const; void removeFeatureState(const std::string& sourceID, - const optional& sourceLayerID, - const optional& featureID, - const optional& stateKey); + const std::optional& sourceLayerID, + const std::optional& featureID, + const std::optional& stateKey); // Debug void dumpDebugLogs(); diff --git a/include/mbgl/storage/database_file_source.hpp b/include/mbgl/storage/database_file_source.hpp index 15c779e56..195e04087 100644 --- a/include/mbgl/storage/database_file_source.hpp +++ b/include/mbgl/storage/database_file_source.hpp @@ -3,7 +3,6 @@ #include #include #include -#include namespace mbgl { diff --git a/include/mbgl/storage/offline.hpp b/include/mbgl/storage/offline.hpp index 97e7fc2e4..77ad3e31d 100644 --- a/include/mbgl/storage/offline.hpp +++ b/include/mbgl/storage/offline.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/include/mbgl/storage/online_file_source.hpp b/include/mbgl/storage/online_file_source.hpp index ba36b898a..797e40700 100644 --- a/include/mbgl/storage/online_file_source.hpp +++ b/include/mbgl/storage/online_file_source.hpp @@ -3,7 +3,8 @@ #include #include #include -#include + +#include namespace mbgl { diff --git a/include/mbgl/storage/resource.hpp b/include/mbgl/storage/resource.hpp index bee359e36..580d26962 100644 --- a/include/mbgl/storage/resource.hpp +++ b/include/mbgl/storage/resource.hpp @@ -2,11 +2,11 @@ #include #include -#include #include #include #include +#include namespace mbgl { @@ -55,7 +55,7 @@ public: Resource(Kind kind_, std::string url_, - optional tileData_ = {}, + std::optional tileData_ = std::nullopt, LoadingMethod loadingMethod_ = LoadingMethod::All) : kind(kind_), loadingMethod(loadingMethod_), @@ -91,11 +91,11 @@ public: std::string url; // Includes auxiliary data if this is a tile request. - optional tileData; + std::optional tileData; - optional priorModified = {}; - optional priorExpires = {}; - optional priorEtag = {}; + std::optional priorModified = std::nullopt; + std::optional priorExpires = std::nullopt; + std::optional priorEtag = std::nullopt; std::shared_ptr priorData; Duration minimumUpdateInterval{Duration::zero()}; StoragePolicy storagePolicy{StoragePolicy::Permanent}; diff --git a/include/mbgl/storage/response.hpp b/include/mbgl/storage/response.hpp index 07b059e43..7516c7944 100644 --- a/include/mbgl/storage/response.hpp +++ b/include/mbgl/storage/response.hpp @@ -1,8 +1,8 @@ #pragma once #include -#include +#include #include #include @@ -33,9 +33,9 @@ public: // The actual data of the response. Present only for non-error, non-notModified responses. std::shared_ptr data; - optional modified; - optional expires; - optional etag; + std::optional modified; + std::optional expires; + std::optional etag; bool isFresh() const { return expires ? *expires > util::now() : !error; @@ -63,10 +63,10 @@ public: // informing the user about the reason for the failure. std::string message; - optional retryAfter; + std::optional retryAfter; public: - Error(Reason, std::string = "", optional = {}); + Error(Reason, std::string = "", std::optional = std::nullopt); }; } // namespace mbgl diff --git a/include/mbgl/style/conversion/color_ramp_property_value.hpp b/include/mbgl/style/conversion/color_ramp_property_value.hpp index 17aa17742..59ff13932 100644 --- a/include/mbgl/style/conversion/color_ramp_property_value.hpp +++ b/include/mbgl/style/conversion/color_ramp_property_value.hpp @@ -9,7 +9,7 @@ namespace conversion { template <> struct Converter { - optional operator()(const Convertible& value, Error& error, bool /* allowDataExpressions */ = false, bool /* convertTokens */ = false) const; + std::optional operator()(const Convertible& value, Error& error, bool /* allowDataExpressions */ = false, bool /* convertTokens */ = false) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/constant.hpp b/include/mbgl/style/conversion/constant.hpp index bc3260e42..ae0a40a0b 100644 --- a/include/mbgl/style/conversion/constant.hpp +++ b/include/mbgl/style/conversion/constant.hpp @@ -16,52 +16,52 @@ namespace conversion { template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; template struct Converter>> { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; template struct Converter, typename std::enable_if_t>> { - optional> operator()(const Convertible& value, Error& error) const; + std::optional> operator()(const Convertible& value, Error& error) const; }; template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; template struct Converter> { - optional> operator()(const Convertible& value, Error& error) const; + std::optional> operator()(const Convertible& value, Error& error) const; }; template <> struct Converter> { - optional> operator()(const Convertible& value, Error& error) const; + std::optional> operator()(const Convertible& value, Error& error) const; }; template struct Converter> { - optional> operator()(const Convertible& value, Error& error) const; + std::optional> operator()(const Convertible& value, Error& error) const; }; template <> struct Converter> { - optional> operator()(const Convertible& value, Error& error) const; + std::optional> operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/coordinate.hpp b/include/mbgl/style/conversion/coordinate.hpp index 1346ed738..13a992d2e 100644 --- a/include/mbgl/style/conversion/coordinate.hpp +++ b/include/mbgl/style/conversion/coordinate.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { namespace style { @@ -11,7 +12,7 @@ namespace conversion { template<> struct Converter { public: - optional operator() (const Convertible& value, Error& error) const; + std::optional operator() (const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/custom_geometry_source_options.hpp b/include/mbgl/style/conversion/custom_geometry_source_options.hpp index 090e5b623..5340df36b 100644 --- a/include/mbgl/style/conversion/custom_geometry_source_options.hpp +++ b/include/mbgl/style/conversion/custom_geometry_source_options.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace mbgl { namespace style { @@ -10,7 +9,7 @@ namespace conversion { template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/filter.hpp b/include/mbgl/style/conversion/filter.hpp index 2d7ad0afc..7492b4062 100644 --- a/include/mbgl/style/conversion/filter.hpp +++ b/include/mbgl/style/conversion/filter.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace mbgl { namespace style { @@ -11,7 +10,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/function.hpp b/include/mbgl/style/conversion/function.hpp index 9ceeb979c..6e9375ff1 100644 --- a/include/mbgl/style/conversion/function.hpp +++ b/include/mbgl/style/conversion/function.hpp @@ -6,6 +6,8 @@ #include #include +#include + namespace mbgl { namespace style { namespace conversion { @@ -15,10 +17,10 @@ std::unique_ptr convertTokenStringToFormatExpression(con std::unique_ptr convertTokenStringToImageExpression(const std::string&); std::unique_ptr convertTokenStringToExpression(const std::string&); -optional> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens); +std::optional> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens); template -optional> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens); +std::optional> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens); } // namespace conversion } // namespace style diff --git a/include/mbgl/style/conversion/geojson.hpp b/include/mbgl/style/conversion/geojson.hpp index 90c1d6419..063b5bc63 100644 --- a/include/mbgl/style/conversion/geojson.hpp +++ b/include/mbgl/style/conversion/geojson.hpp @@ -2,19 +2,20 @@ #include #include -#include + +#include namespace mbgl { namespace style { namespace conversion { // Workaround until https://github.com/mapbox/mapbox-gl-native/issues/5623 is done. -optional parseGeoJSON(const std::string&, Error&); +std::optional parseGeoJSON(const std::string&, Error&); template <> struct Converter { public: - optional operator()(const Convertible&, Error&) const; + std::optional operator()(const Convertible&, Error&) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/geojson_options.hpp b/include/mbgl/style/conversion/geojson_options.hpp index 89511848d..444b5c7ca 100644 --- a/include/mbgl/style/conversion/geojson_options.hpp +++ b/include/mbgl/style/conversion/geojson_options.hpp @@ -2,7 +2,6 @@ #include #include -#include namespace mbgl { namespace style { @@ -10,7 +9,7 @@ namespace conversion { template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/layer.hpp b/include/mbgl/style/conversion/layer.hpp index 9cf019378..d1e669940 100644 --- a/include/mbgl/style/conversion/layer.hpp +++ b/include/mbgl/style/conversion/layer.hpp @@ -2,9 +2,9 @@ #include #include -#include #include +#include namespace mbgl { namespace style { @@ -13,10 +13,10 @@ namespace conversion { template <> struct Converter> { public: - optional> operator()(const Convertible& value, Error& error) const; + std::optional> operator()(const Convertible& value, Error& error) const; }; -optional setPaintProperties(Layer& layer, const Convertible& value); +std::optional setPaintProperties(Layer& layer, const Convertible& value); } // namespace conversion } // namespace style diff --git a/include/mbgl/style/conversion/light.hpp b/include/mbgl/style/conversion/light.hpp index 2f6f8628b..d1b2c7431 100644 --- a/include/mbgl/style/conversion/light.hpp +++ b/include/mbgl/style/conversion/light.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { namespace style { @@ -11,7 +12,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/position.hpp b/include/mbgl/style/conversion/position.hpp index 10db5c6ec..7d53d6580 100644 --- a/include/mbgl/style/conversion/position.hpp +++ b/include/mbgl/style/conversion/position.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { namespace style { @@ -10,7 +11,7 @@ namespace conversion { template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/property_value.hpp b/include/mbgl/style/conversion/property_value.hpp index 925f97af1..75829919b 100644 --- a/include/mbgl/style/conversion/property_value.hpp +++ b/include/mbgl/style/conversion/property_value.hpp @@ -10,13 +10,15 @@ #include #include +#include + namespace mbgl { namespace style { namespace conversion { template struct Converter> { - optional> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const; + std::optional> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const; template PropertyValue maybeConvertTokens(const S& t) const { @@ -49,7 +51,7 @@ struct Converter> { template <> struct Converter>, void> { - optional>> operator()(const Convertible& value, Error& error, bool, bool) const; + std::optional>> operator()(const Convertible& value, Error& error, bool, bool) const; }; } // namespace conversion } // namespace style diff --git a/include/mbgl/style/conversion/rotation.hpp b/include/mbgl/style/conversion/rotation.hpp index 86d67240f..9502e854b 100644 --- a/include/mbgl/style/conversion/rotation.hpp +++ b/include/mbgl/style/conversion/rotation.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { namespace style { @@ -10,7 +11,7 @@ namespace conversion { template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/source.hpp b/include/mbgl/style/conversion/source.hpp index 19bc1ce6b..10d06ee66 100644 --- a/include/mbgl/style/conversion/source.hpp +++ b/include/mbgl/style/conversion/source.hpp @@ -2,9 +2,9 @@ #include #include -#include #include +#include namespace mbgl { namespace style { @@ -13,7 +13,7 @@ namespace conversion { template <> struct Converter> { public: - optional> operator()(const Convertible& value, Error& error, const std::string& id) const; + std::optional> operator()(const Convertible& value, Error& error, const std::string& id) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/tileset.hpp b/include/mbgl/style/conversion/tileset.hpp index 88661c358..5be47b35e 100644 --- a/include/mbgl/style/conversion/tileset.hpp +++ b/include/mbgl/style/conversion/tileset.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { namespace style { @@ -11,7 +12,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion/transition_options.hpp b/include/mbgl/style/conversion/transition_options.hpp index a72d757d3..987233564 100644 --- a/include/mbgl/style/conversion/transition_options.hpp +++ b/include/mbgl/style/conversion/transition_options.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { namespace style { @@ -11,7 +12,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; } // namespace conversion diff --git a/include/mbgl/style/conversion_impl.hpp b/include/mbgl/style/conversion_impl.hpp index e1150ead7..94960d27d 100644 --- a/include/mbgl/style/conversion_impl.hpp +++ b/include/mbgl/style/conversion_impl.hpp @@ -9,7 +9,6 @@ #include #include #include -#include #include #include @@ -18,6 +17,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -34,7 +34,7 @@ namespace style { A single template function serves as the public interface: template - optional convert(const Convertible& input, Error& error); + std::optional convert(const Convertible& input, Error& error); Where `T` is one of the above types. If the conversion fails, the result is empty, and the error parameter includes diagnostic text suitable for presentation to a library user. Otherwise, @@ -69,7 +69,7 @@ namespace style { * `objectMember(v, name)` -- called only if `isObject(v)`; `name` is `const char *`; return value: * is true when evaluated in a boolean context iff the named member exists * is convertable to a `V` or `V&` when dereferenced - * `eachMember(v, [] (const std::string&, const V&) -> optional {...})` -- called + * `eachMember(v, [] (const std::string&, const V&) -> std::optional {...})` -- called only if `isObject(v)`; calls the provided lambda once for each key and value of the object; short-circuits if any call returns an `Error` @@ -150,42 +150,42 @@ public: return v.vtable->isObject(v.storage); } - friend inline optional objectMember(const Convertible& v, const char * name) { + friend inline std::optional objectMember(const Convertible& v, const char * name) { assert(v.vtable); return v.vtable->objectMember(v.storage, name); } - friend inline optional eachMember(const Convertible& v, const std::function (const std::string&, const Convertible&)>& fn) { + friend inline std::optional eachMember(const Convertible& v, const std::function (const std::string&, const Convertible&)>& fn) { assert(v.vtable); return v.vtable->eachMember(v.storage, fn); } - friend inline optional toBool(const Convertible& v) { + friend inline std::optional toBool(const Convertible& v) { assert(v.vtable); return v.vtable->toBool(v.storage); } - friend inline optional toNumber(const Convertible& v) { + friend inline std::optional toNumber(const Convertible& v) { assert(v.vtable); return v.vtable->toNumber(v.storage); } - friend inline optional toDouble(const Convertible& v) { + friend inline std::optional toDouble(const Convertible& v) { assert(v.vtable); return v.vtable->toDouble(v.storage); } - friend inline optional toString(const Convertible& v) { + friend inline std::optional toString(const Convertible& v) { assert(v.vtable); return v.vtable->toString(v.storage); } - friend inline optional toValue(const Convertible& v) { + friend inline std::optional toValue(const Convertible& v) { assert(v.vtable); return v.vtable->toValue(v.storage); } - friend inline optional toGeoJSON(const Convertible& v, Error& error) { + friend inline std::optional toGeoJSON(const Convertible& v, Error& error) { assert(v.vtable); return v.vtable->toGeoJSON(v.storage, error); } @@ -214,23 +214,23 @@ private: Convertible (*arrayMember) (const Storage&, std::size_t); bool (*isObject) (const Storage&); - optional (*objectMember) (const Storage&, const char *); - optional (*eachMember) (const Storage&, const std::function (const std::string&, const Convertible&)>&); + std::optional (*objectMember) (const Storage&, const char *); + std::optional (*eachMember) (const Storage&, const std::function (const std::string&, const Convertible&)>&); - optional (*toBool) (const Storage&); - optional (*toNumber) (const Storage&); - optional (*toDouble) (const Storage&); - optional (*toString) (const Storage&); - optional (*toValue) (const Storage&); + std::optional (*toBool) (const Storage&); + std::optional (*toNumber) (const Storage&); + std::optional (*toDouble) (const Storage&); + std::optional (*toString) (const Storage&); + std::optional (*toValue) (const Storage&); // https://github.com/mapbox/mapbox-gl-native/issues/5623 - optional (*toGeoJSON) (const Storage&, Error&); + std::optional (*toGeoJSON) (const Storage&, Error&); }; // Extracted this function from the table below to work around a GCC bug with differing // visibility settings for capturing lambdas: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=80947 template - static auto vtableEachMember(const Storage& s, const std::function(const std::string&, const Convertible&)>& fn) { + static auto vtableEachMember(const Storage& s, const std::function(const std::string&, const Convertible&)>& fn) { return ConversionTraits::eachMember(reinterpret_cast(s), [&](const std::string& k, T&& v) { return fn(k, Convertible(std::move(v))); }); @@ -262,11 +262,11 @@ private: return Traits::isObject(reinterpret_cast(s)); }, [] (const Storage& s, const char * key) { - optional member = Traits::objectMember(reinterpret_cast(s), key); + std::optional member = Traits::objectMember(reinterpret_cast(s), key); if (member) { - return optional(Convertible(std::move(*member))); + return std::optional(Convertible(std::move(*member))); } else { - return optional(); + return std::optional(); } }, vtableEachMember, @@ -297,7 +297,7 @@ private: }; template -optional convert(const Convertible& value, Error& error, Args&&...args) { +std::optional convert(const Convertible& value, Error& error, Args&&...args) { return Converter()(value, error, std::forward(args)...); } diff --git a/include/mbgl/style/expression/assertion.hpp b/include/mbgl/style/expression/assertion.hpp index 0dec89dac..8921cf921 100644 --- a/include/mbgl/style/expression/assertion.hpp +++ b/include/mbgl/style/expression/assertion.hpp @@ -22,7 +22,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; mbgl::Value serialize() const override; std::string getOperator() const override; diff --git a/include/mbgl/style/expression/at.hpp b/include/mbgl/style/expression/at.hpp index f0dbccb79..c208b4712 100644 --- a/include/mbgl/style/expression/at.hpp +++ b/include/mbgl/style/expression/at.hpp @@ -29,8 +29,8 @@ public: return false; } - std::vector> possibleOutputs() const override { - return { nullopt }; + std::vector> possibleOutputs() const override { + return { std::nullopt }; } std::string getOperator() const override { return "at"; } diff --git a/include/mbgl/style/expression/boolean_operator.hpp b/include/mbgl/style/expression/boolean_operator.hpp index d25474751..cb67fb4ab 100644 --- a/include/mbgl/style/expression/boolean_operator.hpp +++ b/include/mbgl/style/expression/boolean_operator.hpp @@ -21,7 +21,7 @@ public: EvaluationResult evaluate(const EvaluationContext& params) const override; void eachChild(const std::function& visit) const override; bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override { return "any"; } private: @@ -40,7 +40,7 @@ public: EvaluationResult evaluate(const EvaluationContext& params) const override; void eachChild(const std::function& visit) const override; bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override { return "all"; } private: diff --git a/include/mbgl/style/expression/case.hpp b/include/mbgl/style/expression/case.hpp index 4a254dc35..8785049b1 100644 --- a/include/mbgl/style/expression/case.hpp +++ b/include/mbgl/style/expression/case.hpp @@ -26,7 +26,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override { return "case"; } private: diff --git a/include/mbgl/style/expression/check_subtype.hpp b/include/mbgl/style/expression/check_subtype.hpp index 90e5169de..db6e244ba 100644 --- a/include/mbgl/style/expression/check_subtype.hpp +++ b/include/mbgl/style/expression/check_subtype.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include namespace mbgl { @@ -9,7 +8,7 @@ namespace style { namespace expression { namespace type { -optional checkSubtype(const Type& expected, const Type& t); +std::optional checkSubtype(const Type& expected, const Type& t); } // namespace type } // namespace expression diff --git a/include/mbgl/style/expression/coalesce.hpp b/include/mbgl/style/expression/coalesce.hpp index c4216f234..3273fbfc6 100644 --- a/include/mbgl/style/expression/coalesce.hpp +++ b/include/mbgl/style/expression/coalesce.hpp @@ -28,7 +28,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::size_t getLength() const { return args.size(); diff --git a/include/mbgl/style/expression/coercion.hpp b/include/mbgl/style/expression/coercion.hpp index 28c2c0c67..df70182ab 100644 --- a/include/mbgl/style/expression/coercion.hpp +++ b/include/mbgl/style/expression/coercion.hpp @@ -23,7 +23,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override; private: diff --git a/include/mbgl/style/expression/collator.hpp b/include/mbgl/style/expression/collator.hpp index 95a072618..eb82f8f17 100644 --- a/include/mbgl/style/expression/collator.hpp +++ b/include/mbgl/style/expression/collator.hpp @@ -1,9 +1,9 @@ #pragma once #include -#include #include +#include namespace mbgl { namespace style { @@ -11,7 +11,7 @@ namespace expression { class Collator { public: - Collator(bool caseSensitive, bool diacriticSensitive, const optional& locale = {}); + Collator(bool caseSensitive, bool diacriticSensitive, const std::optional& locale = std::nullopt); bool operator==(const Collator& other) const; diff --git a/include/mbgl/style/expression/collator_expression.hpp b/include/mbgl/style/expression/collator_expression.hpp index 2551cd19c..7889f8a7c 100644 --- a/include/mbgl/style/expression/collator_expression.hpp +++ b/include/mbgl/style/expression/collator_expression.hpp @@ -14,7 +14,7 @@ class CollatorExpression : public Expression { public: CollatorExpression(std::unique_ptr caseSensitive, std::unique_ptr diacriticSensitive, - optional> locale); + std::optional> locale); EvaluationResult evaluate(const EvaluationContext&) const override; static ParseResult parse(const mbgl::style::conversion::Convertible&, ParsingContext&); @@ -23,12 +23,12 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override { + std::vector> possibleOutputs() const override { // Technically the set of possible outputs is the combinatoric set of Collators produced // by all possibleOutputs of locale/caseSensitive/diacriticSensitive // But for the primary use of Collators in comparison operators, we ignore the Collator's // possibleOutputs anyway, so we can get away with leaving this undefined for now. - return { nullopt }; + return { std::nullopt }; } mbgl::Value serialize() const override; @@ -36,7 +36,7 @@ public: private: std::unique_ptr caseSensitive; std::unique_ptr diacriticSensitive; - optional> locale; + std::optional> locale; }; } // namespace expression diff --git a/include/mbgl/style/expression/comparison.hpp b/include/mbgl/style/expression/comparison.hpp index df1fbcab9..09f461537 100644 --- a/include/mbgl/style/expression/comparison.hpp +++ b/include/mbgl/style/expression/comparison.hpp @@ -25,7 +25,7 @@ public: void eachChild(const std::function& visit) const override; bool operator==(const Expression&) const override; EvaluationResult evaluate(const EvaluationContext&) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override; private: @@ -49,7 +49,7 @@ public: void eachChild(const std::function& visit) const override; bool operator==(const Expression&) const override; EvaluationResult evaluate(const EvaluationContext&) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override; private: diff --git a/include/mbgl/style/expression/compound_expression.hpp b/include/mbgl/style/expression/compound_expression.hpp index a5b9c0008..d4edb5121 100644 --- a/include/mbgl/style/expression/compound_expression.hpp +++ b/include/mbgl/style/expression/compound_expression.hpp @@ -5,10 +5,10 @@ #include #include #include -#include #include #include +#include namespace mbgl { namespace style { @@ -33,11 +33,11 @@ public: std::string getOperator() const override; EvaluationResult evaluate(const EvaluationContext& evaluationParams) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; void eachChild(const std::function& visit) const override; bool operator==(const Expression& e) const override; - optional getParameterCount() const; + std::optional getParameterCount() const; static bool exists(const std::string& name); diff --git a/include/mbgl/style/expression/distance.hpp b/include/mbgl/style/expression/distance.hpp index 8f522600f..670ae11cd 100644 --- a/include/mbgl/style/expression/distance.hpp +++ b/include/mbgl/style/expression/distance.hpp @@ -33,7 +33,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; mbgl::Value serialize() const override; std::string getOperator() const override; diff --git a/include/mbgl/style/expression/error.hpp b/include/mbgl/style/expression/error.hpp index 9e1da2f0f..7cf76f285 100644 --- a/include/mbgl/style/expression/error.hpp +++ b/include/mbgl/style/expression/error.hpp @@ -24,7 +24,7 @@ public: return EvaluationError{message}; } - std::vector> possibleOutputs() const override { + std::vector> possibleOutputs() const override { return {}; } diff --git a/include/mbgl/style/expression/expression.hpp b/include/mbgl/style/expression/expression.hpp index 2e5a595e6..e620a8f26 100644 --- a/include/mbgl/style/expression/expression.hpp +++ b/include/mbgl/style/expression/expression.hpp @@ -5,12 +5,12 @@ #include #include #include -#include #include #include #include #include +#include namespace mbgl { @@ -30,12 +30,12 @@ public: explicit EvaluationContext(float zoom_) : zoom(zoom_) {} explicit EvaluationContext(GeometryTileFeature const * feature_) : feature(feature_) {} EvaluationContext(float zoom_, GeometryTileFeature const* feature_) : zoom(zoom_), feature(feature_) {} - EvaluationContext(optional accumulated_, GeometryTileFeature const * feature_) : + EvaluationContext(std::optional accumulated_, GeometryTileFeature const * feature_) : accumulated(std::move(accumulated_)), feature(feature_) {} EvaluationContext(float zoom_, GeometryTileFeature const* feature_, const FeatureState* state_) : zoom(zoom_), feature(feature_), featureState(state_) {} - EvaluationContext(optional zoom_, GeometryTileFeature const * feature_, optional colorRampParameter_) : + EvaluationContext(std::optional zoom_, GeometryTileFeature const * feature_, std::optional colorRampParameter_) : zoom(std::move(zoom_)), feature(feature_), colorRampParameter(std::move(colorRampParameter_)) {} @@ -59,10 +59,10 @@ public: return *this; }; - optional zoom; - optional accumulated; + std::optional zoom; + std::optional accumulated; GeometryTileFeature const* feature = nullptr; - optional colorRampParameter; + std::optional colorRampParameter; // Contains formatted section object, std::unordered_map. const Value* formattedSection = nullptr; const FeatureState* featureState = nullptr; @@ -191,24 +191,24 @@ public: Kind getKind() const { return kind; }; type::Type getType() const { return type; }; - EvaluationResult evaluate(optional zoom, const Feature& feature, optional colorRampParameter) const; - EvaluationResult evaluate(optional zoom, + EvaluationResult evaluate(std::optional zoom, const Feature& feature, std::optional colorRampParameter) const; + EvaluationResult evaluate(std::optional zoom, const Feature& feature, - optional colorRampParameter, + std::optional colorRampParameter, const std::set& availableImages) const; - EvaluationResult evaluate(optional zoom, + EvaluationResult evaluate(std::optional zoom, const Feature& feature, - optional colorRampParameter, + std::optional colorRampParameter, const std::set& availableImages, const CanonicalTileID& canonical) const; - EvaluationResult evaluate(optional accumulated, const Feature& feature) const; + EvaluationResult evaluate(std::optional accumulated, const Feature& feature) const; /** * Statically analyze the expression, attempting to enumerate possible outputs. Returns * an array of values plus the sentinel null optional value, used to indicate that the * complete set of outputs is statically undecidable. */ - virtual std::vector> possibleOutputs() const = 0; + virtual std::vector> possibleOutputs() const = 0; virtual mbgl::Value serialize() const { std::vector serialized; diff --git a/include/mbgl/style/expression/find_zoom_curve.hpp b/include/mbgl/style/expression/find_zoom_curve.hpp index 6f1419a69..ff9e5984c 100644 --- a/include/mbgl/style/expression/find_zoom_curve.hpp +++ b/include/mbgl/style/expression/find_zoom_curve.hpp @@ -5,13 +5,14 @@ #include #include -#include + +#include namespace mbgl { namespace style { namespace expression { -optional> findZoomCurve(const expression::Expression* e); +std::optional> findZoomCurve(const expression::Expression* e); variant findZoomCurveChecked(const expression::Expression* e); diff --git a/include/mbgl/style/expression/format_expression.hpp b/include/mbgl/style/expression/format_expression.hpp index 248a3cf6d..e6fec2e2b 100644 --- a/include/mbgl/style/expression/format_expression.hpp +++ b/include/mbgl/style/expression/format_expression.hpp @@ -10,17 +10,17 @@ namespace expression { struct FormatExpressionSection { explicit FormatExpressionSection(std::unique_ptr content_); - void setTextSectionOptions(optional> fontScale_, - optional> textFont_, - optional> textColor_); + void setTextSectionOptions(std::optional> fontScale_, + std::optional> textFont_, + std::optional> textColor_); // Content can be expression that evaluates to String or Image. std::shared_ptr content; // Text related section options. - optional> fontScale; - optional> textFont; - optional> textColor; + std::optional> fontScale; + std::optional> textFont; + std::optional> textColor; }; class FormatExpression final : public Expression { @@ -34,10 +34,10 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override { + std::vector> possibleOutputs() const override { // Technically the combinatoric set of all children // Usually, this.text will be undefined anyway - return { nullopt }; + return { std::nullopt }; } const std::vector& getSections() const { return sections; } diff --git a/include/mbgl/style/expression/format_section_override.hpp b/include/mbgl/style/expression/format_section_override.hpp index 63382fda5..2fec025da 100644 --- a/include/mbgl/style/expression/format_section_override.hpp +++ b/include/mbgl/style/expression/format_section_override.hpp @@ -70,8 +70,8 @@ public: return false; } - std::vector> possibleOutputs() const final { - return {nullopt}; + std::vector> possibleOutputs() const final { + return {std::nullopt}; } std::string getOperator() const final { return "format-section-override"; } diff --git a/include/mbgl/style/expression/formatted.hpp b/include/mbgl/style/expression/formatted.hpp index d089e12d9..55c6ca653 100644 --- a/include/mbgl/style/expression/formatted.hpp +++ b/include/mbgl/style/expression/formatted.hpp @@ -4,10 +4,10 @@ #include #include #include -#include #include #include +#include namespace mbgl { namespace style { @@ -19,9 +19,9 @@ extern const char* const kFormattedSectionTextColor; struct FormattedSection { explicit FormattedSection(std::string text_, - optional fontScale_, - optional fontStack_, - optional textColor_) + std::optional fontScale_, + std::optional fontStack_, + std::optional textColor_) : text(std::move(text_)), fontScale(std::move(fontScale_)), fontStack(std::move(fontStack_)), @@ -30,10 +30,10 @@ struct FormattedSection { explicit FormattedSection(Image image_) : image(std::move(image_)) {} std::string text; - optional image; - optional fontScale; - optional fontStack; - optional textColor; + std::optional image; + std::optional fontScale; + std::optional fontStack; + std::optional textColor; }; class Formatted { @@ -41,7 +41,7 @@ public: Formatted() = default; Formatted(const char* plainU8String) { - sections.emplace_back(std::string(plainU8String), nullopt, nullopt, nullopt); + sections.emplace_back(std::string(plainU8String), std::nullopt, std::nullopt, std::nullopt); } Formatted(std::vector sections_) @@ -65,7 +65,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; template <> diff --git a/include/mbgl/style/expression/image.hpp b/include/mbgl/style/expression/image.hpp index 0bc4794a2..0555139d8 100644 --- a/include/mbgl/style/expression/image.hpp +++ b/include/mbgl/style/expression/image.hpp @@ -2,10 +2,10 @@ #include #include -#include #include #include +#include namespace mbgl { namespace style { @@ -35,7 +35,7 @@ namespace conversion { template <> struct Converter { public: - optional operator()(const Convertible& value, Error& error) const; + std::optional operator()(const Convertible& value, Error& error) const; }; template <> diff --git a/include/mbgl/style/expression/image_expression.hpp b/include/mbgl/style/expression/image_expression.hpp index cd3d37528..5a3ce3b11 100644 --- a/include/mbgl/style/expression/image_expression.hpp +++ b/include/mbgl/style/expression/image_expression.hpp @@ -19,7 +19,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override { return {nullopt}; } + std::vector> possibleOutputs() const override { return {std::nullopt}; } mbgl::Value serialize() const override; std::string getOperator() const override { return "image"; } diff --git a/include/mbgl/style/expression/in.hpp b/include/mbgl/style/expression/in.hpp index a7de17c94..66830a137 100644 --- a/include/mbgl/style/expression/in.hpp +++ b/include/mbgl/style/expression/in.hpp @@ -19,7 +19,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override; diff --git a/include/mbgl/style/expression/interpolate.hpp b/include/mbgl/style/expression/interpolate.hpp index 0e7850471..0035da713 100644 --- a/include/mbgl/style/expression/interpolate.hpp +++ b/include/mbgl/style/expression/interpolate.hpp @@ -9,6 +9,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -65,7 +66,7 @@ public: return false; } - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; mbgl::Value serialize() const override; std::string getOperator() const override { return "interpolate"; } diff --git a/include/mbgl/style/expression/length.hpp b/include/mbgl/style/expression/length.hpp index 1d754f193..f66b3039e 100644 --- a/include/mbgl/style/expression/length.hpp +++ b/include/mbgl/style/expression/length.hpp @@ -20,7 +20,7 @@ public: EvaluationResult evaluate(const EvaluationContext& params) const override; void eachChild(const std::function& visit) const override; bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; std::string getOperator() const override { return "length"; } private: diff --git a/include/mbgl/style/expression/let.hpp b/include/mbgl/style/expression/let.hpp index a03c4b7d7..5e24c0a4e 100644 --- a/include/mbgl/style/expression/let.hpp +++ b/include/mbgl/style/expression/let.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace mbgl { namespace style { @@ -34,7 +35,7 @@ public: return false; } - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; Expression* getResult() const { return result.get(); @@ -65,7 +66,7 @@ public: return false; } - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; mbgl::Value serialize() const override; std::string getOperator() const override { return "var"; } diff --git a/include/mbgl/style/expression/literal.hpp b/include/mbgl/style/expression/literal.hpp index e8f0a5d9e..c22e41b37 100644 --- a/include/mbgl/style/expression/literal.hpp +++ b/include/mbgl/style/expression/literal.hpp @@ -33,7 +33,7 @@ public: return false; } - std::vector> possibleOutputs() const override { + std::vector> possibleOutputs() const override { return {{ value }}; } diff --git a/include/mbgl/style/expression/match.hpp b/include/mbgl/style/expression/match.hpp index 766eec8f5..c94b0bd44 100644 --- a/include/mbgl/style/expression/match.hpp +++ b/include/mbgl/style/expression/match.hpp @@ -30,7 +30,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; mbgl::Value serialize() const override; std::string getOperator() const override { return "match"; } diff --git a/include/mbgl/style/expression/number_format.hpp b/include/mbgl/style/expression/number_format.hpp index 288c144f2..ed6f2e7df 100644 --- a/include/mbgl/style/expression/number_format.hpp +++ b/include/mbgl/style/expression/number_format.hpp @@ -22,7 +22,7 @@ public: EvaluationResult evaluate(const EvaluationContext& params) const override; void eachChild(const std::function& visit) const override; bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; mbgl::Value serialize() const override; std::string getOperator() const override { return "number-format"; } diff --git a/include/mbgl/style/expression/parsing_context.hpp b/include/mbgl/style/expression/parsing_context.hpp index 7723bd17b..16ce844ac 100644 --- a/include/mbgl/style/expression/parsing_context.hpp +++ b/include/mbgl/style/expression/parsing_context.hpp @@ -1,6 +1,5 @@ #pragma once -#include #include #include #include @@ -12,6 +11,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -25,7 +25,7 @@ struct ParsingError { bool operator==(const ParsingError& rhs) const { return message == rhs.message && key == rhs.key; } }; -using ParseResult = optional>; +using ParseResult = std::optional>; namespace detail { @@ -39,14 +39,14 @@ public: const std::map>& bindings; std::shared_ptr parent; - optional> get(const std::string& name) { + std::optional> get(const std::string& name) { auto it = bindings.find(name); if (it != bindings.end()) { return {it->second}; } else if (parent) { return parent->get(name); } else { - return optional>(); + return std::optional>(); } } }; @@ -86,7 +86,7 @@ public: ParsingContext& operator=(const ParsingContext&) = delete; std::string getKey() const { return key; } - optional getExpected() const { return expected; } + std::optional getExpected() const { return expected; } const std::vector& getErrors() const { return *errors; } std::string getCombinedErrors() const; @@ -94,7 +94,7 @@ public: Parse the given style-spec JSON value as an expression. */ ParseResult parseExpression(const mbgl::style::conversion::Convertible& value, - const optional& = {}); + const std::optional& = std::nullopt); /** Parse the given style-spec JSON value as an expression intended to be used @@ -108,24 +108,24 @@ public: */ ParseResult parse(const mbgl::style::conversion::Convertible&, std::size_t, - optional = {}, - const optional& = {}); + std::optional = std::nullopt, + const std::optional& = std::nullopt); /** Parse a child expression. For use by individual Expression::parse() methods. */ ParseResult parse(const mbgl::style::conversion::Convertible&, std::size_t index, - optional, + std::optional, const std::map>&); /** Check whether `t` is a subtype of `expected`, collecting an error if not. */ - optional checkType(const type::Type& t); + std::optional checkType(const type::Type& t); - optional> getBinding(const std::string& name) { - if (!scope) return optional>(); + std::optional> getBinding(const std::string& name) { + if (!scope) return std::optional>(); return scope->get(name); } @@ -153,7 +153,7 @@ public: private: ParsingContext(std::string key_, std::shared_ptr> errors_, - optional expected_, + std::optional expected_, std::shared_ptr scope_) : key(std::move(key_)), expected(std::move(expected_)), @@ -168,10 +168,10 @@ private: type (either Literal, or the one named in value[0]) and dispatching to the appropriate ParseXxxx::parse(const V&, ParsingContext) method. */ - ParseResult parse(const mbgl::style::conversion::Convertible& value, const optional& = {}); + ParseResult parse(const mbgl::style::conversion::Convertible& value, const std::optional& = std::nullopt); std::string key; - optional expected; + std::optional expected; std::shared_ptr scope; std::shared_ptr> errors; }; diff --git a/include/mbgl/style/expression/step.hpp b/include/mbgl/style/expression/step.hpp index f241f7af6..4999ed5d8 100644 --- a/include/mbgl/style/expression/step.hpp +++ b/include/mbgl/style/expression/step.hpp @@ -8,6 +8,7 @@ #include #include +#include namespace mbgl { namespace style { @@ -28,7 +29,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx); diff --git a/include/mbgl/style/expression/type.hpp b/include/mbgl/style/expression/type.hpp index ab398741f..ddd58dbe5 100644 --- a/include/mbgl/style/expression/type.hpp +++ b/include/mbgl/style/expression/type.hpp @@ -1,10 +1,11 @@ #pragma once -#include #include #include #include +#include + namespace mbgl { namespace style { namespace expression { @@ -109,7 +110,7 @@ using Type = variant N_) : itemType(std::move(itemType_)), N(std::move(N_)) {} + Array(Type itemType_, std::optional N_) : itemType(std::move(itemType_)), N(std::move(N_)) {} std::string getName() const { if (N) { return "array<" + toString(itemType) + ", " + util::toString(*N) + ">"; @@ -123,7 +124,7 @@ struct Array { bool operator==(const Array& rhs) const { return itemType == rhs.itemType && N == rhs.N; } Type itemType; - optional N; + std::optional N; }; template diff --git a/include/mbgl/style/expression/value.hpp b/include/mbgl/style/expression/value.hpp index 8b93e9f0f..74af6eedc 100644 --- a/include/mbgl/style/expression/value.hpp +++ b/include/mbgl/style/expression/value.hpp @@ -14,6 +14,7 @@ #include #include +#include namespace mbgl { namespace style { @@ -77,8 +78,8 @@ struct ValueConverter { return Value(value); } - static optional fromExpressionValue(const Value& value) { - return value.template is() ? value.template get() : optional(); + static std::optional fromExpressionValue(const Value& value) { + return value.template is() ? value.template get() : std::optional(); } }; @@ -86,7 +87,7 @@ template <> struct ValueConverter { static type::Type expressionType() { return type::Value; } static Value toExpressionValue(const Value& value) { return value; } - static optional fromExpressionValue(const Value& value) { return value; } + static std::optional fromExpressionValue(const Value& value) { return value; } }; template <> @@ -99,7 +100,7 @@ template <> struct ValueConverter { static type::Type expressionType() { return type::Number; } static Value toExpressionValue(float value); - static optional fromExpressionValue(const Value& value); + static std::optional fromExpressionValue(const Value& value); }; template @@ -108,7 +109,7 @@ struct ValueConverter> { return type::Array(valueTypeToExpressionType(), N); } static Value toExpressionValue(const std::array& value); - static optional> fromExpressionValue(const Value& value); + static std::optional> fromExpressionValue(const Value& value); }; template @@ -117,21 +118,21 @@ struct ValueConverter> { return type::Array(valueTypeToExpressionType()); } static Value toExpressionValue(const std::vector& value); - static optional> fromExpressionValue(const Value& value); + static std::optional> fromExpressionValue(const Value& value); }; template <> struct ValueConverter { static type::Type expressionType() { return type::Array(type::Number, 3); } static Value toExpressionValue(const mbgl::style::Position& value); - static optional fromExpressionValue(const Value& v); + static std::optional fromExpressionValue(const Value& v); }; template struct ValueConverter >> { static type::Type expressionType() { return type::String; } static Value toExpressionValue(const T& value); - static optional fromExpressionValue(const Value& value); + static std::optional fromExpressionValue(const Value& value); }; template @@ -140,16 +141,16 @@ Value toExpressionValue(const T& value) { } template -optional fromExpressionValue(const Value& value) { +std::optional fromExpressionValue(const Value& value) { return ValueConverter::fromExpressionValue(value); } template -std::vector> fromExpressionValues(const std::vector>& values) { - std::vector> result; +std::vector> fromExpressionValues(const std::vector>& values) { + std::vector> result; result.reserve(values.size()); for (const auto& value : values) { - result.push_back(value ? fromExpressionValue(*value) : nullopt); + result.push_back(value ? fromExpressionValue(*value) : std::nullopt); } return result; } @@ -158,7 +159,7 @@ template <> struct ValueConverter { static type::Type expressionType() { return type::Number; } static Value toExpressionValue(const mbgl::style::Rotation& value); - static optional fromExpressionValue(const Value& v); + static std::optional fromExpressionValue(const Value& v); }; } // namespace expression diff --git a/include/mbgl/style/expression/within.hpp b/include/mbgl/style/expression/within.hpp index 37e27f494..883aa2809 100644 --- a/include/mbgl/style/expression/within.hpp +++ b/include/mbgl/style/expression/within.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { namespace style { @@ -22,7 +23,7 @@ public: bool operator==(const Expression& e) const override; - std::vector> possibleOutputs() const override; + std::vector> possibleOutputs() const override; mbgl::Value serialize() const override; std::string getOperator() const override; diff --git a/include/mbgl/style/filter.hpp b/include/mbgl/style/filter.hpp index c3ce6833f..2652c01c3 100644 --- a/include/mbgl/style/filter.hpp +++ b/include/mbgl/style/filter.hpp @@ -8,19 +8,20 @@ #include #include #include +#include namespace mbgl { namespace style { class Filter { public: - optional> expression; + std::optional> expression; private: - optional legacyFilter; + std::optional legacyFilter; public: Filter() = default; - Filter(expression::ParseResult _expression, optional _filter = {}) + Filter(expression::ParseResult _expression, std::optional _filter = std::nullopt) : expression(std::move(*_expression)), legacyFilter(std::move(_filter)){ assert(!expression || *expression != nullptr); diff --git a/include/mbgl/style/image.hpp b/include/mbgl/style/image.hpp index e2365dd63..2c40d4b7e 100644 --- a/include/mbgl/style/image.hpp +++ b/include/mbgl/style/image.hpp @@ -2,11 +2,11 @@ #include #include -#include #include #include #include +#include namespace mbgl { namespace style { @@ -34,13 +34,13 @@ public: bool sdf, ImageStretches stretchX = {}, ImageStretches stretchY = {}, - const optional& content = nullopt); + const std::optional& content = std::nullopt); Image(std::string id, PremultipliedImage&& image, float pixelRatio, ImageStretches stretchX = {}, ImageStretches stretchY = {}, - const optional& content = nullopt) + const std::optional& content = std::nullopt) : Image(std::move(id), std::move(image), pixelRatio, false, std::move(stretchX), std::move(stretchY), content) { } Image(const Image&); @@ -61,7 +61,7 @@ public: const ImageStretches& getStretchY() const; /// The space where text can be fit into this image. - const optional& getContent() const; + const std::optional& getContent() const; class Impl; Immutable baseImpl; diff --git a/include/mbgl/style/layer.hpp b/include/mbgl/style/layer.hpp index 3698b4b05..233755481 100644 --- a/include/mbgl/style/layer.hpp +++ b/include/mbgl/style/layer.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -111,7 +111,7 @@ public: void setMaxZoom(float); // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value); + std::optional setProperty(const std::string& name, const conversion::Convertible& value); virtual StyleProperty getProperty(const std::string&) const = 0; virtual Value serialize() const; @@ -144,15 +144,15 @@ public: protected: virtual Mutable mutableBaseImpl() const = 0; void serializeProperty(Value&, const StyleProperty&, const char* propertyName, bool isPaint) const; - virtual optional setPropertyInternal(const std::string& name, + virtual std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) = 0; LayerObserver* observer; mapbox::base::WeakPtrFactory weakFactory {this}; private: - optional setVisibility(const conversion::Convertible& value); - optional setMinZoom(const conversion::Convertible& value); - optional setMaxZoom(const conversion::Convertible& value); + std::optional setVisibility(const conversion::Convertible& value); + std::optional setMinZoom(const conversion::Convertible& value); + std::optional setMaxZoom(const conversion::Convertible& value); }; } // namespace style diff --git a/include/mbgl/style/layers/background_layer.hpp b/include/mbgl/style/layers/background_layer.hpp index 6217484dc..8ce029822 100644 --- a/include/mbgl/style/layers/background_layer.hpp +++ b/include/mbgl/style/layers/background_layer.hpp @@ -50,7 +50,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/circle_layer.hpp b/include/mbgl/style/layers/circle_layer.hpp index bb1ccbfae..7e8940c08 100644 --- a/include/mbgl/style/layers/circle_layer.hpp +++ b/include/mbgl/style/layers/circle_layer.hpp @@ -104,7 +104,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/fill_extrusion_layer.hpp b/include/mbgl/style/layers/fill_extrusion_layer.hpp index e823e63b8..ed1bbffd2 100644 --- a/include/mbgl/style/layers/fill_extrusion_layer.hpp +++ b/include/mbgl/style/layers/fill_extrusion_layer.hpp @@ -80,7 +80,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/fill_layer.hpp b/include/mbgl/style/layers/fill_layer.hpp index a5f61a0c8..bf96114a0 100644 --- a/include/mbgl/style/layers/fill_layer.hpp +++ b/include/mbgl/style/layers/fill_layer.hpp @@ -80,7 +80,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/heatmap_layer.hpp b/include/mbgl/style/layers/heatmap_layer.hpp index cbe353a6c..751148bad 100644 --- a/include/mbgl/style/layers/heatmap_layer.hpp +++ b/include/mbgl/style/layers/heatmap_layer.hpp @@ -63,7 +63,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/hillshade_layer.hpp b/include/mbgl/style/layers/hillshade_layer.hpp index 2f50f9264..22034737f 100644 --- a/include/mbgl/style/layers/hillshade_layer.hpp +++ b/include/mbgl/style/layers/hillshade_layer.hpp @@ -68,7 +68,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/layer.hpp.ejs b/include/mbgl/style/layers/layer.hpp.ejs index 114fb1e34..9fcb08ac7 100644 --- a/include/mbgl/style/layers/layer.hpp.ejs +++ b/include/mbgl/style/layers/layer.hpp.ejs @@ -72,7 +72,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/line_layer.hpp b/include/mbgl/style/layers/line_layer.hpp index 1f3e8b04c..1a84b9a98 100644 --- a/include/mbgl/style/layers/line_layer.hpp +++ b/include/mbgl/style/layers/line_layer.hpp @@ -123,7 +123,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/location_indicator_layer.hpp b/include/mbgl/style/layers/location_indicator_layer.hpp index 8d70bc18d..72d79fb86 100644 --- a/include/mbgl/style/layers/location_indicator_layer.hpp +++ b/include/mbgl/style/layers/location_indicator_layer.hpp @@ -107,7 +107,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/raster_layer.hpp b/include/mbgl/style/layers/raster_layer.hpp index 2f10b7cbe..d15faea2c 100644 --- a/include/mbgl/style/layers/raster_layer.hpp +++ b/include/mbgl/style/layers/raster_layer.hpp @@ -80,7 +80,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/layers/symbol_layer.hpp b/include/mbgl/style/layers/symbol_layer.hpp index df54b7ad0..da9da5812 100644 --- a/include/mbgl/style/layers/symbol_layer.hpp +++ b/include/mbgl/style/layers/symbol_layer.hpp @@ -285,7 +285,7 @@ public: protected: // Dynamic properties - optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; + std::optional setPropertyInternal(const std::string& name, const conversion::Convertible& value) final; StyleProperty getProperty(const std::string& name) const final; Value serialize() const final; diff --git a/include/mbgl/style/light.hpp b/include/mbgl/style/light.hpp index dc54f9807..432bc44bf 100644 --- a/include/mbgl/style/light.hpp +++ b/include/mbgl/style/light.hpp @@ -22,7 +22,7 @@ public: ~Light(); // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value); + std::optional setProperty(const std::string& name, const conversion::Convertible& value); StyleProperty getProperty(const std::string&) const; static LightAnchorType getDefaultAnchor(); diff --git a/include/mbgl/style/light.hpp.ejs b/include/mbgl/style/light.hpp.ejs index 071647965..227cc031f 100644 --- a/include/mbgl/style/light.hpp.ejs +++ b/include/mbgl/style/light.hpp.ejs @@ -25,7 +25,7 @@ public: ~Light(); // Dynamic properties - optional setProperty(const std::string& name, const conversion::Convertible& value); + std::optional setProperty(const std::string& name, const conversion::Convertible& value); StyleProperty getProperty(const std::string&) const; <% for (const property of properties) { -%> diff --git a/include/mbgl/style/property_expression.hpp b/include/mbgl/style/property_expression.hpp index 90d4feeeb..477e71224 100644 --- a/include/mbgl/style/property_expression.hpp +++ b/include/mbgl/style/property_expression.hpp @@ -7,6 +7,8 @@ #include #include +#include + namespace mbgl { namespace style { @@ -40,7 +42,7 @@ template class PropertyExpression final : public PropertyExpressionBase { public: // Second parameter to be used only for conversions from legacy functions. - PropertyExpression(std::unique_ptr expression_, optional defaultValue_ = nullopt) + PropertyExpression(std::unique_ptr expression_, std::optional defaultValue_ = std::nullopt) : PropertyExpressionBase(std::move(expression_)), defaultValue(std::move(defaultValue_)) { } @@ -48,7 +50,7 @@ public: T evaluate(const expression::EvaluationContext& context, T finalDefaultValue = T()) const { const expression::EvaluationResult result = expression->evaluate(context); if (result) { - const optional typed = expression::fromExpressionValue(*result); + const std::optional typed = expression::fromExpressionValue(*result); return typed ? *typed : defaultValue ? *defaultValue : finalDefaultValue; } return defaultValue ? *defaultValue : finalDefaultValue; @@ -123,7 +125,7 @@ public: return evaluate(expression::EvaluationContext(zoom, &feature, &state), finalDefaultValue); } - std::vector> possibleOutputs() const { + std::vector> possibleOutputs() const { return expression::fromExpressionValues(expression->possibleOutputs()); } @@ -133,7 +135,7 @@ public: } private: - optional defaultValue; + std::optional defaultValue; }; } // namespace style diff --git a/include/mbgl/style/source.hpp b/include/mbgl/style/source.hpp index acc08a7f0..9625fbdac 100644 --- a/include/mbgl/style/source.hpp +++ b/include/mbgl/style/source.hpp @@ -3,13 +3,13 @@ #include #include #include -#include #include #include #include #include +#include namespace mbgl { @@ -64,7 +64,7 @@ public: SourceType getType() const; std::string getID() const; - optional getAttribution() const; + std::optional getAttribution() const; // The data from the volatile sources are not stored in a persistent storage. bool isVolatile() const noexcept; @@ -80,8 +80,8 @@ public: SourceObserver* observer = nullptr; virtual void loadDescription(FileSource&) = 0; - void setPrefetchZoomDelta(optional delta) noexcept; - optional getPrefetchZoomDelta() const noexcept; + void setPrefetchZoomDelta(std::optional delta) noexcept; + std::optional getPrefetchZoomDelta() const noexcept; // If the given source supports loading tiles from a server, // sets the minimum tile update interval. @@ -103,8 +103,8 @@ public: // minimum zoom level of a parent tile that could be used in place of an ideal // tile during rendering would be zoom 0. By default, no limit is set, so any // parent tile may be used. - void setMaxOverscaleFactorForParentTiles(optional overscaleFactor) noexcept; - optional getMaxOverscaleFactorForParentTiles() const noexcept; + void setMaxOverscaleFactorForParentTiles(std::optional overscaleFactor) noexcept; + std::optional getMaxOverscaleFactorForParentTiles() const noexcept; void dumpDebugLogs() const; virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0; diff --git a/include/mbgl/style/sources/geojson_source.hpp b/include/mbgl/style/sources/geojson_source.hpp index c951ad391..accb54449 100644 --- a/include/mbgl/style/sources/geojson_source.hpp +++ b/include/mbgl/style/sources/geojson_source.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include @@ -65,7 +64,7 @@ public: void setGeoJSON(const GeoJSON&); void setGeoJSONData(std::shared_ptr); - optional getURL() const; + std::optional getURL() const; const GeoJSONOptions& getOptions() const; class Impl; @@ -83,7 +82,7 @@ protected: Mutable createMutable() const noexcept final; private: - optional url; + std::optional url; std::unique_ptr req; std::shared_ptr threadPool; mapbox::base::WeakPtrFactory weakFactory {this}; diff --git a/include/mbgl/style/sources/image_source.hpp b/include/mbgl/style/sources/image_source.hpp index 32971ef3d..aae904a4a 100644 --- a/include/mbgl/style/sources/image_source.hpp +++ b/include/mbgl/style/sources/image_source.hpp @@ -2,7 +2,8 @@ #include #include -#include + +#include namespace mbgl { class LatLng; @@ -15,7 +16,7 @@ public: ImageSource(std::string id, std::array); ~ImageSource() override; - optional getURL() const; + std::optional getURL() const; void setURL(const std::string& url); void setImage(PremultipliedImage&&); @@ -38,7 +39,7 @@ protected: Mutable createMutable() const noexcept final; private: - optional url; + std::optional url; std::unique_ptr req; mapbox::base::WeakPtrFactory weakFactory {this}; }; diff --git a/include/mbgl/style/sources/raster_source.hpp b/include/mbgl/style/sources/raster_source.hpp index e06c3404e..486cf7e0b 100644 --- a/include/mbgl/style/sources/raster_source.hpp +++ b/include/mbgl/style/sources/raster_source.hpp @@ -16,7 +16,7 @@ public: ~RasterSource() override; const variant& getURLOrTileset() const; - optional getURL() const; + std::optional getURL() const; uint16_t getTileSize() const; diff --git a/include/mbgl/style/sources/vector_source.hpp b/include/mbgl/style/sources/vector_source.hpp index 83fcae95d..55cdd8de2 100644 --- a/include/mbgl/style/sources/vector_source.hpp +++ b/include/mbgl/style/sources/vector_source.hpp @@ -12,12 +12,12 @@ namespace style { class VectorSource final : public Source { public: - VectorSource(std::string id, variant urlOrTileset, optional maxZoom = nullopt, - optional minZoom = nullopt); + VectorSource(std::string id, variant urlOrTileset, std::optional maxZoom = std::nullopt, + std::optional minZoom = std::nullopt); ~VectorSource() final; const variant& getURLOrTileset() const; - optional getURL() const; + std::optional getURL() const; class Impl; const Impl& impl() const; @@ -37,8 +37,8 @@ private: const variant urlOrTileset; std::unique_ptr req; mapbox::base::WeakPtrFactory weakFactory {this}; - optional maxZoom; - optional minZoom; + std::optional maxZoom; + std::optional minZoom; }; template <> diff --git a/include/mbgl/style/style.hpp b/include/mbgl/style/style.hpp index c5e8d7f15..3d987deb9 100644 --- a/include/mbgl/style/style.hpp +++ b/include/mbgl/style/style.hpp @@ -46,7 +46,7 @@ public: void setLight(std::unique_ptr); // Images - optional getImage(const std::string&) const; + std::optional getImage(const std::string&) const; void addImage(std::unique_ptr); void removeImage(const std::string&); @@ -67,7 +67,7 @@ public: Layer* getLayer(const std::string&); const Layer* getLayer(const std::string&) const; - void addLayer(std::unique_ptr, const optional& beforeLayerID = {}); + void addLayer(std::unique_ptr, const std::optional& beforeLayerID = std::nullopt); std::unique_ptr removeLayer(const std::string& layerID); // Private implementation diff --git a/include/mbgl/style/transition_options.hpp b/include/mbgl/style/transition_options.hpp index 8ead79eb2..c5e51267c 100644 --- a/include/mbgl/style/transition_options.hpp +++ b/include/mbgl/style/transition_options.hpp @@ -1,21 +1,22 @@ #pragma once #include -#include #include +#include + namespace mbgl { namespace style { class TransitionOptions { public: - optional duration; - optional delay; + std::optional duration; + std::optional delay; bool enablePlacementTransitions; - TransitionOptions(optional duration_ = {}, - optional delay_ = {}, + TransitionOptions(std::optional duration_ = std::nullopt, + std::optional delay_ = std::nullopt, bool enablePlacementTransitions_ = true) : duration(std::move(duration_)), delay(std::move(delay_)), diff --git a/include/mbgl/util/color.hpp b/include/mbgl/util/color.hpp index 8a03abfcd..c8c48bb16 100644 --- a/include/mbgl/util/color.hpp +++ b/include/mbgl/util/color.hpp @@ -1,11 +1,11 @@ #pragma once -#include #include #include #include #include +#include namespace mbgl { @@ -37,7 +37,7 @@ public: static Color green() { return { 0.0f, 1.0f, 0.0f, 1.0f }; }; static Color blue() { return { 0.0f, 0.0f, 1.0f, 1.0f }; }; - static optional parse(const std::string&); + static std::optional parse(const std::string&); std::string stringify() const; std::array toArray() const; mbgl::Value toObject() const; diff --git a/include/mbgl/util/enum.hpp b/include/mbgl/util/enum.hpp index 6b08b00ed..c1a376e5f 100644 --- a/include/mbgl/util/enum.hpp +++ b/include/mbgl/util/enum.hpp @@ -1,10 +1,9 @@ #pragma once -#include - #include #include #include +#include namespace mbgl { @@ -13,7 +12,7 @@ class Enum { public: using Type = T; static const char * toString(T); - static optional toEnum(const std::string&); + static std::optional toEnum(const std::string&); }; #define MBGL_DEFINE_ENUM(T, ...) \ @@ -28,10 +27,10 @@ const char * Enum::toString(T t) { } \ \ template <> \ -optional Enum::toEnum(const std::string& s) { \ +std::optional Enum::toEnum(const std::string& s) { \ auto it = std::find_if(std::begin(T##_names), std::end(T##_names), \ [&] (const auto& v) { return s == v.second; }); \ - return it == std::end(T##_names) ? optional() : it->first; \ + return it == std::end(T##_names) ? std::optional() : it->first; \ } } // namespace mbgl diff --git a/include/mbgl/util/feature.hpp b/include/mbgl/util/feature.hpp index ef6a6989f..c8bd4e0d3 100644 --- a/include/mbgl/util/feature.hpp +++ b/include/mbgl/util/feature.hpp @@ -1,10 +1,11 @@ #pragma once -#include #include #include +#include + namespace mbgl { using Value = mapbox::base::Value; @@ -31,22 +32,22 @@ public: }; template -optional numericValue(const Value& value) { - return value.match([](uint64_t t) { return optional(static_cast(t)); }, - [](int64_t t) { return optional(static_cast(t)); }, - [](double t) { return optional(static_cast(t)); }, - [](const auto&) { return optional(); }); +std::optional numericValue(const Value& value) { + return value.match([](uint64_t t) { return std::optional(static_cast(t)); }, + [](int64_t t) { return std::optional(static_cast(t)); }, + [](double t) { return std::optional(static_cast(t)); }, + [](const auto&) { return std::optional(); }); } -inline optional featureIDtoString(const FeatureIdentifier& id) { +inline std::optional featureIDtoString(const FeatureIdentifier& id) { if (id.is()) { - return nullopt; + return std::nullopt; } return id.match( [](const std::string& value_) { return value_; }, [](uint64_t value_) { return util::toString(value_); }, [](int64_t value_) { return util::toString(value_); }, [](double value_) { return util::toString(value_); }, - [](const auto&) -> optional { return nullopt; }); +[](const auto&) -> std::optional { return std::nullopt; }); } } // namespace mbgl diff --git a/include/mbgl/util/logging.hpp b/include/mbgl/util/logging.hpp index f393c7e93..a3d6f776f 100644 --- a/include/mbgl/util/logging.hpp +++ b/include/mbgl/util/logging.hpp @@ -3,10 +3,10 @@ #include #include -#include #include #include +#include namespace mbgl { @@ -75,13 +75,12 @@ private: static Log* get() noexcept; static void record(EventSeverity severity, Event event, const std::string &msg); - static void record(EventSeverity severity, Event event, const char* format = "", ...); - static void record(EventSeverity severity, Event event, int64_t code, const char* format = "", ...); + static void record(EventSeverity severity, Event event, int64_t code, const std::string &msg); static void record(EventSeverity severity, Event event, int64_t code, const std::string& msg, - const optional& threadName); + const std::optional& threadName); // This method is the data sink that must be implemented by each platform we // support. It should ideally output the error message in a human readable diff --git a/include/mbgl/util/optional.hpp b/include/mbgl/util/optional.hpp deleted file mode 100644 index e0a3786a7..000000000 --- a/include/mbgl/util/optional.hpp +++ /dev/null @@ -1,13 +0,0 @@ -#pragma once - -#include - -namespace mbgl { - -template -using optional = std::experimental::optional; - -using nullopt_t = std::experimental::nullopt_t; -constexpr nullopt_t nullopt = std::experimental::nullopt; - -} // namespace mbgl diff --git a/include/mbgl/util/tile_server_options.hpp b/include/mbgl/util/tile_server_options.hpp index e155d3a0a..0879e026b 100644 --- a/include/mbgl/util/tile_server_options.hpp +++ b/include/mbgl/util/tile_server_options.hpp @@ -3,7 +3,8 @@ #include #include #include -#include + +#include namespace mbgl { @@ -65,7 +66,7 @@ namespace mbgl { * @param domainName The domain name. * @return TileServerOptions for chaining options together. */ - TileServerOptions& withSourceTemplate(std::string sourceTemplate, std::string domainName, optional versionPrefix); + TileServerOptions& withSourceTemplate(std::string sourceTemplate, std::string domainName, std::optional versionPrefix); /** * @brief Gets the previously set (or default) source template. @@ -86,7 +87,7 @@ namespace mbgl { * * @return const optional& version prefix. */ - const optional& sourceVersionPrefix() const; + const std::optional& sourceVersionPrefix() const; /** * @brief Sets the template for styles. @@ -96,7 +97,7 @@ namespace mbgl { * * @return TileServerOptions for chaining options together. */ - TileServerOptions& withStyleTemplate(std::string styleTemplate, std::string domainName, optional versionPrefix); + TileServerOptions& withStyleTemplate(std::string styleTemplate, std::string domainName, std::optional versionPrefix); /** * @brief Gets the previously set (or default) style template. @@ -117,7 +118,7 @@ namespace mbgl { * * @return const optional& version prefix. */ - const optional& styleVersionPrefix() const; + const std::optional& styleVersionPrefix() const; /** * @brief Sets the template for sprites. @@ -126,7 +127,7 @@ namespace mbgl { * @param spritesTemplate The sprites template. * @return TileServerOptions for chaining options together. */ - TileServerOptions& withSpritesTemplate(std::string spritesTemplate, std::string domainName, optional versionPrefix); + TileServerOptions& withSpritesTemplate(std::string spritesTemplate, std::string domainName, std::optional versionPrefix); /** * @brief Gets the previously set (or default) sprites template. @@ -147,7 +148,7 @@ namespace mbgl { * * @return const optional& version prefix. */ - const optional& spritesVersionPrefix() const; + const std::optional& spritesVersionPrefix() const; /** * @brief Sets the template for glyphs. @@ -157,7 +158,7 @@ namespace mbgl { * * @return TileServerOptions for chaining options together. */ - TileServerOptions& withGlyphsTemplate(std::string glyphsTemplate, std::string domainName, optional versionPrefix); + TileServerOptions& withGlyphsTemplate(std::string glyphsTemplate, std::string domainName, std::optional versionPrefix); /** * @brief Gets the previously set (or default) glyphs template. @@ -178,7 +179,7 @@ namespace mbgl { * * @return const optional& version prefix. */ - const optional& glyphsVersionPrefix() const; + const std::optional& glyphsVersionPrefix() const; /** * @brief Sets the template for tiles. @@ -188,7 +189,7 @@ namespace mbgl { * * @return TileServerOptions for chaining options together. */ - TileServerOptions& withTileTemplate(std::string tileTemplate, std::string domainName, optional versionPrefix); + TileServerOptions& withTileTemplate(std::string tileTemplate, std::string domainName, std::optional versionPrefix); /** * @brief Gets the previously set (or default) tile template. @@ -209,7 +210,7 @@ namespace mbgl { * * @return const optional& version prefix. */ - const optional& tileVersionPrefix() const; + const std::optional& tileVersionPrefix() const; /** * @brief Sets the access token parameter name. diff --git a/include/mbgl/util/tileset.hpp b/include/mbgl/util/tileset.hpp index c6e41fc4a..4bac337ff 100644 --- a/include/mbgl/util/tileset.hpp +++ b/include/mbgl/util/tileset.hpp @@ -2,12 +2,13 @@ #include #include -#include #include + #include #include #include #include +#include namespace mbgl { @@ -22,7 +23,7 @@ public: Scheme scheme; // DEMEncoding is not supported by the TileJSON spec DEMEncoding encoding; - optional bounds; + std::optional bounds; Tileset(std::vector tiles_ = std::vector(), Range zoomRange_ = {0, util::DEFAULT_MAX_ZOOM}, diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.cpp index b8e07d0f9..da6d979c3 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.cpp @@ -134,7 +134,7 @@ FeatureExtensionValue AndroidRendererFrontend::queryFeatureExtensions(const std: const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args) const { + const std::optional>& args) const { return mapRenderer.actor().ask(&Renderer::queryFeatureExtensions, sourceID, feature, extension, extensionField, args).get(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.hpp index dc5f11e57..7302f6e42 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/android_renderer_frontend.hpp @@ -52,7 +52,7 @@ public: const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args) const; + const std::optional>& args) const; // Memory void reduceMemoryUse(); diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.cpp index e07a10c95..dced5a141 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.cpp @@ -21,7 +21,7 @@ namespace android { // FileSource // FileSource::FileSource(jni::JNIEnv& _env, const jni::String& apiKey, const jni::String& _cachePath, const jni::Object& _options) -:activationCounter( optional(1)) { +:activationCounter( std::optional(1)) { std::string path = jni::Make(_env, _cachePath); mapbox::sqlite::setTempPath(path); diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.hpp index bc3ae1a5c..b5a9d15d5 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/file_source.hpp @@ -78,7 +78,7 @@ public: private: const std::string DATABASE_FILE = "/mbgl-offline.db"; - optional activationCounter; + std::optional activationCounter; mbgl::ResourceOptions resourceOptions; mbgl::ClientOptions clientOptions; std::unique_ptr> resourceTransform; diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/http_file_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/http_file_source.cpp index df4a403d9..121d81ab4 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/http_file_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/http_file_source.cpp @@ -160,8 +160,8 @@ void HTTPRequest::onResponse(jni::JNIEnv& env, int code, } else if (code == 404) { response.error = std::make_unique(Error::Reason::NotFound, "HTTP status code 404"); } else if (code == 429) { - optional retryAfter; - optional xRateLimitReset; + std::optional retryAfter; + std::optional xRateLimitReset; if (jRetryAfter) { retryAfter = jni::Make(env, jRetryAfter); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/i18n/collator.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/i18n/collator.cpp index 92c6ce016..1d8b370fd 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/i18n/collator.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/i18n/collator.cpp @@ -97,7 +97,7 @@ namespace platform { class Collator::Impl { public: - Impl(bool caseSensitive_, bool diacriticSensitive_, optional locale_) + Impl(bool caseSensitive_, bool diacriticSensitive_, std::optional locale_) : caseSensitive(caseSensitive_) , diacriticSensitive(diacriticSensitive_) , env(android::AttachEnv()) @@ -156,9 +156,9 @@ public: std::string language = jni::Make(*env, android::Locale::getLanguage(*env, locale)); std::string region = jni::Make(*env, android::Locale::getCountry(*env, locale)); - optional resultLanguage; + std::optional resultLanguage; if (!language.empty()) resultLanguage = language; - optional resultRegion; + std::optional resultRegion; if (!region.empty()) resultRegion = region; return LanguageTag(resultLanguage, {}, resultRegion).toBCP47(); @@ -173,7 +173,7 @@ private: jni::Global> locale; }; -Collator::Collator(bool caseSensitive, bool diacriticSensitive, const optional& locale_) +Collator::Collator(bool caseSensitive, bool diacriticSensitive, const std::optional& locale_) : impl(std::make_shared(caseSensitive, diacriticSensitive, locale_)) {} bool Collator::operator==(const Collator& other) const { diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp index 07a66f226..051e99410 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.cpp @@ -21,7 +21,7 @@ MapRenderer::MapRenderer(jni::JNIEnv& _env, : javaPeer(_env, obj), pixelRatio(pixelRatio_), localIdeographFontFamily(localIdeographFontFamily_ ? jni::Make(_env, localIdeographFontFamily_) - : optional{}), + : std::optional{}), mailboxData(this) {} MapRenderer::MailboxData::MailboxData(Scheduler* scheduler_) : scheduler(scheduler_) { @@ -51,7 +51,7 @@ void MapRenderer::reset() { std::lock_guard lock(initialisationMutex); rendererObserver.reset(); } catch (const std::exception& exception) { - Log::Error(Event::Android, "MapRenderer::reset failed: %s", exception.what()); + Log::Error(Event::Android, std::string("MapRenderer::reset failed: ") + exception.what()); } } @@ -80,7 +80,7 @@ void MapRenderer::schedule(std::function scheduled) { // Release the c++ peer as it will be destroyed on GC of the Java Peer runnable.release(); } catch (const std::exception& exception) { - Log::Error(Event::Android, "MapRenderer::schedule failed: %s", exception.what()); + Log::Error(Event::Android, std::string("MapRenderer::schedule failed: ") + exception.what()); } } @@ -94,7 +94,7 @@ void MapRenderer::requestRender() { weakReference.Call(*_env, onInvalidate); } } catch (const std::exception& exception) { - Log::Error(Event::Android, "MapRenderer::requestRender failed: %s", exception.what()); + Log::Error(Event::Android, std::string("MapRenderer::requestRender failed: ") + exception.what()); } } @@ -104,7 +104,7 @@ void MapRenderer::update(std::shared_ptr params) { std::lock_guard lock(updateMutex); updateParameters = std::move(params); } catch (const std::exception& exception) { - Log::Error(Event::Android, "MapRenderer::update failed: %s", exception.what()); + Log::Error(Event::Android, std::string("MapRenderer::update failed: ") + exception.what()); } } @@ -120,7 +120,7 @@ void MapRenderer::setObserver(std::shared_ptr _rendererObserve renderer->setObserver(rendererObserver.get()); } } catch (const std::exception& exception) { - Log::Error(Event::Android, "MapRenderer::setObserver failed: %s", exception.what()); + Log::Error(Event::Android, std::string("MapRenderer::setObserver failed: ") + exception.what()); } } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp index e37d37cfc..a7b7ca729 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/map_renderer.hpp @@ -3,11 +3,11 @@ #include #include #include -#include #include #include #include +#include #include @@ -112,7 +112,7 @@ private: jni::WeakReference, jni::EnvAttachingDeleter> javaPeer; float pixelRatio; - optional localIdeographFontFamily; + std::optional localIdeographFontFamily; std::shared_ptr threadPool; const MailboxData mailboxData; diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/native_map_view.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/native_map_view.cpp index 64f78c18e..b10c7cf90 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/native_map_view.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/native_map_view.cpp @@ -407,7 +407,7 @@ void NativeMapView::flyTo(jni::JNIEnv& env, jni::jdouble bearing, jni::jdouble l } jni::Local> NativeMapView::getLatLng(JNIEnv& env) { - return LatLng::New(env, *map->getCameraOptions(mbgl::nullopt).center); + return LatLng::New(env, *map->getCameraOptions(std::nullopt).center); } void NativeMapView::setLatLng(jni::JNIEnv& env, jni::jdouble latitude, jni::jdouble longitude, const jni::Array& padding, jni::jlong duration) { @@ -547,7 +547,7 @@ void NativeMapView::setVisibleCoordinateBounds(JNIEnv& env, const jni::Array& output) { - auto latlngBounds = map->latLngBoundsForCameraUnwrapped(map->getCameraOptions(mbgl::nullopt)); + auto latlngBounds = map->latLngBoundsForCameraUnwrapped(map->getCameraOptions(std::nullopt)); double latNorth = latlngBounds.north(); double lonEast = latlngBounds.east(); @@ -583,7 +583,7 @@ void NativeMapView::scheduleSnapshot(jni::JNIEnv&) { } jni::Local> NativeMapView::getCameraPosition(jni::JNIEnv& env) { - return CameraPosition::New(env, map->getCameraOptions(mbgl::nullopt), pixelRatio); + return CameraPosition::New(env, map->getCameraOptions(std::nullopt), pixelRatio); } void NativeMapView::updateMarker(jni::JNIEnv& env, jni::jlong markerId, jni::jdouble lat, jni::jdouble lon, const jni::String& jid) { @@ -861,7 +861,7 @@ jni::Local>> NativeMapView::queryRender using namespace mbgl::android::conversion; using namespace mbgl::android::geojson; - mbgl::optional> layers; + std::optional> layers; if (layerIds && layerIds.Length(env) > 0) { layers = android::conversion::toVector(env, layerIds); } @@ -878,7 +878,7 @@ jni::Local>> NativeMapView::queryRender using namespace mbgl::android::conversion; using namespace mbgl::android::geojson; - mbgl::optional> layers; + std::optional> layers; if (layerIds && layerIds.Length(env) > 0) { layers = toVector(env, layerIds); } @@ -937,7 +937,7 @@ void NativeMapView::addLayer(JNIEnv& env, jlong nativeLayerPtr, const jni::Strin try { layer->addToStyle( map->getStyle(), - before ? mbgl::optional(jni::Make(env, before)) : mbgl::optional()); + before ? std::optional(jni::Make(env, before)) : std::optional()); } catch (const std::runtime_error& error) { jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"), error.what()); } @@ -961,7 +961,7 @@ void NativeMapView::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, const jni:: } // Check if we found a sibling to place before - mbgl::optional before; + std::optional before; if (index + 1 > layers.size()) { // Not found jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"), @@ -989,7 +989,7 @@ void NativeMapView::addLayerAt(JNIEnv& env, jlong nativeLayerPtr, jni::jint inde // Check index int numLayers = layers.size() - 1; if (index > numLayers || index < 0) { - Log::Error(Event::JNI, "Index out of range: %i", index); + Log::Error(Event::JNI, "Index out of range: " + std::to_string(index)); jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"), std::string("Invalid index").c_str()); return; @@ -1013,7 +1013,7 @@ jni::jboolean NativeMapView::removeLayerAt(JNIEnv& env, jni::jint index) { // Check index int numLayers = layers.size() - 1; if (index > numLayers || index < 0) { - Log::Warning(Event::JNI, "Index out of range: %i", index); + Log::Warning(Event::JNI, "Index out of range: " + std::to_string(index)); return jni::jni_false; } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.cpp index 498f52353..ab60a02fe 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.cpp @@ -250,7 +250,7 @@ void OfflineRegion::OfflineRegionStatusCallback::onError(jni::JNIEnv& env, void OfflineRegion::OfflineRegionStatusCallback::onStatus(jni::JNIEnv& env, const jni::Object& callback, - mbgl::optional status) { + std::optional status) { static auto& javaClass = jni::Class::Singleton(env); static auto method = javaClass.GetMethod)>(env, "onStatus"); @@ -289,7 +289,7 @@ void OfflineRegion::OfflineRegionUpdateMetadataCallback::onError(jni::JNIEnv& en void OfflineRegion::OfflineRegionUpdateMetadataCallback::onUpdate(jni::JNIEnv& env, const jni::Object& callback, - mbgl::optional metadata) { + std::optional metadata) { static auto& javaClass = jni::Class::Singleton(env); static auto method = javaClass.GetMethod)>(env, "onUpdate"); diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.hpp index 6844008bb..4d161e7d9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/offline/offline_region.hpp @@ -25,7 +25,7 @@ public: static void onStatus(jni::JNIEnv&, const jni::Object&, - mbgl::optional); + std::optional); }; class OfflineRegionDeleteCallback { @@ -54,7 +54,7 @@ public: static void onUpdate(jni::JNIEnv&, const jni::Object&, - mbgl::optional); + std::optional); }; static constexpr auto Name() { return "com/mapbox/mapboxsdk/offline/OfflineRegion"; }; diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/snapshotter/map_snapshotter.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/snapshotter/map_snapshotter.cpp index b0e9cda0c..03547c293 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/snapshotter/map_snapshotter.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/snapshotter/map_snapshotter.cpp @@ -48,7 +48,7 @@ MapSnapshotter::MapSnapshotter(jni::JNIEnv& _env, mbgl::android::FileSource::getSharedResourceOptions(_env, _jFileSource), mbgl::android::FileSource::getSharedClientOptions(_env, _jFileSource), *this, - _localIdeographFontFamily ? jni::Make(_env, _localIdeographFontFamily) : optional{}); + _localIdeographFontFamily ? jni::Make(_env, _localIdeographFontFamily) : std::optional{}); if (position) { snapshotter->setCameraOptions(CameraPosition::getCameraOptions(_env, position, pixelRatio)); @@ -197,7 +197,7 @@ void MapSnapshotter::addLayerAt(JNIEnv& env, jlong nativeLayerPtr, jni::jint ind // Check index const int numLayers = layers.size() - 1; if (index > numLayers || index < 0) { - Log::Error(Event::JNI, "Index out of range: %i", index); + Log::Error(Event::JNI, "Index out of range: " + std::to_string(index)); jni::ThrowNew(env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"), std::string("Invalid index").c_str()); @@ -218,7 +218,7 @@ void MapSnapshotter::addLayerBelow(JNIEnv& env, jlong nativeLayerPtr, const jni: try { layer->addToStyle( snapshotter->getStyle(), - below ? mbgl::optional(jni::Make(env, below)) : mbgl::optional()); + below ? std::optional(jni::Make(env, below)) : std::optional()); } catch (const std::runtime_error& error) { jni::ThrowNew( env, jni::FindClass(env, "com/mapbox/mapboxsdk/style/layers/CannotAddLayerException"), error.what()); @@ -242,7 +242,7 @@ void MapSnapshotter::addLayerAbove(JNIEnv& env, jlong nativeLayerPtr, const jni: } // Check if we found a sibling to place before - mbgl::optional before; + std::optional before; if (index > snapshotterLayers.size()) { // Not found jni::ThrowNew(env, diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/android_conversion.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/android_conversion.hpp index 6f1680459..8b33a9f8e 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/android_conversion.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/android_conversion.hpp @@ -4,11 +4,11 @@ #include #include -#include #include #include #include +#include namespace mbgl { namespace style { @@ -37,7 +37,7 @@ public: return value.get(i); } - static optional objectMember(const mbgl::android::Value& value, const char* key) { + static std::optional objectMember(const mbgl::android::Value& value, const char* key) { mbgl::android::Value member = value.get(key); if (!member.isNull()) { return member; @@ -47,14 +47,14 @@ public: } template - static optional eachMember(const mbgl::android::Value& value, Fn&& fn) { + static std::optional eachMember(const mbgl::android::Value& value, Fn&& fn) { assert(value.isObject()); mbgl::android::Value keys = value.keyArray(); std::size_t length = arrayLength(keys); for(std::size_t i = 0; i < length; ++i){ const auto k = keys.get(i).toString(); auto v = value.get(k.c_str()); - optional result = fn(k, std::move(v)); + std::optional result = fn(k, std::move(v)); if (result) { return result; } @@ -62,7 +62,7 @@ public: return {}; } - static optional toBool(const mbgl::android::Value& value) { + static std::optional toBool(const mbgl::android::Value& value) { if (value.isBool()) { return value.toBool(); } else { @@ -70,7 +70,7 @@ public: } } - static optional toNumber(const mbgl::android::Value& value) { + static std::optional toNumber(const mbgl::android::Value& value) { if (value.isNumber()) { auto num = value.toFloat(); return num; @@ -79,7 +79,7 @@ public: } } - static optional toDouble(const mbgl::android::Value& value) { + static std::optional toDouble(const mbgl::android::Value& value) { if (value.isNumber()) { return value.toDouble(); } else { @@ -87,7 +87,7 @@ public: } } - static optional toString(const mbgl::android::Value& value) { + static std::optional toString(const mbgl::android::Value& value) { if (value.isString()) { return value.toString(); } else { @@ -95,7 +95,7 @@ public: } } - static optional toValue(const mbgl::android::Value& value) { + static std::optional toValue(const mbgl::android::Value& value) { if (value.isNull()) { return {}; } else if (value.isBool()) { @@ -109,7 +109,7 @@ public: } } - static optional toGeoJSON(const mbgl::android::Value &value, Error &error) { + static std::optional toGeoJSON(const mbgl::android::Value &value, Error &error) { if (value.isNull()) { error = { "no json data found" }; return {}; @@ -139,7 +139,7 @@ public: }; template -optional convert(mbgl::android::Value&& value, Error& error, Args&&...args) { +std::optional convert(mbgl::android::Value&& value, Error& error, Args&&...args) { return convert(Convertible(std::move(value)), error, std::forward(args)...); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.cpp index d15e2747a..680c72af9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.cpp @@ -8,8 +8,8 @@ namespace mbgl { namespace android { namespace conversion { -optional toFilter(jni::JNIEnv& env, const jni::Array>& jfilter) { - mbgl::optional filter; +std::optional toFilter(jni::JNIEnv& env, const jni::Array>& jfilter) { + std::optional filter; if (jfilter) { mbgl::style::conversion::Error error; auto converted = mbgl::style::conversion::convert(Value(env, jfilter), error); diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.hpp index 920d336a1..15e60c91c 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/filter.hpp @@ -1,7 +1,6 @@ #pragma once #include -#include #include @@ -9,7 +8,7 @@ namespace mbgl { namespace android { namespace conversion { -optional toFilter(jni::JNIEnv&, const jni::Array>&); +std::optional toFilter(jni::JNIEnv&, const jni::Array>&); } // namespace conversion } // namespace android diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/url_or_tileset.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/url_or_tileset.cpp index 2ec585675..238c3ce07 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/url_or_tileset.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/conversion/url_or_tileset.cpp @@ -16,7 +16,7 @@ variant convertURLOrTileset(mbgl::android::Value&& value) const Convertible convertible(std::move(value)); if (isObject(convertible)) { Error error; - optional tileset = convert(convertible, error); + std::optional tileset = convert(convertible, error); if (!tileset) { throw std::logic_error(error.message); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp index 47984e140..a4bf2dd52 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.cpp @@ -40,7 +40,7 @@ namespace android { Layer::~Layer() { } - void Layer::addToStyle(mbgl::style::Style& style, mbgl::optional before) { + void Layer::addToStyle(mbgl::style::Style& style, std::optional before) { // Check to see if we own the layer first if (!ownedLayer) { throw std::runtime_error("Cannot add layer twice"); @@ -69,7 +69,7 @@ namespace android { void Layer::setProperty(jni::JNIEnv& env, const jni::String& jname, const jni::Object<>& jvalue) { // Convert and set property - optional error = + std::optional error = layer.setProperty(jni::Make(env, jname), Value(env, jvalue)); if (error) { mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make(env, jname) + " " + error->message); @@ -82,7 +82,7 @@ namespace android { using namespace mbgl::style::conversion; Error error; - optional converted = convert(Value(env, jfilter), error); + std::optional converted = convert(Value(env, jfilter), error); if (!converted) { mbgl::Log::Error(mbgl::Event::JNI, "Error setting filter: " + error.message); return; diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp index 557990844..d0ebf37fc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/layers/layer.hpp @@ -27,7 +27,7 @@ public: */ void setLayer(std::unique_ptr); - void addToStyle(mbgl::style::Style&, mbgl::optional); + void addToStyle(mbgl::style::Style&, std::optional); // Release the owned view and return it std::unique_ptr releaseCoreLayer(); diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp index b0deacfa5..679201ded 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/custom_geometry_source.cpp @@ -30,7 +30,7 @@ namespace android { return style::CustomGeometrySource::Options(); } Error error; - optional result = convert(Value(env, options), error); + std::optional result = convert(Value(env, options), error); if (!result) { throw std::logic_error(error.message); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/geojson_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/geojson_source.cpp index 5b699e9c6..9993f009b 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/geojson_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/geojson_source.cpp @@ -36,7 +36,7 @@ static Immutable convertGeoJSONOptions(jni::JNIEnv& env, return style::GeoJSONOptions::defaultOptions(); } Error error; - optional result = convert(mbgl::android::Value(env, options), error); + std::optional result = convert(mbgl::android::Value(env, options), error); if (!result) { throw std::logic_error(error.message); } @@ -85,7 +85,7 @@ void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, const jni::String& jStrin } jni::Local GeoJSONSource::getURL(jni::JNIEnv& env) { - optional url = source.as()->getURL(); + std::optional url = source.as()->getURL(); return url ? jni::Make(env, *url) : jni::Local(); } @@ -231,7 +231,7 @@ void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, const jni::String& jStrin android::UniqueEnv _env = android::AttachEnv(); // Convert the jni object Error error; - optional converted = parseGeoJSON(*json, error); + std::optional converted = parseGeoJSON(*json, error); if(!converted) { mbgl::Log::Error(mbgl::Event::JNI, "Error setting geo json: " + error.message); return; diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/image_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/image_source.cpp index 614c39c21..85924b7cc 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/image_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/image_source.cpp @@ -34,7 +34,7 @@ namespace android { } jni::Local ImageSource::getURL(jni::JNIEnv& env) { - optional url = source.as()->ImageSource::getURL(); + std::optional url = source.as()->ImageSource::getURL(); return url ? jni::Make(env, *url) : jni::Local(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_dem_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_dem_source.cpp index a33e00259..f456c030f 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_dem_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_dem_source.cpp @@ -31,7 +31,7 @@ namespace android { RasterDEMSource::~RasterDEMSource() = default; jni::Local RasterDEMSource::getURL(jni::JNIEnv& env) { - optional url = source.as()->RasterDEMSource::getURL(); + std::optional url = source.as()->RasterDEMSource::getURL(); return url ? jni::Make(env, *url) : jni::Local(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_source.cpp index 67603e74c..c7462f7d9 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/raster_source.cpp @@ -28,7 +28,7 @@ namespace android { RasterSource::~RasterSource() = default; jni::Local RasterSource::getURL(jni::JNIEnv& env) { - optional url = source.as()->RasterSource::getURL(); + std::optional url = source.as()->RasterSource::getURL(); return url ? jni::Make(env, *url) : jni::Local(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp index 2b0b4fb51..f43863363 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/source.cpp @@ -108,7 +108,7 @@ static std::unique_ptr createSourcePeer(jni::JNIEnv& env, void Source::setPrefetchZoomDelta(jni::JNIEnv& env, jni::Integer& delta) { if (!delta) { - source.setPrefetchZoomDelta(nullopt); + source.setPrefetchZoomDelta(std::nullopt); } else { source.setPrefetchZoomDelta(jni::Unbox(env, delta)); } @@ -124,7 +124,7 @@ static std::unique_ptr createSourcePeer(jni::JNIEnv& env, void Source::setMaxOverscaleFactorForParentTiles(jni::JNIEnv& env, jni::Integer& maxOverscaleFactor) { if (!maxOverscaleFactor) { - source.setMaxOverscaleFactorForParentTiles(nullopt); + source.setMaxOverscaleFactorForParentTiles(std::nullopt); } else { source.setMaxOverscaleFactorForParentTiles(jni::Unbox(env, maxOverscaleFactor)); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/vector_source.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/vector_source.cpp index 2be1a7811..1c34aba55 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/vector_source.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/style/sources/vector_source.cpp @@ -36,7 +36,7 @@ namespace android { VectorSource::~VectorSource() = default; jni::Local VectorSource::getURL(jni::JNIEnv& env) { - optional url = source.as()->VectorSource::getURL(); + std::optional url = source.as()->VectorSource::getURL(); return url ? jni::Make(env, *url) : jni::Local(); } diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/text/local_glyph_rasterizer.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/text/local_glyph_rasterizer.cpp index 5b31236cb..67e5caf05 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/text/local_glyph_rasterizer.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/text/local_glyph_rasterizer.cpp @@ -64,7 +64,7 @@ void LocalGlyphRasterizer::registerNative(jni::JNIEnv& env) { class LocalGlyphRasterizer::Impl { public: - Impl(const optional fontFamily_) + Impl(const std::optional fontFamily_) : fontFamily(fontFamily_) {} @@ -85,11 +85,11 @@ public: } private: - optional fontFamily; + std::optional fontFamily; android::LocalGlyphRasterizer androidLocalGlyphRasterizer; }; -LocalGlyphRasterizer::LocalGlyphRasterizer(const optional& fontFamily) +LocalGlyphRasterizer::LocalGlyphRasterizer(const std::optional& fontFamily) : impl(std::make_unique(fontFamily)) {} LocalGlyphRasterizer::~LocalGlyphRasterizer() diff --git a/platform/android/MapboxGLAndroidSDK/src/cpp/util/tile_server_options.cpp b/platform/android/MapboxGLAndroidSDK/src/cpp/util/tile_server_options.cpp index 971816ac5..339c6e663 100644 --- a/platform/android/MapboxGLAndroidSDK/src/cpp/util/tile_server_options.cpp +++ b/platform/android/MapboxGLAndroidSDK/src/cpp/util/tile_server_options.cpp @@ -11,11 +11,11 @@ jni::Local> TileServerOptions::New(jni::JNIEnv& e jni::String, jni::String, jni::String, jni::String, jni::String, jni::String, jni::String, jni::jboolean, jni::String, jni::Array>>(env); - optional sourceVersionPrefixValue = tileServerOptions.sourceVersionPrefix(); - optional styleVersionPrefixValue = tileServerOptions.styleVersionPrefix(); - optional spritesVersionPrefixValue = tileServerOptions.spritesVersionPrefix(); - optional glyphsVersionPrefixValue = tileServerOptions.glyphsVersionPrefix(); - optional tileVersionPrefixValue = tileServerOptions.tileVersionPrefix(); + std::optional sourceVersionPrefixValue = tileServerOptions.sourceVersionPrefix(); + std::optional styleVersionPrefixValue = tileServerOptions.styleVersionPrefix(); + std::optional spritesVersionPrefixValue = tileServerOptions.spritesVersionPrefix(); + std::optional glyphsVersionPrefixValue = tileServerOptions.glyphsVersionPrefix(); + std::optional tileVersionPrefixValue = tileServerOptions.tileVersionPrefix(); return javaClass.New(env, constructor, jni::Make(env, tileServerOptions.baseURL()), @@ -119,31 +119,31 @@ mbgl::TileServerOptions TileServerOptions::getTileServerOptions(jni::JNIEnv& env retVal.withSourceTemplate( jni::Make(env, options.Get(env, sourceTemplateField)), jni::Make(env, options.Get(env, sourceDomainNameField)), - sourcePrefixValue ? jni::Make(env, sourcePrefixValue): optional{}); + sourcePrefixValue ? jni::Make(env, sourcePrefixValue): std::optional{}); auto styleVersionPrefixValue = options.Get(env, styleVersionPrefixField); retVal.withStyleTemplate( jni::Make(env, options.Get(env, styleTemplateField)), jni::Make(env, options.Get(env, styleDomainNameField)), - styleVersionPrefixValue ? jni::Make(env, styleVersionPrefixValue): optional{}); + styleVersionPrefixValue ? jni::Make(env, styleVersionPrefixValue): std::optional{}); auto spritesVersionPrefixValue = options.Get(env, spritesVersionPrefixField); retVal.withSpritesTemplate( jni::Make(env, options.Get(env, spritesTemplateField)), jni::Make(env, options.Get(env, spritesDomainNameField)), - spritesVersionPrefixValue ? jni::Make(env, spritesVersionPrefixValue): optional{}); + spritesVersionPrefixValue ? jni::Make(env, spritesVersionPrefixValue): std::optional{}); auto glyphsVersionPrefixValue = options.Get(env, glyphsVersionPrefixField); retVal.withGlyphsTemplate( jni::Make(env, options.Get(env, glyphsTemplateField)), jni::Make(env, options.Get(env, glyphsDomainNameField)), - glyphsVersionPrefixValue ? jni::Make(env, glyphsVersionPrefixValue) : optional{}); + glyphsVersionPrefixValue ? jni::Make(env, glyphsVersionPrefixValue) : std::optional{}); auto tileVersionPrefixValue = options.Get(env, tileVersionPrefixField); retVal.withTileTemplate( jni::Make(env, options.Get(env, tileTemplateField)), jni::Make(env, options.Get(env, tileDomainNameField)), - tileVersionPrefixValue ? jni::Make(env, tileVersionPrefixValue): optional{}); + tileVersionPrefixValue ? jni::Make(env, tileVersionPrefixValue): std::optional{}); retVal.withDefaultStyle(jni::Make(env, options.Get(env, defaultStyleField))); retVal.withDefaultStyles(defaultStyles); diff --git a/platform/android/src/jni.cpp b/platform/android/src/jni.cpp index 189ec29dc..1c958c0ff 100755 --- a/platform/android/src/jni.cpp +++ b/platform/android/src/jni.cpp @@ -20,12 +20,12 @@ bool attach_jni_thread(JavaVM* vm, JNIEnv** env, std::string threadName) { ret = vm->GetEnv(reinterpret_cast(env), JNI_VERSION_1_6); if (ret != JNI_OK) { if (ret != JNI_EDETACHED) { - mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with %i", ret); + mbgl::Log::Error(mbgl::Event::JNI, "GetEnv() failed with " + std::to_string(ret)); throw std::runtime_error("GetEnv() failed"); } else { ret = vm->AttachCurrentThread(env, &args); if (ret != JNI_OK) { - mbgl::Log::Error(mbgl::Event::JNI, "AttachCurrentThread() failed with %i", ret); + mbgl::Log::Error(mbgl::Event::JNI, "AttachCurrentThread() failed with " + std::to_string(ret)); throw std::runtime_error("AttachCurrentThread() failed"); } detach = true; @@ -43,7 +43,7 @@ void detach_jni_thread(JavaVM* vm, JNIEnv** env, bool detach) { jint ret; if ((ret = vm->DetachCurrentThread()) != JNI_OK) { - mbgl::Log::Error(mbgl::Event::JNI, "DetachCurrentThread() failed with %i", ret); + mbgl::Log::Error(mbgl::Event::JNI, "DetachCurrentThread() failed with " + std::to_string(ret)); throw std::runtime_error("DetachCurrentThread() failed"); } } diff --git a/platform/android/src/test/collator_test_stub.cpp b/platform/android/src/test/collator_test_stub.cpp index 0d7c6c95b..137909d06 100644 --- a/platform/android/src/test/collator_test_stub.cpp +++ b/platform/android/src/test/collator_test_stub.cpp @@ -7,7 +7,7 @@ namespace platform { class Collator::Impl { public: - Impl(optional) {} + Impl(std::optional) {} bool operator==(const Impl&) const { return true; } @@ -16,7 +16,7 @@ public: std::string resolvedLocale() const { return ""; } }; -Collator::Collator(bool, bool, const optional& locale_) : impl(std::make_shared(locale_)) {} +Collator::Collator(bool, bool, const std::optional& locale_) : impl(std::make_shared(locale_)) {} int Collator::compare(const std::string& lhs, const std::string& rhs) const { return impl->compare(lhs, rhs); diff --git a/platform/android/src/test/test_runner.cpp b/platform/android/src/test/test_runner.cpp index 4f8b2165f..03faa72c1 100644 --- a/platform/android/src/test/test_runner.cpp +++ b/platform/android/src/test/test_runner.cpp @@ -23,7 +23,7 @@ void runner() { mbgl::Log::Info(mbgl::Event::General, "Start TestRunner"); int status = mbgl::runTests(argv.size(), argv.data()); - mbgl::Log::Info(mbgl::Event::General, "TestRunner finished with status: '%d'", status); + mbgl::Log::Info(mbgl::Event::General, "TestRunner finished with status: '" + std::to_string(status) + "'"); running = false; success = (status == 0); ALooper_wake(looper); @@ -48,7 +48,7 @@ void android_main(struct android_app* app) { runnerThread = std::thread(runner); } } else { - mbgl::Log::Error(mbgl::Event::General, "Failed to copy zip file '%s' to external storage", zipFile.c_str()); + mbgl::Log::Error(mbgl::Event::General, "Failed to copy zip file '" + zipFile + "' to external storage"); changeState(env, app, success); } diff --git a/platform/android/src/test/test_runner_common.cpp b/platform/android/src/test/test_runner_common.cpp index 9d17f72d0..600e24ce9 100644 --- a/platform/android/src/test/test_runner_common.cpp +++ b/platform/android/src/test/test_runner_common.cpp @@ -94,13 +94,13 @@ bool copyFile(JNIEnv* env, bool stateOk = true; if (env->CallBooleanMethod(fileToCopy.get(), fileExists)) { - mbgl::Log::Warning(mbgl::Event::General, "File '%s' already exists", filePath.c_str()); + mbgl::Log::Warning(mbgl::Event::General, "File '" + filePath + "' already exists"); } else { std::unique_ptr> fileAsset( AAssetManager_open(assetManager, fileName.c_str(), AASSET_MODE_BUFFER), [](AAsset* asset) { AAsset_close(asset); }); if (fileAsset == nullptr) { - mbgl::Log::Warning(mbgl::Event::General, "Failed to open asset file %s", fileName.c_str()); + mbgl::Log::Warning(mbgl::Event::General, "Failed to open asset file " + fileName); return false; } const void* fileData = AAsset_getBuffer(fileAsset.get()); @@ -111,12 +111,12 @@ bool copyFile(JNIEnv* env, stateOk = newFile != nullptr; if (!stateOk) { - mbgl::Log::Warning(mbgl::Event::General, "Failed to create new file entry %s", fileName.c_str()); + mbgl::Log::Warning(mbgl::Event::General, "Failed to create new file entry " + fileName); } else { auto res = static_cast(std::fwrite(fileData, sizeof(char), fileLen, newFile.get())); if (fileLen != res) { mbgl::Log::Warning( - mbgl::Event::General, "Failed to generate file entry %s from assets", fileName.c_str()); + mbgl::Event::General, "Failed to generate file entry" + fileName + "from assets"); } } } @@ -184,7 +184,7 @@ void unZipFile(JNIEnv* env, const std::string& zipFilePath, const std::string& d if (!success) { mbgl::Log::Warning( - mbgl::Event::General, "Failed to create folder entry %s from zip", fileNameStr.c_str()); + mbgl::Event::General, "Failed to create folder entry " + fileNameStr + " from zip"); } } } else if (!(env->CallBooleanMethod(f, fileExists))) { @@ -194,7 +194,7 @@ void unZipFile(JNIEnv* env, const std::string& zipFilePath, const std::string& d if (!success) { mbgl::Log::Warning( - mbgl::Event::General, "Failed to create folder entry %s from zip", fileNameStr.c_str()); + mbgl::Event::General, "Failed to create folder entry" + fileNameStr + "from zip"); continue; } @@ -215,7 +215,7 @@ void unZipFile(JNIEnv* env, const std::string& zipFilePath, const std::string& d if (env->CallBooleanMethod(fileToDelete.get(), fileExists)) { jboolean success = (env->CallBooleanMethod(fileToDelete.get(), deleteFile)); if (!success) { - mbgl::Log::Warning(mbgl::Event::General, "Failed to delete file entry %s", zipFilePath.c_str()); + mbgl::Log::Warning(mbgl::Event::General, "Failed to delete file entry " + zipFilePath); } } } diff --git a/platform/darwin/src/collator.mm b/platform/darwin/src/collator.mm index 7d5da5148..8e0248860 100644 --- a/platform/darwin/src/collator.mm +++ b/platform/darwin/src/collator.mm @@ -9,7 +9,7 @@ namespace platform { class Collator::Impl { public: - Impl(bool caseSensitive, bool diacriticSensitive, const optional& locale_) + Impl(bool caseSensitive, bool diacriticSensitive, const std::optional& locale_) : options((caseSensitive ? 0 : NSCaseInsensitiveSearch) | (diacriticSensitive ? 0 : NSDiacriticInsensitiveSearch)) , locale(locale_ ? @@ -47,7 +47,7 @@ private: NSLocale* locale; }; -Collator::Collator(bool caseSensitive, bool diacriticSensitive, const optional& locale_) +Collator::Collator(bool caseSensitive, bool diacriticSensitive, const std::optional& locale_) : impl(std::make_shared(caseSensitive, diacriticSensitive, locale_)) {} diff --git a/platform/darwin/src/http_file_source.mm b/platform/darwin/src/http_file_source.mm index 35bba09d0..8fc7e1b55 100644 --- a/platform/darwin/src/http_file_source.mm +++ b/platform/darwin/src/http_file_source.mm @@ -369,14 +369,14 @@ std::unique_ptr HTTPFileSource::request(const Resource& resource, std::make_unique(Error::Reason::NotFound, "HTTP status code 404"); } else if (responseCode == 429) { // Get the standard header - optional retryAfter; + std::optional retryAfter; NSString *retryAfterHeader = headers[@"Retry-After"]; if (retryAfterHeader) { retryAfter = std::string([retryAfterHeader UTF8String]); } // Fallback mapbox specific header - optional xRateLimitReset; + std::optional xRateLimitReset; NSString *xReset = headers[@"x-rate-limit-reset"]; if (xReset) { xRateLimitReset = std::string([xReset UTF8String]); diff --git a/platform/darwin/src/local_glyph_rasterizer.mm b/platform/darwin/src/local_glyph_rasterizer.mm index dd1e31870..e06ccb355 100644 --- a/platform/darwin/src/local_glyph_rasterizer.mm +++ b/platform/darwin/src/local_glyph_rasterizer.mm @@ -75,7 +75,7 @@ public: glyph rasterization globally. The system font is a good default value to pass into this constructor. */ - Impl(const optional fallbackFontNames_) + Impl(const std::optional fallbackFontNames_) { fallbackFontNames = [[NSUserDefaults standardUserDefaults] stringArrayForKey:@"MGLIdeographicFontFamilyName"]; if (fallbackFontNames_) { @@ -162,7 +162,7 @@ private: NSArray *fallbackFontNames; }; -LocalGlyphRasterizer::LocalGlyphRasterizer(const optional& fontFamily) +LocalGlyphRasterizer::LocalGlyphRasterizer(const std::optional& fontFamily) : impl(std::make_unique(fontFamily)) {} diff --git a/platform/default/include/mbgl/gfx/headless_frontend.hpp b/platform/default/include/mbgl/gfx/headless_frontend.hpp index 3c49e78cd..1e1f1c140 100644 --- a/platform/default/include/mbgl/gfx/headless_frontend.hpp +++ b/platform/default/include/mbgl/gfx/headless_frontend.hpp @@ -5,10 +5,10 @@ #include #include #include -#include #include #include +#include namespace mbgl { @@ -26,12 +26,12 @@ public: HeadlessFrontend(float pixelRatio_, gfx::HeadlessBackend::SwapBehaviour swapBehavior = gfx::HeadlessBackend::SwapBehaviour::NoFlush, gfx::ContextMode mode = gfx::ContextMode::Unique, - const optional& localFontFamily = {}); + const std::optional& localFontFamily = std::nullopt); HeadlessFrontend(Size, float pixelRatio_, gfx::HeadlessBackend::SwapBehaviour swapBehavior = gfx::HeadlessBackend::SwapBehaviour::NoFlush, gfx::ContextMode mode = gfx::ContextMode::Unique, - const optional& localFontFamily = {}); + const std::optional& localFontFamily = std::nullopt); ~HeadlessFrontend() override; void reset() override; @@ -57,7 +57,7 @@ public: RenderResult render(Map&); void renderOnce(Map&); - optional getTransformState() const; + std::optional getTransformState() const; private: Size size; diff --git a/platform/default/include/mbgl/map/map_snapshotter.hpp b/platform/default/include/mbgl/map/map_snapshotter.hpp index 6bb3ca40c..f41ffb5e6 100644 --- a/platform/default/include/mbgl/map/map_snapshotter.hpp +++ b/platform/default/include/mbgl/map/map_snapshotter.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -10,6 +9,8 @@ #include #include #include +#include + namespace mbgl { struct CameraOptions; @@ -38,7 +39,7 @@ public: const ResourceOptions&, const ClientOptions&, MapSnapshotterObserver&, - optional localFontFamily = nullopt); + std::optional localFontFamily = std::nullopt); MapSnapshotter(Size size, float pixelRatio, const ResourceOptions&, const ClientOptions& = ClientOptions()); diff --git a/platform/default/include/mbgl/storage/offline_database.hpp b/platform/default/include/mbgl/storage/offline_database.hpp index 2d6117f5f..6a49de10a 100644 --- a/platform/default/include/mbgl/storage/offline_database.hpp +++ b/platform/default/include/mbgl/storage/offline_database.hpp @@ -4,7 +4,6 @@ #include #include #include -#include #include #include #include @@ -13,6 +12,7 @@ #include #include #include +#include namespace mapbox { namespace sqlite { @@ -44,7 +44,7 @@ public: void changePath(const std::string&); std::exception_ptr resetDatabase(); - optional get(const Resource&); + std::optional get(const Resource&); // Return value is (inserted, stored size) std::pair put(const Resource&, const Response&); @@ -75,8 +75,8 @@ public: std::exception_ptr invalidateRegion(int64_t regionID); // Return value is (response, stored size) - optional> getRegionResource(const Resource&); - optional hasRegionResource(const Resource&); + std::optional> getRegionResource(const Resource&); + std::optional hasRegionResource(const Resource&); uint64_t putRegionResource(int64_t regionID, const Resource&, const Response&); void putRegionResources(int64_t regionID, const std::list>&, OfflineRegionStatus&); @@ -117,20 +117,20 @@ private: mapbox::sqlite::Statement& getStatement(const char *); - optional> getTile(const Resource::TileData&); - optional hasTile(const Resource::TileData&); + std::optional> getTile(const Resource::TileData&); + std::optional hasTile(const Resource::TileData&); bool putTile(const Resource::TileData&, const Response&, const std::string&, bool compressed); - optional> getResource(const Resource&); - optional hasResource(const Resource&); + std::optional> getResource(const Resource&); + std::optional hasResource(const Resource&); bool putResource(const Resource&, const Response&, const std::string&, bool compressed); uint64_t putRegionResourceInternal(int64_t regionID, const Resource&, const Response&); - optional> getInternal(const Resource&); - optional hasInternal(const Resource&); + std::optional> getInternal(const Resource&); + std::optional hasInternal(const Resource&); std::pair putInternal(const Resource&, const Response&, bool evict); // Return value is true iff the resource was previously unused by any other regions. @@ -149,7 +149,7 @@ private: uint64_t maximumAmbientCacheSize = util::DEFAULT_MAX_CACHE_SIZE; uint64_t offlineMapboxTileCountLimit = util::mapbox::DEFAULT_OFFLINE_TILE_COUNT_LIMIT; - optional offlineMapboxTileCount; + std::optional offlineMapboxTileCount; bool evict(uint64_t neededFreeSize, DatabaseSizeChangeStats& stats); @@ -181,7 +181,7 @@ private: // Lazily initializes currentAmbientCacheSize. std::exception_ptr initAmbientCacheSize(); - optional currentAmbientCacheSize; + std::optional currentAmbientCacheSize; void updateAmbientCacheSize(DatabaseSizeChangeStats&); bool autopack = true; diff --git a/platform/default/src/mbgl/gfx/headless_frontend.cpp b/platform/default/src/mbgl/gfx/headless_frontend.cpp index e98e2694c..e5bed4479 100644 --- a/platform/default/src/mbgl/gfx/headless_frontend.cpp +++ b/platform/default/src/mbgl/gfx/headless_frontend.cpp @@ -14,14 +14,14 @@ namespace mbgl { HeadlessFrontend::HeadlessFrontend(float pixelRatio_, gfx::HeadlessBackend::SwapBehaviour swapBehavior, const gfx::ContextMode contextMode, - const optional& localFontFamily) + const std::optional& localFontFamily) : HeadlessFrontend({256, 256}, pixelRatio_, swapBehavior, contextMode, localFontFamily) {} HeadlessFrontend::HeadlessFrontend(Size size_, float pixelRatio_, gfx::HeadlessBackend::SwapBehaviour swapBehavior, const gfx::ContextMode contextMode, - const optional& localFontFamily) + const std::optional& localFontFamily) : size(size_), pixelRatio(pixelRatio_), frameTime(0), @@ -169,7 +169,7 @@ void HeadlessFrontend::renderOnce(Map&) { util::RunLoop::Get()->runOnce(); } -optional HeadlessFrontend::getTransformState() const { +std::optional HeadlessFrontend::getTransformState() const { if (updateParameters) { return updateParameters->transformState; } else { diff --git a/platform/default/src/mbgl/i18n/collator.cpp b/platform/default/src/mbgl/i18n/collator.cpp index fe5917c7e..847d143cd 100644 --- a/platform/default/src/mbgl/i18n/collator.cpp +++ b/platform/default/src/mbgl/i18n/collator.cpp @@ -51,7 +51,7 @@ namespace platform { class Collator::Impl { public: - Impl(bool caseSensitive_, bool diacriticSensitive_, const optional&) + Impl(bool caseSensitive_, bool diacriticSensitive_, const std::optional&) : caseSensitive(caseSensitive_), diacriticSensitive(diacriticSensitive_) {} bool operator==(const Impl& other) const { @@ -93,7 +93,7 @@ std::string Collator::resolvedLocale() const { return impl->resolvedLocale(); } -Collator::Collator(bool caseSensitive, bool diacriticSensitive, const optional& locale) +Collator::Collator(bool caseSensitive, bool diacriticSensitive, const std::optional& locale) : impl(std::make_shared(caseSensitive, diacriticSensitive, locale)) {} } // namespace platform diff --git a/platform/default/src/mbgl/map/map_snapshotter.cpp b/platform/default/src/mbgl/map/map_snapshotter.cpp index 572f0d0ef..7ddd4daa2 100644 --- a/platform/default/src/mbgl/map/map_snapshotter.cpp +++ b/platform/default/src/mbgl/map/map_snapshotter.cpp @@ -52,7 +52,7 @@ private: class SnapshotterRenderer final : public RendererObserver { public: - SnapshotterRenderer(Size size, float pixelRatio, const optional& localFontFamily) + SnapshotterRenderer(Size size, float pixelRatio, const std::optional& localFontFamily) : frontend(size, pixelRatio, gfx::HeadlessBackend::SwapBehaviour::NoFlush, @@ -112,7 +112,7 @@ private: class SnapshotterRendererFrontend final : public RendererFrontend { public: - SnapshotterRendererFrontend(Size size, float pixelRatio, optional localFontFamily) + SnapshotterRendererFrontend(Size size, float pixelRatio, std::optional localFontFamily) : renderer(std::make_unique>( "Snapshotter", size, pixelRatio, std::move(localFontFamily))) {} @@ -153,7 +153,7 @@ public: const ResourceOptions& resourceOptions, const ClientOptions& clientOptions, MapSnapshotterObserver& observer_, - optional localFontFamily) + std::optional localFontFamily) : observer(observer_), frontend(size, pixelRatio, std::move(localFontFamily)), map(frontend, @@ -256,7 +256,7 @@ MapSnapshotter::MapSnapshotter(Size size, const ResourceOptions& resourceOptions, const ClientOptions& clientOptions, MapSnapshotterObserver& observer, - optional localFontFamily) + std::optional localFontFamily) : impl(std::make_unique( size, pixelRatio, resourceOptions, clientOptions, observer, std::move(localFontFamily))) {} diff --git a/platform/default/src/mbgl/storage/database_file_source.cpp b/platform/default/src/mbgl/storage/database_file_source.cpp index 3e7729edd..3215e161a 100644 --- a/platform/default/src/mbgl/storage/database_file_source.cpp +++ b/platform/default/src/mbgl/storage/database_file_source.cpp @@ -25,8 +25,8 @@ public: ), onlineFileSource(std::move(onlineFileSource_)) {} void request(const Resource& resource, const ActorRef& req) { - optional offlineResponse = - (resource.storagePolicy != Resource::StoragePolicy::Volatile) ? db->get(resource) : nullopt; + std::optional offlineResponse = + (resource.storagePolicy != Resource::StoragePolicy::Volatile) ? db->get(resource) : std::nullopt; if (!offlineResponse) { offlineResponse.emplace(); offlineResponse->noContent = true; diff --git a/platform/default/src/mbgl/storage/http_file_source.cpp b/platform/default/src/mbgl/storage/http_file_source.cpp index e16ed4fd3..09bb87faa 100644 --- a/platform/default/src/mbgl/storage/http_file_source.cpp +++ b/platform/default/src/mbgl/storage/http_file_source.cpp @@ -6,7 +6,6 @@ #include #include -#include #include #include #include @@ -21,6 +20,7 @@ #include #include #include +#include static void handleError(CURLMcode code) { if (code != CURLM_OK) { @@ -96,8 +96,8 @@ private: std::shared_ptr data; std::unique_ptr response; - optional retryAfter; - optional xRateLimitReset; + std::optional retryAfter; + std::optional xRateLimitReset; CURL *handle = nullptr; curl_slist *headers = nullptr; diff --git a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp index 64bccb599..2f25270c4 100644 --- a/platform/default/src/mbgl/storage/mbtiles_file_source.cpp +++ b/platform/default/src/mbgl/storage/mbtiles_file_source.cpp @@ -211,7 +211,7 @@ public: for (mapbox::sqlite::Query q(stmt); q.run();) { - optional data = q.get>(0); + std::optional data = q.get>(0); if (data) { response.data = std::make_shared(*data); response.noContent = false; diff --git a/platform/default/src/mbgl/storage/offline_database.cpp b/platform/default/src/mbgl/storage/offline_database.cpp index c8f547d03..f11836ad2 100644 --- a/platform/default/src/mbgl/storage/offline_database.cpp +++ b/platform/default/src/mbgl/storage/offline_database.cpp @@ -108,7 +108,7 @@ void OfflineDatabase::handleError(const mapbox::sqlite::Exception& ex, const cha ex.extendedCode == mapbox::sqlite::ExtendedResultCode::ReadOnlyDBMoved)) { // The database was corruped, moved away, or deleted. We're going to start fresh with a // clean slate for the next operation. - Log::Error(Event::Database, static_cast(ex.code), "Can't %s: %s", action, ex.what()); + Log::Error(Event::Database, static_cast(ex.code), std::string("Can't ") + action + ": " + ex.what()); try { removeExisting(); } catch (const util::IOException& ioEx) { @@ -116,17 +116,17 @@ void OfflineDatabase::handleError(const mapbox::sqlite::Exception& ex, const cha } } else { // We treat the error as temporary, and pretend we have an inaccessible DB. - Log::Warning(Event::Database, static_cast(ex.code), "Can't %s: %s", action, ex.what()); + Log::Warning(Event::Database, static_cast(ex.code), std::string("Can't ") + action + ": " + ex.what()); } } void OfflineDatabase::handleError(const util::IOException& ex, const char* action) { // We failed to delete the database file. - Log::Error(Event::Database, ex.code, "Can't %s: %s", action, ex.what()); + Log::Error(Event::Database, ex.code, std::string("Can't ") + action + ": " + ex.what()); } void OfflineDatabase::handleError(const std::runtime_error& ex, const char* action) { - Log::Error(Event::Database, "Can't %s: %s", action, ex.what()); + Log::Error(Event::Database, std::string("Can't ") + action + ": " + ex.what()); } void OfflineDatabase::handleError(const char* action) { @@ -143,7 +143,7 @@ void OfflineDatabase::handleError(const char* action) { handleError(ex, action); } catch (...) { assert(false); - Log::Error(Event::Database, "Can't %s", action); + Log::Error(Event::Database, std::string("Can't ") + action); } } @@ -240,19 +240,19 @@ mapbox::sqlite::Statement& OfflineDatabase::getStatement(const char* sql) { return *it->second; } -optional OfflineDatabase::get(const Resource& resource) try { +std::optional OfflineDatabase::get(const Resource& resource) try { if (disabled()) { - return nullopt; + return std::nullopt; } auto result = getInternal(resource); - return result ? optional{ result->first } : nullopt; + return result ? std::optional{ result->first } : std::nullopt; } catch (...) { handleError("read resource"); - return nullopt; + return std::nullopt; } -optional> OfflineDatabase::getInternal(const Resource& resource) { +std::optional> OfflineDatabase::getInternal(const Resource& resource) { if (resource.kind == Resource::Kind::Tile) { assert(resource.tileData); return getTile(*resource.tileData); @@ -261,7 +261,7 @@ optional> OfflineDatabase::getInternal(const Resou } } -optional OfflineDatabase::hasInternal(const Resource& resource) { +std::optional OfflineDatabase::hasInternal(const Resource& resource) { if (resource.kind == Resource::Kind::Tile) { assert(resource.tileData); return hasTile(*resource.tileData); @@ -307,7 +307,7 @@ std::pair OfflineDatabase::putInternal(const Resource& resource, size = compressed ? compressedData.size() : response.data->size(); } - optional stats; + std::optional stats; if (evict_) { stats = DatabaseSizeChangeStats(this); if (!evict(size, *stats)) { @@ -336,7 +336,7 @@ std::pair OfflineDatabase::putInternal(const Resource& resource, return { inserted, size }; } -optional> OfflineDatabase::getResource(const Resource& resource) { +std::optional> OfflineDatabase::getResource(const Resource& resource) { // Update accessed timestamp used for LRU eviction. if (!readOnly) { try { @@ -350,7 +350,7 @@ optional> OfflineDatabase::getResource(const Resou } // If we don't have any indication that the database is corrupt, continue as usual. - Log::Warning(Event::Database, static_cast(ex.code), "Can't update timestamp: %s", ex.what()); + Log::Warning(Event::Database, static_cast(ex.code), std::string("Can't update timestamp: ") + ex.what()); } } @@ -365,18 +365,18 @@ optional> OfflineDatabase::getResource(const Resou query.bind(1, resource.url); if (!query.run()) { - return nullopt; + return std::nullopt; } Response response; uint64_t size = 0; - response.etag = query.get>(0); - response.expires = query.get>(1); + response.etag = query.get>(0); + response.expires = query.get>(1); response.mustRevalidate = query.get(2); - response.modified = query.get>(3); + response.modified = query.get>(3); - auto data = query.get>(4); + auto data = query.get>(4); if (!data) { response.noContent = true; } else if (query.get(5)) { @@ -390,14 +390,14 @@ optional> OfflineDatabase::getResource(const Resou return std::make_pair(response, size); } -optional OfflineDatabase::hasResource(const Resource& resource) { +std::optional OfflineDatabase::hasResource(const Resource& resource) { mapbox::sqlite::Query query{ getStatement("SELECT length(data) FROM resources WHERE url = ?") }; query.bind(1, resource.url); if (!query.run()) { - return nullopt; + return std::nullopt; } - return query.get>(0); + return query.get>(0); } bool OfflineDatabase::putResource(const Resource& resource, @@ -487,7 +487,7 @@ bool OfflineDatabase::putResource(const Resource& resource, return true; } -optional> OfflineDatabase::getTile(const Resource::TileData& tile) { +std::optional> OfflineDatabase::getTile(const Resource::TileData& tile) { // Update accessed timestamp used for LRU eviction. if (!readOnly) { try { @@ -515,7 +515,7 @@ optional> OfflineDatabase::getTile(const Resource: } // If we don't have any indication that the database is corrupt, continue as usual. - Log::Warning(Event::Database, static_cast(ex.code), "Can't update timestamp: %s", ex.what()); + Log::Warning(Event::Database, static_cast(ex.code), std::string("Can't update timestamp: ") + ex.what()); } } @@ -538,18 +538,18 @@ optional> OfflineDatabase::getTile(const Resource: query.bind(5, tile.z); if (!query.run()) { - return nullopt; + return std::nullopt; } Response response; uint64_t size = 0; - response.etag = query.get>(0); - response.expires = query.get>(1); + response.etag = query.get>(0); + response.expires = query.get>(1); response.mustRevalidate = query.get(2); - response.modified = query.get>(3); + response.modified = query.get>(3); - optional data = query.get>(4); + std::optional data = query.get>(4); if (!data) { response.noContent = true; } else if (query.get(5)) { @@ -563,7 +563,7 @@ optional> OfflineDatabase::getTile(const Resource: return std::make_pair(response, size); } -optional OfflineDatabase::hasTile(const Resource::TileData& tile) { +std::optional OfflineDatabase::hasTile(const Resource::TileData& tile) { // clang-format off mapbox::sqlite::Query size{ getStatement( "SELECT length(data) " @@ -582,10 +582,10 @@ optional OfflineDatabase::hasTile(const Resource::TileData& tile) { size.bind(5, tile.z); if (!size.run()) { - return nullopt; + return std::nullopt; } - return size.get>(0); + return size.get>(0); } bool OfflineDatabase::putTile(const Resource::TileData& tile, @@ -811,7 +811,7 @@ expected OfflineDatabase::listRegions() try } catch (const std::exception& ex) { // Catch errors from malformed offline region definitions // and skip them. - Log::Error(Event::General, "%s", ex.what()); + Log::Error(Event::General, ex.what()); } } // Explicit move to avoid triggering the copy constructor. @@ -853,7 +853,8 @@ OfflineDatabase::mergeDatabase(const std::string& sideDatabasePath) { query.bind(1, sideDatabasePath); query.run(); } catch (const mapbox::sqlite::Exception& ex) { - Log::Error(Event::Database, static_cast(ex.code), "Can't attach database (%s) for merge: %s", sideDatabasePath.c_str(), ex.what()); + Log::Error(Event::Database, static_cast(ex.code), std::string("Can't attach database (") + sideDatabasePath + ") for merge: " + ex.what()); + return unexpected(std::current_exception()); } try { @@ -913,7 +914,7 @@ OfflineDatabase::mergeDatabase(const std::string& sideDatabasePath) { return { std::move(result) }; } catch (const std::runtime_error& ex) { db->exec("DETACH DATABASE side"); - Log::Error(Event::Database, "%s", ex.what()); + Log::Error(Event::Database, std::string(ex.what())); return unexpected(std::current_exception()); } @@ -955,25 +956,25 @@ std::exception_ptr OfflineDatabase::deleteRegion(OfflineRegion&& region) try { updateAmbientCacheSize(stats); // Ensure that the cached offlineTileCount value is recalculated. - offlineMapboxTileCount = nullopt; + offlineMapboxTileCount = std::nullopt; return nullptr; } catch (...) { handleError("delete region"); return std::current_exception(); } -optional> OfflineDatabase::getRegionResource(const Resource& resource) try { +std::optional> OfflineDatabase::getRegionResource(const Resource& resource) try { return getInternal(resource); } catch (...) { handleError("read region resource"); - return nullopt; + return std::nullopt; } -optional OfflineDatabase::hasRegionResource(const Resource& resource) try { +std::optional OfflineDatabase::hasRegionResource(const Resource& resource) try { return hasInternal(resource); } catch (...) { handleError("query region resource"); - return nullopt; + return std::nullopt; } uint64_t OfflineDatabase::putRegionResource(int64_t regionID, diff --git a/platform/default/src/mbgl/storage/offline_download.cpp b/platform/default/src/mbgl/storage/offline_download.cpp index e109aba1f..c4933a109 100644 --- a/platform/default/src/mbgl/storage/offline_download.cpp +++ b/platform/default/src/mbgl/storage/offline_download.cpp @@ -134,7 +134,7 @@ OfflineRegionStatus OfflineDownload::getStatus() const { } result->requiredResourceCount++; - optional styleResponse = + std::optional styleResponse = offlineDatabase.get(Resource::style(definition.match([](auto& reg){ return reg.styleURL; }))); if (!styleResponse) { return *result; @@ -156,10 +156,10 @@ OfflineRegionStatus OfflineDownload::getStatus() const { } else { result->requiredResourceCount += 1; const auto& url = urlOrTileset.get(); - optional sourceResponse = offlineDatabase.get(Resource::source(url)); + std::optional sourceResponse = offlineDatabase.get(Resource::source(url)); if (sourceResponse) { style::conversion::Error error; - optional tileset = style::conversion::convertJSON(*sourceResponse->data, error); + std::optional tileset = style::conversion::convertJSON(*sourceResponse->data, error); if (tileset) { uint64_t tileSourceCount = tileCount(definition, type, tileSize, (*tileset).zoomRange); result->requiredTileCount += tileSourceCount; @@ -266,7 +266,7 @@ void OfflineDownload::activateDownload() { ensureResource(std::move(sourceResource), [=](const Response& sourceResponse) { style::conversion::Error error; - optional tileset = style::conversion::convertJSON(*sourceResponse.data, error); + std::optional tileset = style::conversion::convertJSON(*sourceResponse.data, error); if (tileset) { auto resourceOptions = onlineFileSource.getResourceOptions(); util::mapbox::canonicalizeTileset(resourceOptions.tileServerOptions(), *tileset, url, type, tileSize); @@ -451,12 +451,12 @@ void OfflineDownload::ensureResource(Resource&& resource, *workRequestsIt = util::RunLoop::Get()->invokeCancellable([=]() { requests.erase(workRequestsIt); const auto resourceKind = resource.kind; - auto getResourceSizeInDatabase = [&] () -> optional { - optional result; + auto getResourceSizeInDatabase = [&] () -> std::optional { + std::optional result; if (!callback) { result = offlineDatabase.hasRegionResource(resource); } else { - optional> response = offlineDatabase.getRegionResource(resource); + std::optional> response = offlineDatabase.getRegionResource(resource); if (response) { callback(response->first); result = response->second; @@ -467,7 +467,7 @@ void OfflineDownload::ensureResource(Resource&& resource, return result; }; - optional offlineResponse = getResourceSizeInDatabase(); + std::optional offlineResponse = getResourceSizeInDatabase(); if (offlineResponse) { assert(!resourcesToBeMarkedAsUsed.empty()); status.completedResourceCount++; diff --git a/platform/default/src/mbgl/storage/online_file_source.cpp b/platform/default/src/mbgl/storage/online_file_source.cpp index ce1d1fa1a..1e2b928ca 100644 --- a/platform/default/src/mbgl/storage/online_file_source.cpp +++ b/platform/default/src/mbgl/storage/online_file_source.cpp @@ -51,7 +51,7 @@ struct OnlineFileRequest { ActorRef actor(); void onCancel(std::function); - Duration getUpdateInterval(optional expires) const; + Duration getUpdateInterval(std::optional expires) const; OnlineFileSourceThread& impl; Resource resource; std::unique_ptr request; @@ -70,7 +70,7 @@ struct OnlineFileRequest { // backoff when retrying requests. uint32_t failedRequests = 0; Response::Error::Reason failedRequestReason = Response::Error::Reason::Success; - optional retryAfter; + std::optional retryAfter; }; class OnlineFileSourceThread { @@ -267,7 +267,7 @@ private: } } - optional pop() { + std::optional pop() { if (queue.empty()) { return {}; } @@ -443,7 +443,7 @@ OnlineFileRequest::~OnlineFileRequest() { } } -Timestamp interpolateExpiration(const Timestamp& current, optional prior, bool& expired) { +Timestamp interpolateExpiration(const Timestamp& current, std::optional prior, bool& expired) { auto now = util::now(); if (current > now) { return current; @@ -509,7 +509,7 @@ void OnlineFileRequest::schedule(Duration timeout) { }); } -Duration OnlineFileRequest::getUpdateInterval(optional expires) const { +Duration OnlineFileRequest::getUpdateInterval(std::optional expires) const { // Calculate a timeout that depends on how many // consecutive errors we've encountered, and on the expiration time, if present. Duration errorRetryTimeout = http::errorRetryTimeout(failedRequestReason, failedRequests, retryAfter); @@ -567,7 +567,7 @@ void OnlineFileRequest::completed(Response response) { if (response.error) { if (response.error->reason == Response::Error::Reason::NotFound) { - Log::Error(Event::General, "The resource `%s` not found", sanitizeURL(resource.url).c_str()); + Log::Error(Event::General, "The resource `" + sanitizeURL(resource.url) + "` not found"); } failedRequests++; failedRequestReason = response.error->reason; diff --git a/platform/default/src/mbgl/storage/sqlite3.cpp b/platform/default/src/mbgl/storage/sqlite3.cpp index c1be6a7a7..c6d4c6fc5 100644 --- a/platform/default/src/mbgl/storage/sqlite3.cpp +++ b/platform/default/src/mbgl/storage/sqlite3.cpp @@ -6,10 +6,10 @@ #include #include #include +#include #include #include -#include #define MBGL_CONSTRUCTOR(f) \ static void f(void); \ @@ -54,7 +54,7 @@ public: explicit DatabaseImpl(sqlite3* db_) : db(db_) { const int error = sqlite3_extended_result_codes(db, true); if (error != SQLITE_OK) { - mbgl::Log::Warning(mbgl::Event::Database, error, "Failed to enable extended result codes: %s", sqlite3_errmsg(db)); + mbgl::Log::Warning(mbgl::Event::Database, error, std::string("Failed to enable extended result codes: ") + sqlite3_errmsg(db)); } } @@ -308,7 +308,7 @@ void Query::bind( stmt.impl->check(sqlite3_bind_int64(stmt.impl->stmt, offset, std::chrono::system_clock::to_time_t(value))); } -template <> void Query::bind(int offset, mbgl::optional value) { +template <> void Query::bind(int offset, std::optional value) { if (!value) { bind(offset, nullptr); } else { @@ -319,7 +319,7 @@ template <> void Query::bind(int offset, mbgl::optional value) { template <> void Query::bind( int offset, - mbgl::optional> value) { + std::optional> value) { if (!value) { bind(offset, nullptr); } else { @@ -386,39 +386,39 @@ Query::get(int offset) { std::chrono::system_clock::from_time_t(sqlite3_column_int64(stmt.impl->stmt, offset))); } -template <> mbgl::optional Query::get(int offset) { +template <> std::optional Query::get(int offset) { assert(stmt.impl); if (sqlite3_column_type(stmt.impl->stmt, offset) == SQLITE_NULL) { - return mbgl::nullopt; + return std::nullopt; } else { return get(offset); } } -template <> mbgl::optional Query::get(int offset) { +template <> std::optional Query::get(int offset) { assert(stmt.impl); if (sqlite3_column_type(stmt.impl->stmt, offset) == SQLITE_NULL) { - return mbgl::nullopt; + return std::nullopt; } else { return get(offset); } } -template <> mbgl::optional Query::get(int offset) { +template <> std::optional Query::get(int offset) { assert(stmt.impl); if (sqlite3_column_type(stmt.impl->stmt, offset) == SQLITE_NULL) { - return mbgl::nullopt; + return std::nullopt; } else { return get(offset); } } template <> -mbgl::optional> +std::optional> Query::get(int offset) { assert(stmt.impl); if (sqlite3_column_type(stmt.impl->stmt, offset) == SQLITE_NULL) { - return mbgl::nullopt; + return std::nullopt; } else { return get>( offset); diff --git a/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp b/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp index 1aea1857f..ac9b40b29 100644 --- a/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp +++ b/platform/default/src/mbgl/text/local_glyph_rasterizer.cpp @@ -5,7 +5,7 @@ namespace mbgl { class LocalGlyphRasterizer::Impl { }; -LocalGlyphRasterizer::LocalGlyphRasterizer(const optional&) {} +LocalGlyphRasterizer::LocalGlyphRasterizer(const std::optional&) {} LocalGlyphRasterizer::~LocalGlyphRasterizer() = default; diff --git a/platform/default/src/mbgl/util/png_reader.cpp b/platform/default/src/mbgl/util/png_reader.cpp index 2936796bf..40448cf27 100644 --- a/platform/default/src/mbgl/util/png_reader.cpp +++ b/platform/default/src/mbgl/util/png_reader.cpp @@ -36,7 +36,7 @@ static void user_error_fn(png_structp, png_const_charp error_msg) { } static void user_warning_fn(png_structp, png_const_charp warning_msg) { - Log::Warning(Event::Image, "ImageReader (PNG): %s", warning_msg); + Log::Warning(Event::Image, std::string("ImageReader (PNG): ") + warning_msg); } static void png_read_data(png_structp png_ptr, png_bytep data, png_size_t length) { diff --git a/platform/glfw/glfw_view.cpp b/platform/glfw/glfw_view.cpp index a02fbde8a..d48ef2d16 100644 --- a/platform/glfw/glfw_view.cpp +++ b/platform/glfw/glfw_view.cpp @@ -52,6 +52,7 @@ #include #include #include +#include #if defined(MBGL_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_LOCATION_INDICATOR_DISABLE_ALL) #include @@ -118,7 +119,8 @@ void addFillExtrusionLayer(mbgl::style::Style &style, bool visible) { } // namespace void glfwError(int error, const char *description) { - mbgl::Log::Error(mbgl::Event::OpenGL, "GLFW error (%i): %s", error, description); + mbgl::Log::Error(mbgl::Event::OpenGL, std::string("GLFW error (") + std::to_string(error) + "): " + description); + } GLFWView::GLFWView(bool fullscreen_, bool benchmark_, const mbgl::ResourceOptions &resourceOptions, const mbgl::ClientOptions &clientOptions) @@ -739,10 +741,9 @@ void GLFWView::makeSnapshot(bool withOverlay) { const mbgl::MapSnapshotter::PointForFn &, const mbgl::MapSnapshotter::LatLngForFn &) { if (!ptr) { - mbgl::Log::Info(mbgl::Event::General, - "Made snapshot './snapshot.png' with size w:%dpx h:%dpx", - image.size.width, - image.size.height); + std::ostringstream oss; + oss << "Made snapshot './snapshot.png' with size w:" << image.size.width << "px h:" << image.size.height << "px"; + mbgl::Log::Info(mbgl::Event::General, oss.str()); std::ofstream file("./snapshot.png"); file << mbgl::encodePNG(image); } else { @@ -869,13 +870,13 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) { if (!result.empty()) { FeatureIdentifier id = result[0].id; - optional idStr = featureIDtoString(id); + std::optional idStr = featureIDtoString(id); if (idStr) { if (view->featureID && (*view->featureID != *idStr)) { newState["hover"] = false; view->rendererFrontend->getRenderer()->setFeatureState("states", {}, *view->featureID, newState); - view->featureID = nullopt; + view->featureID = std::nullopt; } if (!view->featureID) { @@ -888,7 +889,7 @@ void GLFWView::onMouseMove(GLFWwindow *window, double x, double y) { if (view->featureID) { newState["hover"] = false; view->rendererFrontend->getRenderer()->setFeatureState("states", {}, *view->featureID, newState); - view->featureID = nullopt; + view->featureID = std::nullopt; } } view->invalidate(); @@ -963,8 +964,12 @@ void GLFWView::report(float duration) { const double currentTime = glfwGetTime(); if (currentTime - lastReported >= 1) { frameTime /= frames; - mbgl::Log::Info(mbgl::Event::OpenGL, "Frame time: %6.2fms (%6.2f fps)", frameTime, - 1000 / frameTime); + + std::ostringstream oss; + oss.precision(2); + oss << "Frame time: " << std::fixed << frameTime << "ms (" << 1000 / frameTime << "fps)"; + mbgl::Log::Info(mbgl::Event::OpenGL, oss.str()); + frames = 0; frameTime = 0; lastReported = currentTime; diff --git a/platform/glfw/glfw_view.hpp b/platform/glfw/glfw_view.hpp index 3eed3aeec..c430fad6d 100644 --- a/platform/glfw/glfw_view.hpp +++ b/platform/glfw/glfw_view.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #if defined(MBGL_RENDER_BACKEND_OPENGL) && !defined(MBGL_LAYER_CUSTOM_DISABLE_ALL) @@ -11,6 +10,7 @@ #endif #include +#include struct GLFWwindow; class GLFWBackend; @@ -148,7 +148,7 @@ private: GLFWwindow *window = nullptr; bool dirty = false; - mbgl::optional featureID; + std::optional featureID; std::unique_ptr snapshotter; std::unique_ptr snapshotterObserver; mbgl::ResourceOptions mapResourceOptions; diff --git a/platform/glfw/main.cpp b/platform/glfw/main.cpp index e2ebcd5f3..c7df099c1 100644 --- a/platform/glfw/main.cpp +++ b/platform/glfw/main.cpp @@ -152,7 +152,7 @@ int main(int argc, char *argv[]) { } settings.online = !settings.online; onlineFileSource->setProperty("online-status", settings.online); - mbgl::Log::Info(mbgl::Event::Setup, "Application is %s. Press `O` to toggle online status.", settings.online ? "online" : "offline"); + mbgl::Log::Info(mbgl::Event::Setup, std::string("Application is ") + (settings.online ? "online" : "offline") + ". Press `O` to toggle online status."); }); view->setChangeStyleCallback([&map,&orderedStyles] () { @@ -166,7 +166,7 @@ int main(int argc, char *argv[]) { map.getStyle().loadURL(newStyle.getUrl()); view->setWindowTitle(newStyle.getName()); - mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: %s", newStyle.getName().c_str()); + mbgl::Log::Info(mbgl::Event::Setup, "Changed style to: " + newStyle.getName()); }); // Resource loader controls top-level request processing and can resume / pause all managed sources simultaneously. @@ -190,7 +190,7 @@ int main(int argc, char *argv[]) { view->setResetCacheCallback([databaseFileSource]() { databaseFileSource->resetDatabase([](const std::exception_ptr& ex) { if (ex) { - mbgl::Log::Error(mbgl::Event::Database, "Failed to reset cache:: %s", mbgl::util::toString(ex).c_str()); + mbgl::Log::Error(mbgl::Event::Database, "Failed to reset cache: " + mbgl::util::toString(ex)); } }); }); @@ -222,8 +222,10 @@ int main(int argc, char *argv[]) { settings.debug = mbgl::EnumType(map.getDebug()); settings.save(); mbgl::Log::Info(mbgl::Event::General, - R"(Exit location: --lat="%f" --lon="%f" --zoom="%f" --bearing "%f")", - settings.latitude, settings.longitude, settings.zoom, settings.bearing); + "Exit location: --lat=\"" + std::to_string(settings.latitude) + + "\" --lon=\"" + std::to_string(settings.longitude) + + "\" --zoom=\"" + std::to_string(settings.zoom) + + "\" --bearing=\"" + std::to_string(settings.bearing) + "\""); view = nullptr; diff --git a/platform/ios/platform/darwin/src/MGLAttributionInfo.mm b/platform/ios/platform/darwin/src/MGLAttributionInfo.mm index 7a9fbf2c7..7721319fa 100644 --- a/platform/ios/platform/darwin/src/MGLAttributionInfo.mm +++ b/platform/ios/platform/darwin/src/MGLAttributionInfo.mm @@ -34,11 +34,11 @@ if (fontSize) { NSString *sizeRule = [NSString stringWithFormat:@"font-size: %.1fpx;", fontSize]; #if !TARGET_OS_IPHONE - if (fontSize == [NSFont systemFontSizeForControlSize:NSMiniControlSize]) { + if (fontSize == [NSFont systemFontSizeForControlSize:NSControlSizeMini]) { sizeRule = @"font: -webkit-mini-control"; - } else if (fontSize == [NSFont systemFontSizeForControlSize:NSSmallControlSize]) { + } else if (fontSize == [NSFont systemFontSizeForControlSize:NSControlSizeSmall]) { sizeRule = @"font: -webkit-small-control"; - } else if (fontSize == [NSFont systemFontSizeForControlSize:NSRegularControlSize]) { + } else if (fontSize == [NSFont systemFontSizeForControlSize:NSControlSizeRegular]) { sizeRule = @"font: -webkit-control"; } #endif diff --git a/platform/ios/platform/darwin/src/MGLConversion.h b/platform/ios/platform/darwin/src/MGLConversion.h index 257b8dfc9..7048d3f0b 100644 --- a/platform/ios/platform/darwin/src/MGLConversion.h +++ b/platform/ios/platform/darwin/src/MGLConversion.h @@ -49,7 +49,7 @@ public: return {[value objectAtIndex: i]}; } - static optional objectMember(const Holder& holder, const char *key) { + static std::optional objectMember(const Holder& holder, const char *key) { const id value = holder.value; NSCAssert([value isKindOfClass:[NSDictionary class]], @"Value must be an NSDictionary for get(string)."); NSObject *member = [value objectForKey: @(key)]; @@ -64,7 +64,7 @@ public: #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wnullability-completeness" template - static optional eachMember(const Holder& holder, Fn&& visit) { + static std::optional eachMember(const Holder& holder, Fn&& visit) { #pragma clang diagnostic pop [holder.value enumerateKeysAndObjectsUsingBlock:^(id _Nonnull key, id _Nonnull obj, BOOL * _Nonnull stop) { auto result = visit(std::string(static_cast([key UTF8String])), obj); @@ -75,7 +75,7 @@ public: return {}; } - static optional toBool(const Holder& holder) { + static std::optional toBool(const Holder& holder) { const id value = holder.value; if (_isBool(value)) { return ((NSNumber *)value).boolValue; @@ -84,7 +84,7 @@ public: } } - static optional toNumber(const Holder& holder) { + static std::optional toNumber(const Holder& holder) { const id value = holder.value; if (_isNumber(value)) { return ((NSNumber *)value).floatValue; @@ -93,7 +93,7 @@ public: } } - static optional toDouble(const Holder& holder) { + static std::optional toDouble(const Holder& holder) { const id value = holder.value; if (_isNumber(value)) { return ((NSNumber *)value).doubleValue; @@ -102,7 +102,7 @@ public: } } - static optional toString(const Holder& holder) { + static std::optional toString(const Holder& holder) { const id value = holder.value; if (_isString(value)) { return std::string(static_cast([value UTF8String])); @@ -111,7 +111,7 @@ public: } } - static optional toValue(const Holder& holder) { + static std::optional toValue(const Holder& holder) { const id value = holder.value; if (isUndefined(value)) { return {}; @@ -126,7 +126,7 @@ public: } } - static optional toGeoJSON(const Holder& holder, Error& error) { + static std::optional toGeoJSON(const Holder& holder, Error& error) { id object = holder.value; if ([object isKindOfClass:[NSDictionary class]]) { NSError *serializationError; diff --git a/platform/ios/platform/darwin/src/MGLMapSnapshotter.mm b/platform/ios/platform/darwin/src/MGLMapSnapshotter.mm index 301ea8e64..af1510b61 100644 --- a/platform/ios/platform/darwin/src/MGLMapSnapshotter.mm +++ b/platform/ios/platform/darwin/src/MGLMapSnapshotter.mm @@ -568,7 +568,7 @@ NSArray *MGLAttributionInfosFromAttributions(mbgl::MapSnap CGFloat fontSize = [UIFont smallSystemFontSize]; UIColor *attributeFontColor = [UIColor blackColor]; #else - CGFloat fontSize = [NSFont systemFontSizeForControlSize:NSMiniControlSize]; + CGFloat fontSize = [NSFont systemFontSizeForControlSize:NSControlSizeMini]; NSColor *attributeFontColor = [NSColor blackColor]; #endif for (auto attribution : attributions) { diff --git a/platform/ios/platform/darwin/src/MGLMultiPoint.mm b/platform/ios/platform/darwin/src/MGLMultiPoint.mm index 19aacaea4..365c89574 100644 --- a/platform/ios/platform/darwin/src/MGLMultiPoint.mm +++ b/platform/ios/platform/darwin/src/MGLMultiPoint.mm @@ -7,7 +7,7 @@ @implementation MGLMultiPoint { - mbgl::optional _bounds; + std::optional _bounds; std::vector _coordinates; } diff --git a/platform/ios/platform/darwin/src/MGLPointCollection.mm b/platform/ios/platform/darwin/src/MGLPointCollection.mm index 6e056712f..65657ef21 100644 --- a/platform/ios/platform/darwin/src/MGLPointCollection.mm +++ b/platform/ios/platform/darwin/src/MGLPointCollection.mm @@ -10,7 +10,7 @@ NS_ASSUME_NONNULL_BEGIN @implementation MGLPointCollection { - mbgl::optional _bounds; + std::optional _bounds; std::vector _coordinates; } diff --git a/platform/ios/platform/darwin/src/MGLRendererFrontend.h b/platform/ios/platform/darwin/src/MGLRendererFrontend.h index e2b8260fd..492714eaf 100644 --- a/platform/ios/platform/darwin/src/MGLRendererFrontend.h +++ b/platform/ios/platform/darwin/src/MGLRendererFrontend.h @@ -3,8 +3,6 @@ #include #include #include -#include - /** The RenderFrontend is passed to the Map to facilitate rendering in a platform @@ -71,5 +69,5 @@ private: __weak MGLMapView *nativeView = nullptr; mbgl::gfx::RendererBackend& mbglBackend; std::shared_ptr updateParameters; - mbgl::optional asyncInvalidate; + std::optional asyncInvalidate; }; diff --git a/platform/ios/platform/darwin/src/MGLSettings.mm b/platform/ios/platform/darwin/src/MGLSettings.mm index a1a8273fc..c13717066 100644 --- a/platform/ios/platform/darwin/src/MGLSettings.mm +++ b/platform/ios/platform/darwin/src/MGLSettings.mm @@ -134,27 +134,27 @@ opts.withSourceTemplate( std::string([options.sourceTemplate UTF8String]), std::string([options.sourceDomainName UTF8String]), - options.sourceVersionPrefix ? std::string([options.sourceVersionPrefix UTF8String]) : mbgl::optional{}); + options.sourceVersionPrefix ? std::string([options.sourceVersionPrefix UTF8String]) : std::optional{}); opts.withStyleTemplate( std::string([options.styleTemplate UTF8String]), std::string([options.styleDomainName UTF8String]), - options.styleVersionPrefix ? std::string([options.styleVersionPrefix UTF8String]) : mbgl::optional{}); + options.styleVersionPrefix ? std::string([options.styleVersionPrefix UTF8String]) : std::optional{}); opts.withSpritesTemplate( std::string([options.spritesTemplate UTF8String]), std::string([options.spritesDomainName UTF8String]), - options.spritesVersionPrefix ? std::string([options.spritesVersionPrefix UTF8String]) : mbgl::optional{}); + options.spritesVersionPrefix ? std::string([options.spritesVersionPrefix UTF8String]) : std::optional{}); opts.withGlyphsTemplate( std::string([options.glyphsTemplate UTF8String]), std::string([options.glyphsDomainName UTF8String]), - options.glyphsVersionPrefix ? std::string([options.glyphsVersionPrefix UTF8String]) : mbgl::optional{}); + options.glyphsVersionPrefix ? std::string([options.glyphsVersionPrefix UTF8String]) : std::optional{}); opts.withTileTemplate( std::string([options.tileTemplate UTF8String]), std::string([options.tileDomainName UTF8String]), - options.tileVersionPrefix ? std::string([options.tileVersionPrefix UTF8String]) : mbgl::optional{}); + options.tileVersionPrefix ? std::string([options.tileVersionPrefix UTF8String]) : std::optional{}); std::vector defaultStyles; if (options.defaultStyles) { diff --git a/platform/ios/platform/darwin/src/MGLSettings_Private.h b/platform/ios/platform/darwin/src/MGLSettings_Private.h index 6e626a204..f4c08e8d1 100644 --- a/platform/ios/platform/darwin/src/MGLSettings_Private.h +++ b/platform/ios/platform/darwin/src/MGLSettings_Private.h @@ -1,7 +1,6 @@ #import "MGLSettings.h" #import #import -#import NS_ASSUME_NONNULL_BEGIN diff --git a/platform/ios/platform/darwin/src/MGLShapeSource.mm b/platform/ios/platform/darwin/src/MGLShapeSource.mm index 2f2b86c37..9ae0f6535 100644 --- a/platform/ios/platform/darwin/src/MGLShapeSource.mm +++ b/platform/ios/platform/darwin/src/MGLShapeSource.mm @@ -237,7 +237,7 @@ mbgl::Immutable MGLGeoJSONOptionsFromDictionary(NSD - (NSArray> *)featuresMatchingPredicate:(nullable NSPredicate *)predicate { MGLAssertStyleSourceIsValid(); - mbgl::optional optionalFilter; + std::optional optionalFilter; if (predicate) { optionalFilter = predicate.mgl_filter; } @@ -252,9 +252,9 @@ mbgl::Immutable MGLGeoJSONOptionsFromDictionary(NSD // MARK: - MGLCluster management -- (mbgl::optional)featureExtensionValueOfCluster:(MGLShape *)cluster extension:(std::string)extension options:(const std::map)options { +- (std::optional)featureExtensionValueOfCluster:(MGLShape *)cluster extension:(std::string)extension options:(const std::map)options { MGLAssertStyleSourceIsValid(); - mbgl::optional extensionValue; + std::optional extensionValue; // Check parameters if (!self.rawSource || !self.stylable || !cluster) { diff --git a/platform/ios/platform/darwin/src/MGLStyleLayer.mm b/platform/ios/platform/darwin/src/MGLStyleLayer.mm index 7847cbb31..fe650164b 100644 --- a/platform/ios/platform/darwin/src/MGLStyleLayer.mm +++ b/platform/ios/platform/darwin/src/MGLStyleLayer.mm @@ -47,7 +47,7 @@ const MGLExceptionName MGLInvalidStyleLayerException = @"MGLInvalidStyleLayerExc } if (otherLayer) { - const mbgl::optional belowLayerId{otherLayer.identifier.UTF8String}; + const std::optional belowLayerId{otherLayer.identifier.UTF8String}; style.rawStyle->addLayer(std::move(_pendingLayer), belowLayerId); } else { style.rawStyle->addLayer(std::move(_pendingLayer)); diff --git a/platform/ios/platform/darwin/src/MGLVectorTileSource.mm b/platform/ios/platform/darwin/src/MGLVectorTileSource.mm index f9a5401b1..0425e1d84 100644 --- a/platform/ios/platform/darwin/src/MGLVectorTileSource.mm +++ b/platform/ios/platform/darwin/src/MGLVectorTileSource.mm @@ -56,7 +56,7 @@ - (NSArray> *)featuresInSourceLayersWithIdentifiers:(NSSet *)sourceLayerIdentifiers predicate:(nullable NSPredicate *)predicate { MGLAssertStyleSourceIsValid(); - mbgl::optional> optionalSourceLayerIDs; + std::optional> optionalSourceLayerIDs; if (sourceLayerIdentifiers) { __block std::vector layerIDs; layerIDs.reserve(sourceLayerIdentifiers.count); @@ -66,7 +66,7 @@ optionalSourceLayerIDs = layerIDs; } - mbgl::optional optionalFilter; + std::optional optionalFilter; if (predicate) { optionalFilter = predicate.mgl_filter; } diff --git a/platform/ios/platform/ios/ios.xcodeproj/project.pbxproj b/platform/ios/platform/ios/ios.xcodeproj/project.pbxproj index 5723e98a4..d6e2a5f55 100644 --- a/platform/ios/platform/ios/ios.xcodeproj/project.pbxproj +++ b/platform/ios/platform/ios/ios.xcodeproj/project.pbxproj @@ -3724,6 +3724,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 10.3; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = "-Wno-ambiguous-macro"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SYMROOT = ../../build/ios; @@ -3797,6 +3798,7 @@ GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1"; INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LLVM_LTO = YES; ONLY_ACTIVE_ARCH = YES; @@ -4288,6 +4290,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 10.3; MTL_ENABLE_DEBUG_INFO = YES; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = "-Wno-ambiguous-macro"; SDKROOT = iphoneos; SYMROOT = ../../build/ios; TARGETED_DEVICE_FAMILY = "1,2"; @@ -4312,6 +4315,7 @@ IPHONEOS_DEPLOYMENT_TARGET = 10.3; MTL_ENABLE_DEBUG_INFO = NO; ONLY_ACTIVE_ARCH = YES; + OTHER_CFLAGS = "-Wno-ambiguous-macro"; SDKROOT = iphoneos; SWIFT_OPTIMIZATION_LEVEL = "-Owholemodule"; SYMROOT = ../../build/ios; @@ -4427,6 +4431,7 @@ DYLIB_INSTALL_NAME_BASE = "@rpath"; INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; ONLY_ACTIVE_ARCH = YES; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.Mapbox; @@ -4451,6 +4456,7 @@ GCC_PREPROCESSOR_DEFINITIONS = "NDEBUG=1"; INFOPLIST_FILE = framework/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; + IPHONEOS_DEPLOYMENT_TARGET = 11.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; LLVM_LTO = YES; ONLY_ACTIVE_ARCH = YES; diff --git a/platform/ios/platform/ios/src/MGLMapView.mm b/platform/ios/platform/ios/src/MGLMapView.mm index 947fc12d1..d611ceb1c 100644 --- a/platform/ios/platform/ios/src/MGLMapView.mm +++ b/platform/ios/platform/ios/src/MGLMapView.mm @@ -627,7 +627,7 @@ public: // setup mbgl map MGLRendererConfiguration *config = [MGLRendererConfiguration currentConfiguration]; - mbgl::optional localFontFamilyName = config.localFontFamilyName ? mbgl::optional(std::string(config.localFontFamilyName.UTF8String)) : mbgl::nullopt; + std::optional localFontFamilyName = config.localFontFamilyName ? std::optional(std::string(config.localFontFamilyName.UTF8String)) : std::nullopt; auto renderer = std::make_unique(_mbglView->getRendererBackend(), config.scaleFactor, localFontFamilyName); BOOL enableCrossSourceCollisions = !config.perSourceCollisions; _rendererFrontend = std::make_unique(std::move(renderer), self, _mbglView->getRendererBackend()); @@ -1031,7 +1031,10 @@ public: automaticallyAdjustContentInset = _automaticallyAdjustContentInsetHolder.boolValue; } else { UIViewController *viewController = [self rootViewController]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" automaticallyAdjustContentInset = viewController.automaticallyAdjustsScrollViewInsets; +#pragma clang diagnostic pop } if (! automaticallyAdjustContentInset) { @@ -1261,23 +1264,15 @@ public: UIEdgeInsets adjustedContentInsets = UIEdgeInsetsZero; UIViewController *viewController = [self rootViewController]; BOOL automaticallyAdjustContentInset; - if (@available(iOS 11.0, *)) - { - adjustedContentInsets = self.safeAreaInsets; - - } else { - adjustedContentInsets.top = viewController.topLayoutGuide.length; - CGFloat bottomPoint = CGRectGetMaxY(viewController.view.bounds) - - (CGRectGetMaxY(viewController.view.bounds) - - viewController.bottomLayoutGuide.length); - adjustedContentInsets.bottom = bottomPoint; - - } + adjustedContentInsets = self.safeAreaInsets; if (_automaticallyAdjustContentInsetHolder) { automaticallyAdjustContentInset = _automaticallyAdjustContentInsetHolder.boolValue; } else { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" automaticallyAdjustContentInset = viewController.automaticallyAdjustsScrollViewInsets; +#pragma clang diagnostic pop } self.safeMapViewContentInsets = adjustedContentInsets; @@ -3216,9 +3211,12 @@ static void *windowScreenContext = &windowScreenContext; UIViewController *viewController = self.mgl_viewControllerForLayoutGuides; if (viewController) { +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wdeprecated-declarations" CGFloat topInset = viewController.topLayoutGuide.length; frame.origin.y += topInset; frame.size.height -= topInset + viewController.bottomLayoutGuide.length; +#pragma clang diagnostic pop } return frame; } @@ -6514,7 +6512,7 @@ static void *windowScreenContext = &windowScreenContext; MGLLogDebug(@"Querying visibleFeaturesAtPoint: %@ inStyleLayersWithIdentifiers: %@ predicate: %@", NSStringFromCGPoint(point), styleLayerIdentifiers, predicate); mbgl::ScreenCoordinate screenCoordinate = { point.x, point.y }; - mbgl::optional> optionalLayerIDs; + std::optional> optionalLayerIDs; if (styleLayerIdentifiers) { __block std::vector layerIDs; @@ -6526,7 +6524,7 @@ static void *windowScreenContext = &windowScreenContext; optionalLayerIDs = layerIDs; } - mbgl::optional optionalFilter; + std::optional optionalFilter; if (predicate) { optionalFilter = predicate.mgl_filter; } @@ -6552,7 +6550,7 @@ static void *windowScreenContext = &windowScreenContext; { CGRectGetMaxX(rect), CGRectGetMaxY(rect) }, }; - mbgl::optional> optionalLayerIDs; + std::optional> optionalLayerIDs; if (styleLayerIdentifiers) { __block std::vector layerIDs; layerIDs.reserve(styleLayerIdentifiers.count); @@ -6562,7 +6560,7 @@ static void *windowScreenContext = &windowScreenContext; optionalLayerIDs = layerIDs; } - mbgl::optional optionalFilter; + std::optional optionalFilter; if (predicate) { optionalFilter = predicate.mgl_filter; } diff --git a/platform/ios/platform/ios/src/UIImage+MGLAdditions.mm b/platform/ios/platform/ios/src/UIImage+MGLAdditions.mm index 4d0ffa546..1652e1a96 100644 --- a/platform/ios/platform/ios/src/UIImage+MGLAdditions.mm +++ b/platform/ios/platform/ios/src/UIImage+MGLAdditions.mm @@ -73,7 +73,7 @@ BOOL MGLEdgeInsetsIsZero(UIEdgeInsets edgeInsets) { }); } - mbgl::optional imageContent; + std::optional imageContent; if (!MGLEdgeInsetsIsZero(self.capInsets)) { imageContent = (mbgl::style::ImageContent){ diff --git a/platform/ios/platform/ios/src/UIView+MGLAdditions.m b/platform/ios/platform/ios/src/UIView+MGLAdditions.m index 802ceb070..92d8176ff 100644 --- a/platform/ios/platform/ios/src/UIView+MGLAdditions.m +++ b/platform/ios/platform/ios/src/UIView+MGLAdditions.m @@ -21,49 +21,19 @@ } - (NSLayoutYAxisAnchor *)mgl_safeTopAnchor { - if (@available(iOS 11.0, *)) { - return self.safeAreaLayoutGuide.topAnchor; - } else { - UIViewController *viewController = self.mgl_viewControllerForLayoutGuides; - BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets; - if (useLayoutGuides) { - return viewController.topLayoutGuide.bottomAnchor; - } - else { - return self.topAnchor; - } - } + return self.safeAreaLayoutGuide.topAnchor; } - (NSLayoutXAxisAnchor *)mgl_safeLeadingAnchor { - if (@available(iOS 11.0, *)) { - return self.safeAreaLayoutGuide.leadingAnchor; - } else { - return self.leadingAnchor; - } + return self.safeAreaLayoutGuide.leadingAnchor; } - (NSLayoutYAxisAnchor *)mgl_safeBottomAnchor { - if (@available(iOS 11.0, *)) { - return self.safeAreaLayoutGuide.bottomAnchor; - } else { - UIViewController *viewController = self.mgl_viewControllerForLayoutGuides; - BOOL useLayoutGuides = viewController.view && viewController.automaticallyAdjustsScrollViewInsets; - if (useLayoutGuides) { - return viewController.bottomLayoutGuide.topAnchor; - } - else { - return self.bottomAnchor; - } - } + return self.safeAreaLayoutGuide.bottomAnchor; } - (NSLayoutXAxisAnchor *)mgl_safeTrailingAnchor { - if (@available(iOS 11.0, *)) { - return self.safeAreaLayoutGuide.trailingAnchor; - } else { - return self.trailingAnchor; - } + return self.safeAreaLayoutGuide.trailingAnchor; } - (CGRect)mgl_frameForIdentifyTransform { diff --git a/platform/ios/platform/macos/app/MapDocument.m b/platform/ios/platform/macos/app/MapDocument.m index 515e1c49d..aea07f0fe 100644 --- a/platform/ios/platform/macos/app/MapDocument.m +++ b/platform/ios/platform/macos/app/MapDocument.m @@ -192,7 +192,7 @@ NSArray> *MBXFlattenedShapes(NSArray> *sha __weak __typeof__(self) weakSelf = self; [panel beginSheetModalForWindow:self.window completionHandler:^(NSModalResponse result) { - if (result != NSFileHandlingPanelOKButton) { + if (result != NSModalResponseOK) { return; } @@ -270,7 +270,7 @@ NSArray> *MBXFlattenedShapes(NSArray> *sha panel.allowedFileTypes = [@[(NSString *)kUTTypePNG] arrayByAddingObjectsFromArray:[NSBitmapImageRep imageUnfilteredTypes]]; [panel beginSheetModalForWindow:strongSelf.window completionHandler:^(NSInteger result) { - if (result == NSFileHandlingPanelOKButton) { + if (result == NSModalResponseOK) { // Write the contents in the new format. NSURL *fileURL = panel.URL; @@ -1312,7 +1312,7 @@ NSArray> *MBXFlattenedShapes(NSArray> *sha SEL action = toolbarItem.action; if (action == @selector(showShareMenu:)) { - [(NSButton *)toolbarItem.view sendActionOn:NSLeftMouseDownMask]; + [(NSButton *)toolbarItem.view sendActionOn:NSEventMaskLeftMouseDown]; if (![MGLSettings apiKey]) { return NO; } diff --git a/platform/ios/platform/macos/macos.xcodeproj/project.pbxproj b/platform/ios/platform/macos/macos.xcodeproj/project.pbxproj index ddc2edba4..b4e838523 100644 --- a/platform/ios/platform/macos/macos.xcodeproj/project.pbxproj +++ b/platform/ios/platform/macos/macos.xcodeproj/project.pbxproj @@ -2128,6 +2128,7 @@ DEVELOPMENT_TEAM = ""; INFOPLIST_FILE = app/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_CFLAGS = "-fvisibility=hidden"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; PRODUCT_NAME = "Mapbox GL"; @@ -2150,6 +2151,7 @@ "EXCLUDED_ARCHS[sdk=*]" = arm64; INFOPLIST_FILE = app/Info.plist; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks"; + MACOSX_DEPLOYMENT_TARGET = 10.13; OTHER_CFLAGS = "-fvisibility=hidden"; PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.MapboxGL; PRODUCT_NAME = "Mapbox GL"; @@ -2196,7 +2198,11 @@ INFOPLIST_FILE = sdk/Info.plist; INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; - OTHER_CFLAGS = "-fvisibility=hidden"; + MACOSX_DEPLOYMENT_TARGET = 10.13; + OTHER_CFLAGS = ( + "-fvisibility=hidden", + "-Wno-ambiguous-macro", + ); PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.Mapbox; PRODUCT_NAME = Mapbox; SKIP_INSTALL = YES; @@ -2220,8 +2226,12 @@ INSTALL_PATH = "$(LOCAL_LIBRARY_DIR)/Frameworks"; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/../Frameworks @loader_path/Frameworks"; LLVM_LTO = YES; + MACOSX_DEPLOYMENT_TARGET = 10.13; ONLY_ACTIVE_ARCH = NO; - OTHER_CFLAGS = "-fvisibility=hidden"; + OTHER_CFLAGS = ( + "-fvisibility=hidden", + "-Wno-ambiguous-macro", + ); PRODUCT_BUNDLE_IDENTIFIER = com.mapbox.Mapbox; PRODUCT_NAME = Mapbox; SKIP_INSTALL = YES; diff --git a/platform/ios/platform/macos/src/MGLCompassCell.m b/platform/ios/platform/macos/src/MGLCompassCell.m index b3a4ad454..44c2fec44 100644 --- a/platform/ios/platform/macos/src/MGLCompassCell.m +++ b/platform/ios/platform/macos/src/MGLCompassCell.m @@ -4,7 +4,10 @@ - (instancetype)init { if (self = [super init]) { +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" self.sliderType = NSCircularSlider; +#pragma GCC diagnostic pop // A tick mark for each cardinal direction. self.numberOfTickMarks = 4; // This slider goes backwards! diff --git a/platform/ios/platform/macos/src/MGLMapView.mm b/platform/ios/platform/macos/src/MGLMapView.mm index bcf692b89..776638b76 100644 --- a/platform/ios/platform/macos/src/MGLMapView.mm +++ b/platform/ios/platform/macos/src/MGLMapView.mm @@ -372,7 +372,7 @@ public: [(NSSegmentedCell *)_zoomControls.cell setToolTip:NSLocalizedStringWithDefaultValue(@"ZOOM_IN_TOOLTIP", nil, nil, @"Zoom In", @"Tooltip of Zoom In button") forSegment:1]; _zoomControls.target = self; _zoomControls.action = @selector(zoomInOrOut:); - _zoomControls.controlSize = NSRegularControlSize; + _zoomControls.controlSize = NSControlSizeRegular; [_zoomControls sizeToFit]; _zoomControls.translatesAutoresizingMaskIntoConstraints = NO; [self addSubview:_zoomControls]; @@ -480,7 +480,7 @@ public: // Make the whole string mini by default. // Force links to be black, because the default blue is distracting. - CGFloat miniSize = [NSFont systemFontSizeForControlSize:NSMiniControlSize]; + CGFloat miniSize = [NSFont systemFontSizeForControlSize:NSControlSizeMini]; NSArray *attributionInfos = [self.style attributionInfosWithFontSize:miniSize linkColor:[NSColor blackColor]]; for (MGLAttributionInfo *info in attributionInfos) { // Feedback links are added to the Help menu. @@ -491,7 +491,7 @@ public: // For each attribution, add a borderless button that responds to clicks // and feels like a hyperlink. NSButton *button = [[MGLAttributionButton alloc] initWithAttributionInfo:info]; - button.controlSize = NSMiniControlSize; + button.controlSize = NSControlSizeMini; button.translatesAutoresizingMaskIntoConstraints = NO; // Set the new button flush with the buttom of the container and to the @@ -1449,7 +1449,7 @@ public: } NSEdgeInsets contentInsets = self.contentInsets; - if ((self.window.styleMask & NSFullSizeContentViewWindowMask) + if ((self.window.styleMask & NSWindowStyleMaskFullSizeContentView) && !self.window.titlebarAppearsTransparent) { NSRect contentLayoutRect = [self convertRect:self.window.contentLayoutRect fromView:nil]; if (NSMaxX(contentLayoutRect) > 0 && NSMaxY(contentLayoutRect) > 0) { @@ -1528,8 +1528,7 @@ public: CGDisplayShowCursor(kCGDirectMainDisplay); } } - - if (flags & NSShiftKeyMask) { + if (flags & NSEventModifierFlagShift) { // Shift-drag to zoom. if (!self.zoomEnabled) { return; @@ -1543,7 +1542,7 @@ public: CGFloat newZoomLevel = _zoomAtBeginningOfGesture - delta.y / 75; [self setZoomLevel:newZoomLevel atPoint:startPoint animated:NO]; } - } else if (flags & NSAlternateKeyMask) { + } else if (flags & NSEventModifierFlagOption) { // Option-drag to rotate and/or tilt. _mbglMap->cancelTransitions(); @@ -1586,10 +1585,10 @@ public: /// Returns whether the user is panning using a gesture. - (BOOL)isPanningWithGesture { - NSGestureRecognizerState state = _panGestureRecognizer.state; - NSEventModifierFlags flags = [NSApp currentEvent].modifierFlags; - return ((state == NSGestureRecognizerStateBegan || state == NSGestureRecognizerStateChanged) - && !(flags & NSShiftKeyMask || flags & NSAlternateKeyMask)); + NSGestureRecognizerState state = _panGestureRecognizer.state; + NSEventModifierFlags flags = [NSApp currentEvent].modifierFlags; + return ((state == NSGestureRecognizerStateBegan || state == NSGestureRecognizerStateChanged) + && !(flags & NSEventModifierFlagShift || flags & NSEventModifierFlagOption)); } /// Pinch to zoom. @@ -2845,7 +2844,7 @@ public: // Cocoa origin is at the lower-left corner. mbgl::ScreenCoordinate screenCoordinate = { point.x, NSHeight(self.bounds) - point.y }; - mbgl::optional> optionalLayerIDs; + std::optional> optionalLayerIDs; if (styleLayerIdentifiers) { __block std::vector layerIDs; layerIDs.reserve(styleLayerIdentifiers.count); @@ -2855,7 +2854,7 @@ public: optionalLayerIDs = layerIDs; } - mbgl::optional optionalFilter; + std::optional optionalFilter; if (predicate) { optionalFilter = predicate.mgl_filter; } @@ -2882,7 +2881,7 @@ public: { NSMaxX(rect), NSHeight(self.bounds) - NSMinY(rect) }, }; - mbgl::optional> optionalLayerIDs; + std::optional> optionalLayerIDs; if (styleLayerIdentifiers) { __block std::vector layerIDs; layerIDs.reserve(styleLayerIdentifiers.count); @@ -2892,7 +2891,7 @@ public: optionalLayerIDs = layerIDs; } - mbgl::optional optionalFilter; + std::optional optionalFilter; if (predicate) { optionalFilter = predicate.mgl_filter; } diff --git a/platform/ios/platform/macos/src/NSImage+MGLAdditions.mm b/platform/ios/platform/macos/src/NSImage+MGLAdditions.mm index 178cd17c7..aed7a10e2 100644 --- a/platform/ios/platform/macos/src/NSImage+MGLAdditions.mm +++ b/platform/ios/platform/macos/src/NSImage+MGLAdditions.mm @@ -63,7 +63,7 @@ BOOL MGLEdgeInsetsIsZero(NSEdgeInsets edgeInsets) { }); } - mbgl::optional imageContent; + std::optional imageContent; if (!MGLEdgeInsetsIsZero(self.capInsets)) { imageContent = (mbgl::style::ImageContent){ .left = static_cast(self.capInsets.left * scale), diff --git a/platform/ios/scripts/generate-file-lists.js b/platform/ios/scripts/generate-file-lists.js index 2e9d0ee4b..710fb000b 100755 --- a/platform/ios/scripts/generate-file-lists.js +++ b/platform/ios/scripts/generate-file-lists.js @@ -147,7 +147,7 @@ generateFileList('vendor/mapbox-base-files.json', 'vendor/mapbox-base/mapbox/weak', 'vendor/mapbox-base/mapbox/typewrapper', 'vendor/mapbox-base/mapbox/value'], - vendorRegex, [ "include/*.hpp", "include/**/*.hpp", "include/**/*.h", "optional.hpp", ":!:include/jni/string_conversion.hpp" ]); + vendorRegex, [ "include/*.hpp", "include/**/*.hpp", "include/**/*.h", ":!:include/jni/string_conversion.hpp" ]); generateFileList('vendor/polylabel-files.json', [ 'vendor/polylabel' ], vendorRegex, [ "include/**/*.hpp" ]); generateFileList('vendor/protozero-files.json', [ 'vendor/protozero' ], vendorRegex, [ "include/**/*.hpp" ]); generateFileList('vendor/shelf-pack-cpp-files.json', [ 'vendor/shelf-pack-cpp' ], vendorRegex, [ "include/**/*.hpp" ]); diff --git a/platform/linux/src/headless_backend_egl.cpp b/platform/linux/src/headless_backend_egl.cpp index 2a3add53c..580fc2cd9 100644 --- a/platform/linux/src/headless_backend_egl.cpp +++ b/platform/linux/src/headless_backend_egl.cpp @@ -6,6 +6,7 @@ #include #include +#include namespace mbgl { namespace gl { @@ -30,8 +31,8 @@ public: } if (!eglBindAPI(EGL_OPENGL_ES_API)) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglBindAPI(EGL_OPENGL_ES_API) returned error %d", - eglGetError()); + mbgl::Log::Error(mbgl::Event::OpenGL, "eglBindAPI(EGL_OPENGL_ES_API) returned error " + + std::to_string(eglGetError())); throw std::runtime_error("eglBindAPI() failed"); } @@ -82,8 +83,10 @@ public: eglContext = eglCreateContext(eglDisplay->display, eglDisplay->config, EGL_NO_CONTEXT, attribs); if (eglContext == EGL_NO_CONTEXT) { - mbgl::Log::Error(mbgl::Event::OpenGL, "eglCreateContext() returned error 0x%04x", - eglGetError()); + std::ostringstream logMsg; + logMsg << "eglCreateContext() returned error 0x" << std::hex << eglGetError(); + mbgl::Log::Error(mbgl::Event::OpenGL, logMsg.str()); + throw std::runtime_error("Error creating the EGL context object.\n"); } diff --git a/platform/node/src/node_conversion.hpp b/platform/node/src/node_conversion.hpp index b49778278..64da82d20 100644 --- a/platform/node/src/node_conversion.hpp +++ b/platform/node/src/node_conversion.hpp @@ -6,7 +6,6 @@ #include #pragma GCC diagnostic pop -#include #include #include #include @@ -47,7 +46,7 @@ public: return value->IsObject() && !value->IsArray(); } - static optional> objectMember(const v8::Local& value, const char * name) { + static std::optional> objectMember(const v8::Local& value, const char * name) { Nan::EscapableHandleScope scope; if (!Nan::Has(Nan::To(value).ToLocalChecked(), Nan::New(name).ToLocalChecked()).FromJust()) { return {}; @@ -60,13 +59,13 @@ public: } template - static optional eachMember(const v8::Local& value, Fn&& fn) { + static std::optional eachMember(const v8::Local& value, Fn&& fn) { Nan::HandleScope scope; v8::Local names = Nan::GetOwnPropertyNames(Nan::To(value).ToLocalChecked()).ToLocalChecked(); for (uint32_t i = 0; i < names->Length(); ++i) { v8::Local k = Nan::Get(names, i).ToLocalChecked(); v8::Local v = Nan::Get(Nan::To(value).ToLocalChecked(), k).ToLocalChecked(); - optional result = fn(*Nan::Utf8String(k), std::move(v)); // NOLINT(performance-move-const-arg) + std::optional result = fn(*Nan::Utf8String(k), std::move(v)); // NOLINT(performance-move-const-arg) if (result) { return result; } @@ -74,7 +73,7 @@ public: return {}; } - static optional toBool(const v8::Local& value) { + static std::optional toBool(const v8::Local& value) { Nan::HandleScope scope; if (!value->IsBoolean()) { return {}; @@ -82,7 +81,7 @@ public: return Nan::To(value).ToChecked(); } - static optional toNumber(const v8::Local& value) { + static std::optional toNumber(const v8::Local& value) { Nan::HandleScope scope; if (!value->IsNumber()) { return {}; @@ -90,7 +89,7 @@ public: return static_cast(Nan::To(value).ToChecked()); } - static optional toDouble(const v8::Local& value) { + static std::optional toDouble(const v8::Local& value) { Nan::HandleScope scope; if (!value->IsNumber()) { return {}; @@ -98,7 +97,7 @@ public: return Nan::To(value).ToChecked(); } - static optional toString(const v8::Local& value) { + static std::optional toString(const v8::Local& value) { Nan::HandleScope scope; if (!value->IsString()) { return {}; @@ -106,7 +105,7 @@ public: return std::string(*Nan::Utf8String(value)); } - static optional toValue(const v8::Local& value) { + static std::optional toValue(const v8::Local& value) { if (value->IsFalse()) { return { false }; } else if (value->IsTrue()) { @@ -124,7 +123,7 @@ public: } } - static optional toGeoJSON(const v8::Local& value, Error& error) { + static std::optional toGeoJSON(const v8::Local& value, Error& error) { try { Nan::JSON NanJSON; v8::Local obj = Nan::To(value).ToLocalChecked(); @@ -139,7 +138,7 @@ public: }; template -optional convert(const v8::Local& value, Error& error, Args&&...args) { +std::optional convert(const v8::Local& value, Error& error, Args&&...args) { return convert(Convertible(value), error, std::forward(args)...); } diff --git a/platform/node/src/node_expression.cpp b/platform/node/src/node_expression.cpp index 5480ef279..7da4f12c3 100644 --- a/platform/node/src/node_expression.cpp +++ b/platform/node/src/node_expression.cpp @@ -60,7 +60,7 @@ type::Type parseType(v8::Local type) { v8::Local context = type->GetCreationContext().ToLocalChecked(); #endif type::Type itemType = parseType(Nan::Get(type, Nan::New("itemType").ToLocalChecked()).ToLocalChecked()->ToObject(context).ToLocalChecked()); - mbgl::optional N; + std::optional N; v8::Local Nkey = Nan::New("N").ToLocalChecked(); if (Nan::Has(type, Nkey).FromMaybe(false)) { @@ -80,7 +80,7 @@ void NodeExpression::Parse(const Nan::FunctionCallbackInfo& info) { return Nan::ThrowTypeError("Requires a JSON style expression argument."); } - mbgl::optional expected; + std::optional expected; if (info.Length() > 1 && info[1]->IsObject()) { expected = parseType(info[1]->ToObject(context).ToLocalChecked()); } @@ -247,17 +247,17 @@ void NodeExpression::Evaluate(const Nan::FunctionCallbackInfo& info) return Nan::ThrowTypeError("Requires globals and feature arguments."); } - mbgl::optional zoom; + std::optional zoom; v8::Local v8zoom = Nan::Get(info[0]->ToObject(context).ToLocalChecked(), Nan::New("zoom").ToLocalChecked()).ToLocalChecked(); if (v8zoom->IsNumber()) zoom = static_cast(Nan::To(v8zoom).FromJust()); - mbgl::optional heatmapDensity; + std::optional heatmapDensity; v8::Local v8heatmapDensity = Nan::Get(info[0]->ToObject(context).ToLocalChecked(), Nan::New("heatmapDensity").ToLocalChecked()).ToLocalChecked(); if (v8heatmapDensity->IsNumber()) heatmapDensity = Nan::To(v8heatmapDensity).FromJust(); Nan::JSON NanJSON; conversion::Error conversionError; - mbgl::optional geoJSON = conversion::convert(info[1], conversionError); + std::optional geoJSON = conversion::convert(info[1], conversionError); if (!geoJSON) { Nan::ThrowTypeError(conversionError.message.c_str()); return; diff --git a/platform/node/src/node_map.cpp b/platform/node/src/node_map.cpp index bb5561333..28a5a7f24 100644 --- a/platform/node/src/node_map.cpp +++ b/platform/node/src/node_map.cpp @@ -708,7 +708,7 @@ void NodeMap::AddSource(const Nan::FunctionCallbackInfo& info) { } Error error; - mbgl::optional> source = convert>(info[1], error, *Nan::Utf8String(info[0])); + std::optional> source = convert>(info[1], error, *Nan::Utf8String(info[0])); if (!source) { Nan::ThrowTypeError(error.message.c_str()); return; @@ -747,7 +747,7 @@ void NodeMap::AddLayer(const Nan::FunctionCallbackInfo& info) { } Error error; - mbgl::optional> layer = convert>(info[0], error); + std::optional> layer = convert>(info[0], error); if (!layer) { Nan::ThrowTypeError(error.message.c_str()); return; @@ -912,7 +912,7 @@ void NodeMap::SetLayerProperty(const Nan::FunctionCallbackInfo& info) return Nan::ThrowTypeError("Second argument must be a string"); } - mbgl::optional error = layer->setProperty(*Nan::Utf8String(info[1]), Convertible(info[2])); + std::optional error = layer->setProperty(*Nan::Utf8String(info[1]), Convertible(info[2])); if (error) { return Nan::ThrowTypeError(error->message.c_str()); } @@ -944,7 +944,7 @@ void NodeMap::SetFilter(const Nan::FunctionCallbackInfo& info) { if (!info[1]->IsNull() && !info[1]->IsUndefined()) { Error error; - mbgl::optional converted = convert(info[1], error); + std::optional converted = convert(info[1], error); if (!converted) { Nan::ThrowTypeError(error.message.c_str()); return; @@ -1149,7 +1149,7 @@ void NodeMap::SetFeatureState(const Nan::FunctionCallbackInfo& info) std::string sourceID; std::string featureID; - mbgl::optional sourceLayerID; + std::optional sourceLayerID; auto feature = Nan::To(info[0]).ToLocalChecked(); if (Nan::Has(feature, Nan::New("source").ToLocalChecked()).FromJust()) { auto sourceOption = Nan::Get(feature, Nan::New("source").ToLocalChecked()).ToLocalChecked(); @@ -1191,9 +1191,9 @@ void NodeMap::SetFeatureState(const Nan::FunctionCallbackInfo& info) bool valueParsed = false; FeatureState newState; - const std::function(const std::string&, const Convertible&)> convertFn = - [&](const std::string& k, const Convertible& v) -> optional { - optional value = toValue(v); + const std::function(const std::string&, const Convertible&)> convertFn = + [&](const std::string& k, const Convertible& v) -> std::optional { + std::optional value = toValue(v); if (value) { stateValue = std::move(*value); valueParsed = true; @@ -1202,7 +1202,7 @@ void NodeMap::SetFeatureState(const Nan::FunctionCallbackInfo& info) std::size_t length = arrayLength(v); array.reserve(length); for (size_t i = 0; i < length; ++i) { - optional arrayVal = toValue(arrayMember(v, i)); + std::optional arrayVal = toValue(arrayMember(v, i)); if (arrayVal) { array.emplace_back(*arrayVal); } @@ -1218,11 +1218,11 @@ void NodeMap::SetFeatureState(const Nan::FunctionCallbackInfo& info) } if (!valueParsed) { Nan::ThrowTypeError("Could not get feature state value"); - return nullopt; + return std::nullopt; } stateKey = k; newState[stateKey] = stateValue; - return nullopt; + return std::nullopt; }; eachMember(state, convertFn); @@ -1250,7 +1250,7 @@ void NodeMap::GetFeatureState(const Nan::FunctionCallbackInfo& info) std::string sourceID; std::string featureID; - mbgl::optional sourceLayerID; + std::optional sourceLayerID; auto feature = Nan::To(info[0]).ToLocalChecked(); if (Nan::Has(feature, Nan::New("source").ToLocalChecked()).FromJust()) { auto sourceOption = Nan::Get(feature, Nan::New("source").ToLocalChecked()).ToLocalChecked(); @@ -1307,9 +1307,9 @@ void NodeMap::RemoveFeatureState(const Nan::FunctionCallbackInfo& inf } std::string sourceID; - mbgl::optional sourceLayerID; - mbgl::optional featureID; - mbgl::optional stateKey; + std::optional sourceLayerID; + std::optional featureID; + std::optional stateKey; auto feature = Nan::To(info[0]).ToLocalChecked(); if (Nan::Has(feature, Nan::New("source").ToLocalChecked()).FromJust()) { auto sourceOption = Nan::Get(feature, Nan::New("source").ToLocalChecked()).ToLocalChecked(); @@ -1406,7 +1406,7 @@ void NodeMap::QueryRenderedFeatures(const Nan::FunctionCallbackInfo& if (Nan::Has(options, Nan::New("filter").ToLocalChecked()).FromJust()) { auto filterOption = Nan::Get(options, Nan::New("filter").ToLocalChecked()).ToLocalChecked(); Error error; - mbgl::optional converted = convert(filterOption, error); + std::optional converted = convert(filterOption, error); if (!converted) { return Nan::ThrowTypeError(error.message.c_str()); } diff --git a/platform/qt/src/map.cpp b/platform/qt/src/map.cpp index 3a266856f..6d3e48600 100644 --- a/platform/qt/src/map.cpp +++ b/platform/qt/src/map.cpp @@ -136,7 +136,7 @@ mbgl::ClientOptions clientOptionsFromSettings(const QMapLibreGL::Settings &setti } -mbgl::optional asAnnotation(const QMapLibreGL::Annotation & annotation) { +std::optional asAnnotation(const QMapLibreGL::Annotation & annotation) { auto asGeometry = [](const QMapLibreGL::ShapeAnnotationGeometry &geometry) { mbgl::ShapeAnnotationGeometry result; switch (geometry.type) { @@ -607,7 +607,7 @@ void Map::setGestureInProgress(bool progress) values transition to new values with animation when they are updated. */ void Map::setTransitionOptions(qint64 duration, qint64 delay) { - static auto convert = [](qint64 value) -> mbgl::optional { + static auto convert = [](qint64 value) -> std::optional { return std::chrono::duration_cast(mbgl::Milliseconds(value)); }; @@ -927,7 +927,7 @@ void Map::addSource(const QString &id, const QVariantMap ¶ms) using namespace mbgl::style::conversion; Error error; - mbgl::optional> source = convert>(QVariant(params), error, id.toStdString()); + std::optional> source = convert>(QVariant(params), error, id.toStdString()); if (!source) { qWarning() << "Unable to add source:" << error.message.c_str(); return; @@ -1039,7 +1039,7 @@ void Map::addCustomLayer(const QString &id, d_ptr->mapObj->getStyle().addLayer(std::make_unique( id.toStdString(), std::make_unique(std::move(host))), - before.isEmpty() ? mbgl::optional() : mbgl::optional(before.toStdString())); + before.isEmpty() ? std::optional() : std::optional(before.toStdString())); } /*! @@ -1068,14 +1068,14 @@ void Map::addLayer(const QVariantMap ¶ms, const QString& before) using namespace mbgl::style::conversion; Error error; - mbgl::optional> layer = convert>(QVariant(params), error); + std::optional> layer = convert>(QVariant(params), error); if (!layer) { qWarning() << "Unable to add layer:" << error.message.c_str(); return; } d_ptr->mapObj->getStyle().addLayer(std::move(*layer), - before.isEmpty() ? mbgl::optional() : mbgl::optional(before.toStdString())); + before.isEmpty() ? std::optional() : std::optional(before.toStdString())); } /*! @@ -1168,7 +1168,7 @@ void Map::setFilter(const QString& layer, const QVariant& filter) } Error error; - mbgl::optional converted = convert(filter, error); + std::optional converted = convert(filter, error); if (!converted) { qWarning() << "Error parsing filter:" << error.message.c_str(); return; @@ -1521,7 +1521,7 @@ bool MapPrivate::setProperty(const PropertySetter& setter, const QString& layer, const std::string& propertyString = name.toStdString(); - mbgl::optional result; + std::optional result; #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (value.typeId() == QMetaType::QString) { diff --git a/platform/qt/src/map_p.hpp b/platform/qt/src/map_p.hpp index af5e0d485..b93492d4a 100644 --- a/platform/qt/src/map_p.hpp +++ b/platform/qt/src/map_p.hpp @@ -38,7 +38,7 @@ public: void render(); void setFramebufferObject(quint32 fbo, const QSize& size); - using PropertySetter = mbgl::optional (mbgl::style::Layer::*)(const std::string&, const mbgl::style::conversion::Convertible&); + using PropertySetter = std::optional (mbgl::style::Layer::*)(const std::string&, const mbgl::style::conversion::Convertible&); bool setProperty(const PropertySetter& setter, const QString& layer, const QString& name, const QVariant& value); mbgl::EdgeInsets margins; diff --git a/platform/qt/src/mbgl/http_request.cpp b/platform/qt/src/mbgl/http_request.cpp index a9a8b1158..ed33403a8 100644 --- a/platform/qt/src/mbgl/http_request.cpp +++ b/platform/qt/src/mbgl/http_request.cpp @@ -3,7 +3,6 @@ #include #include -#include #include #include #include @@ -83,8 +82,8 @@ void HTTPRequest::handleNetworkReply(QNetworkReply *reply, const QByteArray& dat } QPair line; - optional retryAfter; - optional xRateLimitReset; + std::optional retryAfter; + std::optional xRateLimitReset; foreach(line, reply->rawHeaderPairs()) { QString header = QString(line.first).toLower(); diff --git a/platform/qt/src/mbgl/local_glyph_rasterizer.cpp b/platform/qt/src/mbgl/local_glyph_rasterizer.cpp index b1fe3845d..8cadb54b0 100644 --- a/platform/qt/src/mbgl/local_glyph_rasterizer.cpp +++ b/platform/qt/src/mbgl/local_glyph_rasterizer.cpp @@ -12,16 +12,16 @@ namespace mbgl { class LocalGlyphRasterizer::Impl { public: - Impl(const optional& fontFamily_); + Impl(const std::optional& fontFamily_); bool isConfigured() const; - optional fontFamily; + std::optional fontFamily; QFont font; - optional metrics; + std::optional metrics; }; -LocalGlyphRasterizer::Impl::Impl(const optional& fontFamily_) : fontFamily(fontFamily_) { +LocalGlyphRasterizer::Impl::Impl(const std::optional& fontFamily_) : fontFamily(fontFamily_) { if (isConfigured()) { font.setFamily(QString::fromStdString(*fontFamily)); font.setPixelSize(util::ONE_EM); @@ -33,7 +33,7 @@ bool LocalGlyphRasterizer::Impl::isConfigured() const { return fontFamily.operator bool(); } -LocalGlyphRasterizer::LocalGlyphRasterizer(const optional& fontFamily) +LocalGlyphRasterizer::LocalGlyphRasterizer(const std::optional& fontFamily) : impl(std::make_unique(fontFamily)) {} LocalGlyphRasterizer::~LocalGlyphRasterizer() { diff --git a/platform/qt/src/mbgl/sqlite3.cpp b/platform/qt/src/mbgl/sqlite3.cpp index f5194f7b2..b3f5abdb3 100644 --- a/platform/qt/src/mbgl/sqlite3.cpp +++ b/platform/qt/src/mbgl/sqlite3.cpp @@ -13,10 +13,10 @@ #include #include #include +#include #include #include -#include #include #include @@ -80,9 +80,6 @@ public: int64_t changes = 0; }; -template -using optional = std::experimental::optional; - mapbox::util::variant Database::tryOpen(const std::string &filename, int flags) { if (!QSqlDatabase::drivers().contains("QSQLITE")) { return Exception { ResultCode::CantOpen, "SQLite driver not found." }; @@ -274,7 +271,7 @@ void Query::bind(int offset, mbgl::Timestamp value) { } template <> -void Query::bind(int offset, optional value) { +void Query::bind(int offset, std::optional value) { if (value) { bind(offset, *value); } else { @@ -283,7 +280,7 @@ void Query::bind(int offset, optional value) { } template <> -void Query::bind(int offset, optional value) { +void Query::bind(int offset, std::optional value) { if (value) { bind(offset, *value); } else { @@ -373,7 +370,7 @@ template <> mbgl::Timestamp Query::get(int offset) { std::chrono::system_clock::from_time_t(value.value<::time_t>())); } -template <> optional Query::get(int offset) { +template <> std::optional Query::get(int offset) { assert(stmt.impl && stmt.impl->query.isValid()); QVariant value = stmt.impl->query.value(offset); checkQueryError(stmt.impl->query); @@ -382,7 +379,7 @@ template <> optional Query::get(int offset) { return { value.value() }; } -template <> optional Query::get(int offset) { +template <> std::optional Query::get(int offset) { assert(stmt.impl && stmt.impl->query.isValid()); QVariant value = stmt.impl->query.value(offset); checkQueryError(stmt.impl->query); @@ -398,7 +395,7 @@ template <> std::string Query::get(int offset) { return std::string(value.constData(), value.size()); } -template <> optional Query::get(int offset) { +template <> std::optional Query::get(int offset) { assert(stmt.impl && stmt.impl->query.isValid()); QByteArray value = stmt.impl->query.value(offset).toByteArray(); checkQueryError(stmt.impl->query); @@ -407,7 +404,7 @@ template <> optional Query::get(int offset) { return { std::string(value.constData(), value.size()) }; } -template <> optional Query::get(int offset) { +template <> std::optional Query::get(int offset) { assert(stmt.impl && stmt.impl->query.isValid()); QVariant value = stmt.impl->query.value(offset); checkQueryError(stmt.impl->query); diff --git a/platform/qt/src/utils/conversion.hpp b/platform/qt/src/utils/conversion.hpp index c4343ab40..678588e6e 100644 --- a/platform/qt/src/utils/conversion.hpp +++ b/platform/qt/src/utils/conversion.hpp @@ -6,11 +6,12 @@ #include #include -#include #include #include +#include + namespace mbgl { namespace style { namespace conversion { @@ -54,7 +55,7 @@ public: || value.userType() == qMetaTypeId>(); } - static optional objectMember(const QVariant& value, const char* key) { + static std::optional objectMember(const QVariant& value, const char* key) { auto map = value.toMap(); auto iter = map.constFind(key); @@ -66,12 +67,12 @@ public: } template - static optional eachMember(const QVariant& value, Fn&& fn) { + static std::optional eachMember(const QVariant& value, Fn&& fn) { auto map = value.toMap(); auto iter = map.constBegin(); while (iter != map.constEnd()) { - optional result = fn(iter.key().toStdString(), QVariant(iter.value())); + std::optional result = fn(iter.key().toStdString(), QVariant(iter.value())); if (result) { return result; } @@ -82,7 +83,7 @@ public: return {}; } - static optional toBool(const QVariant& value) { + static std::optional toBool(const QVariant& value) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (value.typeId() == QMetaType::Bool) { #else @@ -94,7 +95,7 @@ public: } } - static optional toNumber(const QVariant& value) { + static std::optional toNumber(const QVariant& value) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) { #else @@ -106,7 +107,7 @@ public: } } - static optional toDouble(const QVariant& value) { + static std::optional toDouble(const QVariant& value) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (value.typeId() == QMetaType::Int || value.typeId() == QMetaType::Double) { #else @@ -118,7 +119,7 @@ public: } } - static optional toString(const QVariant& value) { + static std::optional toString(const QVariant& value) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (value.typeId() == QMetaType::QString) { return value.toString().toStdString(); @@ -138,7 +139,7 @@ public: #endif } - static optional toValue(const QVariant& value) { + static std::optional toValue(const QVariant& value) { #if QT_VERSION >= QT_VERSION_CHECK(6, 0, 0) if (value.typeId() == QMetaType::Bool) { return { value.toBool() }; @@ -170,7 +171,7 @@ public: #endif } - static optional toGeoJSON(const QVariant& value, Error& error) { + static std::optional toGeoJSON(const QVariant& value, Error& error) { if (value.typeName() == QStringLiteral("QMapLibreGL::Feature")) { return GeoJSON { QMapLibreGL::GeoJSON::asFeature(value.value()) }; } else if (value.userType() == qMetaTypeId>()) { @@ -205,7 +206,7 @@ private: }; template -optional convert(const QVariant& value, Error& error, Args&&...args) { +std::optional convert(const QVariant& value, Error& error, Args&&...args) { return convert(Convertible(value), error, std::forward(args)...); } diff --git a/platform/qt/src/utils/map_renderer.cpp b/platform/qt/src/utils/map_renderer.cpp index b2798d443..b0fced736 100644 --- a/platform/qt/src/utils/map_renderer.cpp +++ b/platform/qt/src/utils/map_renderer.cpp @@ -35,7 +35,7 @@ namespace QMapLibreGL { MapRenderer::MapRenderer(qreal pixelRatio, Settings::GLContextMode mode, const QString &localFontFamily) : m_backend(static_cast(mode)), m_renderer(std::make_unique(m_backend, pixelRatio, - localFontFamily.isEmpty() ? mbgl::nullopt : mbgl::optional { localFontFamily.toStdString() })) + localFontFamily.isEmpty() ? std::nullopt : std::optional { localFontFamily.toStdString() })) , m_forceScheduler(needsToForceScheduler()) { // If we don't have a Scheduler on this thread, which diff --git a/render-test/file_source.cpp b/render-test/file_source.cpp index 98b2fa2d6..51810dc27 100644 --- a/render-test/file_source.cpp +++ b/render-test/file_source.cpp @@ -60,11 +60,11 @@ std::unique_ptr ProxyFileSource::request(const Resource& resource, if (transformed.loadingMethod == Resource::LoadingMethod::CacheOnly && response.noContent) { if (transformed.kind == Resource::Kind::Tile && transformed.tileData) { mbgl::Log::Info(mbgl::Event::Database, - "Resource not found in cache: %s (%s)", - transformed.url.c_str(), - transformed.tileData->urlTemplate.c_str()); + "Resource not found in cache: " + + transformed.url + "(" + + transformed.tileData->urlTemplate + ")"); } else { - mbgl::Log::Info(mbgl::Event::Database, "Resource not found in cache: %s", transformed.url.c_str()); + mbgl::Log::Info(mbgl::Event::Database, "Resource not found in cache: " + transformed.url); } } diff --git a/render-test/manifest_parser.cpp b/render-test/manifest_parser.cpp index 1fc58196c..b2e53c1d8 100644 --- a/render-test/manifest_parser.cpp +++ b/render-test/manifest_parser.cpp @@ -94,13 +94,13 @@ mbgl::filesystem::path getValidPath(const std::string& manifestPath, const std:: if (mbgl::filesystem::exists(result)) { return result.lexically_normal(); } - mbgl::Log::Warning(mbgl::Event::General, "Invalid path is provided inside the manifest file: %s", path.c_str()); + mbgl::Log::Warning(mbgl::Event::General, "Invalid path is provided inside the manifest file: " + path); return mbgl::filesystem::path{}; } } // namespace -mbgl::optional ManifestParser::parseManifest(const std::string& manifestPath, +std::optional ManifestParser::parseManifest(const std::string& manifestPath, std::string testFilter) { Manifest manifest; const auto filePath = mbgl::filesystem::path(manifestPath); @@ -108,8 +108,8 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife auto contents = readJson(filePath); if (!contents.is()) { - mbgl::Log::Error(mbgl::Event::General, "Provided manifest file: %s is not a valid json", filePath.c_str()); - return mbgl::nullopt; + mbgl::Log::Error(mbgl::Event::General, "Provided manifest file: " + std::string(filePath) + " is not a valid json"); + return std::nullopt; } auto document = std::move(contents.get()); @@ -117,24 +117,24 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& resultPathValue = document["result_path"]; if (!resultPathValue.IsString()) { mbgl::Log::Warning( - mbgl::Event::General, "Invalid result_path is provided inside the manifest file: %s", filePath.c_str()); - return mbgl::nullopt; + mbgl::Event::General, "Invalid result_path is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } manifest.resultPath = (getValidPath(manifest.manifestPath, resultPathValue.GetString()) / "").string(); if (manifest.resultPath.empty()) { - return mbgl::nullopt; + return std::nullopt; } } if (document.HasMember("cache_path")) { const auto& cachePathValue = document["cache_path"]; if (!cachePathValue.IsString()) { mbgl::Log::Warning( - mbgl::Event::General, "Invalid cache_path is provided inside the manifest file: %s", filePath.c_str()); - return mbgl::nullopt; + mbgl::Event::General, "Invalid cache_path is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } manifest.cachePath = (getValidPath(manifest.manifestPath, ".") / cachePathValue.GetString()).string(); if (manifest.cachePath.empty()) { - return mbgl::nullopt; + return std::nullopt; } } //TODO:PP @@ -142,13 +142,12 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& apiKeyValue = document["access_token"]; if (!apiKeyValue.IsString()) { mbgl::Log::Warning(mbgl::Event::General, - "Invalid access_token is provided inside the manifest file: %s", - filePath.c_str()); - return mbgl::nullopt; + "Invalid access_token is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } manifest.apiKey = apiKeyValue.GetString(); if (manifest.apiKey.empty()) { - return mbgl::nullopt; + return std::nullopt; } } mbgl::filesystem::path baseTestPath; @@ -156,13 +155,12 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& testPathValue = document["base_test_path"]; if (!testPathValue.IsString()) { mbgl::Log::Warning(mbgl::Event::General, - "Invalid base_test_path is provided inside the manifest file: %s", - filePath.c_str()); - return mbgl::nullopt; + "Invalid base_test_path is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } baseTestPath = getValidPath(manifest.manifestPath, testPathValue.GetString()); if (baseTestPath.empty()) { - return mbgl::nullopt; + return std::nullopt; } } mbgl::filesystem::path expectedMetricPath; @@ -170,12 +168,12 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& metricPathValue = document["metric_path"]; if (!metricPathValue.IsString()) { mbgl::Log::Warning( - mbgl::Event::General, "Invalid metric_path is provided inside the manifest file: %s", filePath.c_str()); - return mbgl::nullopt; + mbgl::Event::General, "Invalid metric_path is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } expectedMetricPath = getValidPath(manifest.manifestPath, metricPathValue.GetString()); if (expectedMetricPath.empty()) { - return mbgl::nullopt; + return std::nullopt; } } std::vector expectationPaths{}; @@ -183,20 +181,18 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& expectationPathValue = document["expectation_paths"]; if (!expectationPathValue.IsArray()) { mbgl::Log::Warning(mbgl::Event::General, - "Provided expectation_paths inside the manifest file: %s is not a valid array", - filePath.c_str()); - return mbgl::nullopt; + "Provided expectation_paths inside the manifest file: %s is not a valid array" + std::string(filePath)); + return std::nullopt; } for (const auto& value : expectationPathValue.GetArray()) { if (!value.IsString()) { mbgl::Log::Warning(mbgl::Event::General, - "Invalid expectation path item is provided inside the manifest file: %s", - filePath.c_str()); - return mbgl::nullopt; + "Invalid expectation path item is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } expectationPaths.emplace_back(getValidPath(manifest.manifestPath, value.GetString())); if (expectationPaths.back().empty()) { - return mbgl::nullopt; + return std::nullopt; } } } @@ -205,20 +201,18 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& ignorePathValue = document["ignore_paths"]; if (!ignorePathValue.IsArray()) { mbgl::Log::Warning(mbgl::Event::General, - "Provided ignore_paths inside the manifest file: %s is not a valid array", - filePath.c_str()); - return mbgl::nullopt; + "Provided ignore_paths inside the manifest file: " + std::string(filePath) + " is not a valid array"); + return std::nullopt; } for (const auto& value : ignorePathValue.GetArray()) { if (!value.IsString()) { mbgl::Log::Warning(mbgl::Event::General, - "Invalid ignore path item is provided inside the manifest file: %s", - filePath.c_str()); - return mbgl::nullopt; + "Invalid ignore path item is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } ignorePaths.emplace_back(getValidPath(manifest.manifestPath, value.GetString())); if (ignorePaths.back().empty()) { - return mbgl::nullopt; + return std::nullopt; } } manifest.ignores = parseIgnores(ignorePaths); @@ -228,16 +222,15 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& probesValue = document["probes"]; if (!probesValue.IsArray()) { mbgl::Log::Warning(mbgl::Event::General, - "Provided probes inside the manifest file: %s is not a valid array", - filePath.c_str()); - return mbgl::nullopt; + "Provided probes inside the manifest file: " + std::string(filePath) + "is not a valid array"); + return std::nullopt; } for (const auto& value : probesValue.GetArray()) { if (!value.IsString()) { mbgl::Log::Warning(mbgl::Event::General, - "Invalid probe type is provided inside the manifest file: %s", - filePath.c_str()); - return mbgl::nullopt; + "Invalid probe type is provided inside the manifest file: " + + std::string(filePath)); + return std::nullopt; } manifest.probes.emplace(value.GetString()); } @@ -247,8 +240,8 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife const auto& filterValue = document["filter"]; if (!filterValue.IsString()) { mbgl::Log::Warning( - mbgl::Event::General, "Invalid filter is provided inside the manifest file: %s", filePath.c_str()); - return mbgl::nullopt; + mbgl::Event::General, "Invalid filter is provided inside the manifest file: " + std::string(filePath)); + return std::nullopt; } testFilter = filterValue.GetString(); @@ -294,5 +287,5 @@ mbgl::optional ManifestParser::parseManifest(const std::string& manife } } - return mbgl::optional(manifest); + return std::optional(manifest); } diff --git a/render-test/manifest_parser.hpp b/render-test/manifest_parser.hpp index a6c537bbc..2fad5ce72 100644 --- a/render-test/manifest_parser.hpp +++ b/render-test/manifest_parser.hpp @@ -2,7 +2,6 @@ #include "metadata.hpp" -#include #include #include @@ -10,6 +9,7 @@ #include #include #include +#include class Manifest { public: @@ -39,6 +39,6 @@ private: class ManifestParser { public: - static mbgl::optional parseManifest(const std::string& manifestPath, + static std::optional parseManifest(const std::string& manifestPath, std::string testFilter); }; diff --git a/render-test/parser.cpp b/render-test/parser.cpp index 4a039cf40..e42f00b1a 100644 --- a/render-test/parser.cpp +++ b/render-test/parser.cpp @@ -459,13 +459,13 @@ TestMetadata parseTestMetadata(const TestPaths& paths) { metadata.document = std::move(maybeJson.get()); if (!metadata.document.HasMember("metadata")) { - mbgl::Log::Warning(mbgl::Event::ParseStyle, "Style has no 'metadata': %s", paths.stylePath.c_str()); + mbgl::Log::Warning(mbgl::Event::ParseStyle, "Style has no 'metadata': " + paths.stylePath.string()); return metadata; } const mbgl::JSValue& metadataValue = metadata.document["metadata"]; if (!metadataValue.HasMember("test")) { - mbgl::Log::Warning(mbgl::Event::ParseStyle, "Style has no 'metadata.test': %s", paths.stylePath.c_str()); + mbgl::Log::Warning(mbgl::Event::ParseStyle, "Style has no 'metadata.test': " + paths.stylePath.string()); return metadata; } @@ -486,7 +486,7 @@ TestMetadata parseTestMetadata(const TestPaths& paths) { metadata.mapMode = mbgl::MapMode::Static; else { mbgl::Log::Warning( - mbgl::Event::ParseStyle, "Unknown map mode: %s. Falling back to static mode", mapModeStr.c_str()); + mbgl::Event::ParseStyle, "Unknown map mode: " + mapModeStr + ". Falling back to static mode"); metadata.mapMode = mbgl::MapMode::Static; } } @@ -594,7 +594,7 @@ TestMetadata parseTestMetadata(const TestPaths& paths) { assert(testValue["queryOptions"]["filter"].IsArray()); auto& filterVal = testValue["queryOptions"]["filter"]; Error error; - mbgl::optional converted = convert(filterVal, error); + std::optional converted = convert(filterVal, error); assert(converted); metadata.queryOptions.filter = std::move(*converted); } @@ -711,7 +711,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) { std::string imagePath = operationArray[2].GetString(); result.emplace_back([imageName, imagePath, sdf, pixelRatio](TestContext& ctx) { - mbgl::optional maybeImage; + std::optional maybeImage; bool requestCompleted = false; auto req = ctx.getFileSource().request(mbgl::Resource::image("mapbox://render-tests/" + imagePath), @@ -1039,7 +1039,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) { using namespace mbgl::style::conversion; std::string sourceID; - mbgl::optional sourceLayer; + std::optional sourceLayer; std::string featureID; std::string stateKey; Value stateValue; @@ -1062,9 +1062,9 @@ TestOperations parseTestOperations(TestMetadata& metadata) { } const JSValue* state = &operationArray[2]; - const std::function(const std::string&, const Convertible&)> convertFn = - [&](const std::string& k, const Convertible& v) -> optional { - optional value = toValue(v); + const std::function(const std::string&, const Convertible&)> convertFn = + [&](const std::string& k, const Convertible& v) -> std::optional { + std::optional value = toValue(v); if (value) { stateValue = std::move(*value); valueParsed = true; @@ -1073,7 +1073,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) { std::size_t length = arrayLength(v); array.reserve(length); for (size_t i = 0; i < length; ++i) { - optional arrayVal = toValue(arrayMember(v, i)); + std::optional arrayVal = toValue(arrayMember(v, i)); if (arrayVal) { array.emplace_back(*arrayVal); } @@ -1082,7 +1082,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) { values[k] = std::move(array); stateValue = std::move(values); valueParsed = true; - return nullopt; + return std::nullopt; } else if (isObject(v)) { eachMember(v, convertFn); @@ -1090,11 +1090,11 @@ TestOperations parseTestOperations(TestMetadata& metadata) { if (!valueParsed) { metadata.errorMessage = std::string("Could not get feature state value, state key: ") + k; - return nullopt; + return std::nullopt; } stateKey = k; parsedState[stateKey] = stateValue; - return nullopt; + return std::nullopt; }; eachMember(state, convertFn); @@ -1114,7 +1114,7 @@ TestOperations parseTestOperations(TestMetadata& metadata) { assert(operationArray[1].IsObject()); std::string sourceID; - mbgl::optional sourceLayer; + std::optional sourceLayer; std::string featureID; const auto& featureOptions = operationArray[1].GetObject(); @@ -1148,9 +1148,9 @@ TestOperations parseTestOperations(TestMetadata& metadata) { assert(operationArray[1].IsObject()); std::string sourceID; - mbgl::optional sourceLayer; + std::optional sourceLayer; std::string featureID; - mbgl::optional stateKey; + std::optional stateKey; const auto& featureOptions = operationArray[1].GetObject(); if (featureOptions.HasMember("source")) { diff --git a/render-test/render_test.cpp b/render-test/render_test.cpp index aae5ae6ad..0c3473b15 100644 --- a/render-test/render_test.cpp +++ b/render-test/render_test.cpp @@ -97,8 +97,7 @@ ArgumentsTuple parseArguments(int argc, char** argv) { mbgl::filesystem::path manifestPath = args::get(testPathValue); if (!mbgl::filesystem::exists(manifestPath) || !manifestPath.has_filename()) { mbgl::Log::Error(mbgl::Event::General, - "Provided test manifest file path '%s' does not exist", - manifestPath.string().c_str()); + "Provided test manifest file path '" + manifestPath.string() + "' does not exist"); exit(3); } diff --git a/render-test/runner.cpp b/render-test/runner.cpp index 746c4446c..d07ac9711 100644 --- a/render-test/runner.cpp +++ b/render-test/runner.cpp @@ -76,7 +76,7 @@ std::string simpleDiff(const Value& result, const Value& expected) { break; } - if (!deepEqual(resultTokens[i], expectedTokens[i])) { + if (resultTokens[i] != expectedTokens[i]) { diff << "" << "-" << expectedTokens[i] << "" << std::endl; diff << "" @@ -246,7 +246,7 @@ void TestRunner::checkRenderTestResults(mbgl::PremultipliedImage&& actualImage, } for (const auto& entry : expectedImagesPaths) { - mbgl::optional maybeExpectedImage = mbgl::util::readFile(entry); + std::optional maybeExpectedImage = mbgl::util::readFile(entry); if (!maybeExpectedImage) { metadata.errorMessage = "Failed to load expected image " + entry; metadata.renderErrored++; diff --git a/src/mbgl/algorithm/update_renderables.hpp b/src/mbgl/algorithm/update_renderables.hpp index 91eb05863..7fa8fee78 100644 --- a/src/mbgl/algorithm/update_renderables.hpp +++ b/src/mbgl/algorithm/update_renderables.hpp @@ -2,10 +2,10 @@ #include #include -#include #include #include +#include namespace mbgl { namespace algorithm { @@ -21,7 +21,7 @@ void updateRenderables(GetTileFn getTile, RenderTileFn renderTile, const IdealTileIDs& idealTileIDs, const Range& zoomRange, - const optional& maxParentOverscaleFactor = nullopt) { + const std::optional& maxParentOverscaleFactor = std::nullopt) { std::unordered_set checked; bool covered; int32_t overscaledZ; diff --git a/src/mbgl/annotation/annotation_source.cpp b/src/mbgl/annotation/annotation_source.cpp index 318241a91..19a33bb02 100644 --- a/src/mbgl/annotation/annotation_source.cpp +++ b/src/mbgl/annotation/annotation_source.cpp @@ -22,7 +22,7 @@ void AnnotationSource::loadDescription(FileSource&) { loaded = true; } -optional AnnotationSource::Impl::getAttribution() const { +std::optional AnnotationSource::Impl::getAttribution() const { return {}; } diff --git a/src/mbgl/annotation/annotation_source.hpp b/src/mbgl/annotation/annotation_source.hpp index de432202a..3d1cd33ec 100644 --- a/src/mbgl/annotation/annotation_source.hpp +++ b/src/mbgl/annotation/annotation_source.hpp @@ -28,7 +28,7 @@ class AnnotationSource::Impl : public style::Source::Impl { public: Impl(); - optional getAttribution() const final; + std::optional getAttribution() const final; }; } // namespace mbgl diff --git a/src/mbgl/annotation/annotation_tile.cpp b/src/mbgl/annotation/annotation_tile.cpp index c74fcfd4a..aa910ae54 100644 --- a/src/mbgl/annotation/annotation_tile.cpp +++ b/src/mbgl/annotation/annotation_tile.cpp @@ -52,12 +52,12 @@ FeatureType AnnotationTileFeature::getType() const { return data->type; } -optional AnnotationTileFeature::getValue(const std::string& key) const { +std::optional AnnotationTileFeature::getValue(const std::string& key) const { auto it = data->properties.find(key); if (it != data->properties.end()) { - return optional(it->second); + return std::optional(it->second); } - return optional(); + return std::nullopt; } FeatureIdentifier AnnotationTileFeature::getID() const { diff --git a/src/mbgl/annotation/annotation_tile.hpp b/src/mbgl/annotation/annotation_tile.hpp index 92ddf09f6..5fba88501 100644 --- a/src/mbgl/annotation/annotation_tile.hpp +++ b/src/mbgl/annotation/annotation_tile.hpp @@ -26,7 +26,7 @@ public: ~AnnotationTileFeature() override; FeatureType getType() const override; - optional getValue(const std::string&) const override; + std::optional getValue(const std::string&) const override; FeatureIdentifier getID() const override; const GeometryCollection& getGeometries() const override; diff --git a/src/mbgl/annotation/render_annotation_source.cpp b/src/mbgl/annotation/render_annotation_source.cpp index 571f619f1..3cd74b025 100644 --- a/src/mbgl/annotation/render_annotation_source.cpp +++ b/src/mbgl/annotation/render_annotation_source.cpp @@ -38,7 +38,7 @@ void RenderAnnotationSource::update(Immutable baseImpl_, // Zoom level 16 is typically sufficient for annotations. // See https://github.com/mapbox/mapbox-gl-native/issues/10197 {0, 16}, - optional{}, + std::nullopt, [&](const OverscaledTileID& tileID) { return std::make_unique(tileID, parameters); }); } diff --git a/src/mbgl/geometry/anchor.hpp b/src/mbgl/geometry/anchor.hpp index f50816a3a..454d3ad07 100644 --- a/src/mbgl/geometry/anchor.hpp +++ b/src/mbgl/geometry/anchor.hpp @@ -1,9 +1,10 @@ #pragma once #include -#include + #include #include +#include namespace mbgl { @@ -11,9 +12,9 @@ class Anchor { public: Point point; float angle = 0.0f; - optional segment; + std::optional segment; - Anchor(float x_, float y_, float angle_, optional segment_ = nullopt) + Anchor(float x_, float y_, float angle_, std::optional segment_ = std::nullopt) : point(x_, y_), angle(angle_), segment(std::move(segment_)) {} }; diff --git a/src/mbgl/geometry/feature_index.cpp b/src/mbgl/geometry/feature_index.cpp index 286956c15..c64bdf8bd 100644 --- a/src/mbgl/geometry/feature_index.cpp +++ b/src/mbgl/geometry/feature_index.cpp @@ -159,7 +159,7 @@ void FeatureIndex::addFeature(std::unordered_map idStr = featureIDtoString(geometryTileFeature->getID()); + std::optional idStr = featureIDtoString(geometryTileFeature->getID()); if (idStr) { sourceFeatureState->getState(state, sourceLayer->getName(), *idStr); } @@ -184,7 +184,7 @@ void FeatureIndex::addFeature(std::unordered_map FeatureIndex::translateQueryGeometry( +std::optional FeatureIndex::translateQueryGeometry( const GeometryCoordinates& queryGeometry, const std::array& translate, const style::TranslateAnchorType anchorType, diff --git a/src/mbgl/geometry/feature_index.hpp b/src/mbgl/geometry/feature_index.hpp index dc6aa55f5..7f1976910 100644 --- a/src/mbgl/geometry/feature_index.hpp +++ b/src/mbgl/geometry/feature_index.hpp @@ -92,7 +92,7 @@ public: float additionalQueryPadding, const SourceFeatureState& sourceFeatureState) const; - static optional translateQueryGeometry(const GeometryCoordinates& queryGeometry, + static std::optional translateQueryGeometry(const GeometryCoordinates& queryGeometry, const std::array& translate, style::TranslateAnchorType, float bearing, diff --git a/src/mbgl/geometry/line_atlas.hpp b/src/mbgl/geometry/line_atlas.hpp index 0ac5a489c..942e1a84b 100644 --- a/src/mbgl/geometry/line_atlas.hpp +++ b/src/mbgl/geometry/line_atlas.hpp @@ -2,12 +2,12 @@ #include #include -#include #include #include #include #include +#include namespace mbgl { diff --git a/src/mbgl/gfx/attribute.cpp b/src/mbgl/gfx/attribute.cpp index ed5d4032f..a96bd7593 100644 --- a/src/mbgl/gfx/attribute.cpp +++ b/src/mbgl/gfx/attribute.cpp @@ -6,7 +6,7 @@ namespace mbgl { namespace gfx { -optional offsetAttributeBinding(const optional& binding, std::size_t vertexOffset) { +std::optional offsetAttributeBinding(const std::optional& binding, std::size_t vertexOffset) { assert(vertexOffset <= std::numeric_limits::max()); if (binding) { AttributeBinding result = *binding; diff --git a/src/mbgl/gfx/attribute.hpp b/src/mbgl/gfx/attribute.hpp index 7b7f2ab6d..1707e13dc 100644 --- a/src/mbgl/gfx/attribute.hpp +++ b/src/mbgl/gfx/attribute.hpp @@ -5,11 +5,11 @@ #include #include #include -#include #include #include #include +#include #define MBGL_DEFINE_ATTRIBUTE(type_, n_, name_) \ struct name_ { \ @@ -95,6 +95,10 @@ public: lhs.vertexBufferResource == rhs.vertexBufferResource && lhs.vertexOffset == rhs.vertexOffset; } + + bool operator!=(const AttributeBinding& rhs) const { + return !(*this == rhs); + } }; // Attribute binding requires member offsets. The only standard way to @@ -255,7 +259,7 @@ AttributeBinding attributeBinding(const VertexBuffer>& }; } -optional offsetAttributeBinding(const optional& binding, std::size_t vertexOffset); +std::optional offsetAttributeBinding(const std::optional& binding, std::size_t vertexOffset); template class AttributeBindings; @@ -263,9 +267,9 @@ class AttributeBindings; template class AttributeBindings> final : public IndexedTuple, - TypeList>...>> { + TypeList>...>> { using Base = IndexedTuple, - TypeList>...>>; + TypeList>...>>; public: AttributeBindings(const VertexBuffer>>& buffer) diff --git a/src/mbgl/gfx/render_pass.hpp b/src/mbgl/gfx/render_pass.hpp index db5ba661b..3cc377429 100644 --- a/src/mbgl/gfx/render_pass.hpp +++ b/src/mbgl/gfx/render_pass.hpp @@ -2,9 +2,9 @@ #include #include -#include #include +#include namespace mbgl { namespace gfx { @@ -14,9 +14,9 @@ class Renderable; class RenderPassDescriptor { public: Renderable& renderable; - optional clearColor; - optional clearDepth; - optional clearStencil; + std::optional clearColor; + std::optional clearDepth; + std::optional clearStencil; }; class RenderPass { diff --git a/src/mbgl/gl/attribute.cpp b/src/mbgl/gl/attribute.cpp index d5240b5b7..e4fdf6fb7 100644 --- a/src/mbgl/gl/attribute.cpp +++ b/src/mbgl/gl/attribute.cpp @@ -6,7 +6,7 @@ namespace gl { using namespace platform; -optional queryLocation(ProgramID id, const char* name) { +std::optional queryLocation(ProgramID id, const char* name) { GLint attributeLocation = MBGL_CHECK_ERROR(glGetAttribLocation(id, name)); if (attributeLocation != -1) { return attributeLocation; diff --git a/src/mbgl/gl/attribute.hpp b/src/mbgl/gl/attribute.hpp index f7509ad08..888361649 100644 --- a/src/mbgl/gl/attribute.hpp +++ b/src/mbgl/gl/attribute.hpp @@ -4,18 +4,18 @@ #include #include #include -#include #include #include +#include namespace mbgl { namespace gl { -using AttributeBindingArray = std::vector>; +using AttributeBindingArray = std::vector>; using NamedAttributeLocations = std::vector>; -optional queryLocation(ProgramID id, const char* name); +std::optional queryLocation(ProgramID id, const char* name); template class AttributeLocations; @@ -24,7 +24,7 @@ template class AttributeLocations> final { private: using Locations = - IndexedTuple, TypeList>...>>; + IndexedTuple, TypeList>...>>; Locations locations; @@ -35,7 +35,7 @@ public: locations = Locations{ queryLocation(id, concat_literals<&string_literal<'a', '_'>::value, &As::name>::value())... }; using TypeOfFirst = typename std::tuple_element_t<0, std::tuple>; - auto first = locations.template get(); + [[maybe_unused]] auto first = locations.template get(); assert(first && first.value() == 0); } @@ -50,7 +50,7 @@ public: NamedAttributeLocations getNamedLocations() const { NamedAttributeLocations result; - auto maybeAddLocation = [&] (const std::string& name, const optional& location) { + auto maybeAddLocation = [&] (const std::string& name, const std::optional& location) { if (location) { result.emplace_back(name, *location); } @@ -67,8 +67,8 @@ public: AttributeBindingArray result; result.resize(sizeof...(As)); - auto maybeAddBinding = [&] (const optional& location, - const optional& binding) { + auto maybeAddBinding = [&] (const std::optional& location, + const std::optional& binding) { if (location) { result.at(*location) = binding; } diff --git a/src/mbgl/gl/context.cpp b/src/mbgl/gl/context.cpp index 6bb4475aa..4444eb565 100644 --- a/src/mbgl/gl/context.cpp +++ b/src/mbgl/gl/context.cpp @@ -84,7 +84,7 @@ void Context::initializeExtensions(const std::function(MBGL_CHECK_ERROR(glGetString(GL_RENDERER))); - Log::Info(Event::General, "GPU Identifier: %s", r.c_str()); + Log::Info(Event::General, "GPU Identifier: " + r); return r; }(); @@ -159,7 +159,7 @@ UniqueShader Context::createShader(ShaderType type, const std::initializer_list< if (logLength > 0) { const auto log = std::make_unique(logLength); MBGL_CHECK_ERROR(glGetShaderInfoLog(result, logLength, &logLength, log.get())); - Log::Error(Event::Shader, "Shader failed to compile: %s", log.get()); + Log::Error(Event::Shader, std::string("Shader failed to compile: ") + log.get()); } throw std::runtime_error("shader failed to compile"); @@ -199,7 +199,7 @@ void Context::verifyProgramLinkage(ProgramID program_) { const auto log = std::make_unique(logLength); if (logLength > 0) { MBGL_CHECK_ERROR(glGetProgramInfoLog(program_, logLength, &logLength, log.get())); - Log::Error(Event::Shader, "Program failed to link: %s", log.get()); + Log::Error(Event::Shader, std::string("Program failed to link: ") + log.get()); } throw std::runtime_error("program failed to link"); @@ -501,9 +501,9 @@ void Context::setDirtyState() { globalVertexArrayState.setDirty(); } -void Context::clear(optional color, - optional depth, - optional stencil) { +void Context::clear(std::optional color, + std::optional depth, + std::optional stencil) { GLbitfield mask = 0; if (color) { diff --git a/src/mbgl/gl/context.hpp b/src/mbgl/gl/context.hpp index ec0f4c1e2..ed926b3f9 100644 --- a/src/mbgl/gl/context.hpp +++ b/src/mbgl/gl/context.hpp @@ -82,9 +82,9 @@ public: } #endif // MBGL_USE_GLES2 - void clear(optional color, - optional depth, - optional stencil); + void clear(std::optional color, + std::optional depth, + std::optional stencil); void setDepthMode(const gfx::DepthMode&); void setStencilMode(const gfx::StencilMode&); diff --git a/src/mbgl/gl/custom_layer.cpp b/src/mbgl/gl/custom_layer.cpp index 47d1e6ea8..853b6e400 100644 --- a/src/mbgl/gl/custom_layer.cpp +++ b/src/mbgl/gl/custom_layer.cpp @@ -38,7 +38,7 @@ std::unique_ptr CustomLayer::cloneRef(const std::string&) const { using namespace conversion; -optional CustomLayer::setPropertyInternal(const std::string&, const Convertible&) { +std::optional CustomLayer::setPropertyInternal(const std::string&, const Convertible&) { return Error { "layer doesn't support this property" }; } diff --git a/src/mbgl/gl/debugging_extension.cpp b/src/mbgl/gl/debugging_extension.cpp index 5afa4f50f..06bdd70d9 100644 --- a/src/mbgl/gl/debugging_extension.cpp +++ b/src/mbgl/gl/debugging_extension.cpp @@ -46,8 +46,13 @@ void Debugging::DebugCallback(GLenum source, case GL_DEBUG_SEVERITY_NOTIFICATION: strSeverity = "DEBUG_SEVERITY_NOTIFICATION"; evtSeverity = mbgl::EventSeverity::Debug; break; default: strSource = "(unknown)"; evtSeverity = mbgl::EventSeverity::Debug; break; } + const std::string logMsg = "GL_" + strSource + + " GL_" + strType + + " " + std::to_string(id) + + " GL_" + strSeverity + + " - " + message; + mbgl::Log::Record(evtSeverity, mbgl::Event::OpenGL, logMsg); - mbgl::Log::Record(evtSeverity, mbgl::Event::OpenGL, "GL_%s GL_%s %u GL_%s - %s", strSource.c_str(), strType.c_str(), id, strSeverity.c_str(), message); } } // namespace extension diff --git a/src/mbgl/gl/offscreen_texture.cpp b/src/mbgl/gl/offscreen_texture.cpp index 303df0379..ab9e72a53 100644 --- a/src/mbgl/gl/offscreen_texture.cpp +++ b/src/mbgl/gl/offscreen_texture.cpp @@ -45,9 +45,9 @@ public: private: gl::Context& context; const Size size; - optional texture; + std::optional texture; const gfx::TextureChannelDataType type; - optional framebuffer; + std::optional framebuffer; }; OffscreenTexture::OffscreenTexture(gl::Context& context, diff --git a/src/mbgl/gl/uniform.hpp b/src/mbgl/gl/uniform.hpp index 671437921..f26bafd77 100644 --- a/src/mbgl/gl/uniform.hpp +++ b/src/mbgl/gl/uniform.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -11,6 +10,8 @@ #include #include #include +#include +#include namespace mbgl { namespace gl { @@ -49,7 +50,7 @@ public: } UniformLocation location; - optional current = {}; + std::optional current = std::nullopt; }; UniformLocation uniformLocation(ProgramID, const char* name); diff --git a/src/mbgl/gl/value.hpp b/src/mbgl/gl/value.hpp index a634bc335..04582f62b 100644 --- a/src/mbgl/gl/value.hpp +++ b/src/mbgl/gl/value.hpp @@ -264,7 +264,7 @@ struct BindVertexArray { }; struct VertexAttribute { - using Type = optional; + using Type = std::optional; static const Type Default; static void Set(const Type&, Context&, AttributeLocation); }; diff --git a/src/mbgl/layermanager/circle_layer_factory.cpp b/src/mbgl/layermanager/circle_layer_factory.cpp index 5bde1ede8..1e51b4f5b 100644 --- a/src/mbgl/layermanager/circle_layer_factory.cpp +++ b/src/mbgl/layermanager/circle_layer_factory.cpp @@ -13,7 +13,7 @@ const style::LayerTypeInfo* CircleLayerFactory::getTypeInfo() const noexcept { } std::unique_ptr CircleLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + auto const source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp b/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp index 079d1a094..234ba8947 100644 --- a/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp +++ b/src/mbgl/layermanager/fill_extrusion_layer_factory.cpp @@ -12,7 +12,7 @@ const style::LayerTypeInfo* FillExtrusionLayerFactory::getTypeInfo() const noexc } std::unique_ptr FillExtrusionLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + auto const source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layermanager/fill_layer_factory.cpp b/src/mbgl/layermanager/fill_layer_factory.cpp index 94f3f47ce..441dbb791 100644 --- a/src/mbgl/layermanager/fill_layer_factory.cpp +++ b/src/mbgl/layermanager/fill_layer_factory.cpp @@ -12,7 +12,7 @@ const style::LayerTypeInfo* FillLayerFactory::getTypeInfo() const noexcept { } std::unique_ptr FillLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + std::optional source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layermanager/heatmap_layer_factory.cpp b/src/mbgl/layermanager/heatmap_layer_factory.cpp index babbe8993..636afd5fd 100644 --- a/src/mbgl/layermanager/heatmap_layer_factory.cpp +++ b/src/mbgl/layermanager/heatmap_layer_factory.cpp @@ -12,7 +12,7 @@ const style::LayerTypeInfo* HeatmapLayerFactory::getTypeInfo() const noexcept { } std::unique_ptr HeatmapLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + auto const source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layermanager/hillshade_layer_factory.cpp b/src/mbgl/layermanager/hillshade_layer_factory.cpp index c2981e17e..4e1d78a69 100644 --- a/src/mbgl/layermanager/hillshade_layer_factory.cpp +++ b/src/mbgl/layermanager/hillshade_layer_factory.cpp @@ -11,7 +11,7 @@ const style::LayerTypeInfo* HillshadeLayerFactory::getTypeInfo() const noexcept } std::unique_ptr HillshadeLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + auto const source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layermanager/layer_factory.cpp b/src/mbgl/layermanager/layer_factory.cpp index 9db96f62c..f9b4d1c60 100644 --- a/src/mbgl/layermanager/layer_factory.cpp +++ b/src/mbgl/layermanager/layer_factory.cpp @@ -11,15 +11,15 @@ namespace mbgl { -optional LayerFactory::getSource(const style::conversion::Convertible& value) const noexcept { +std::optional LayerFactory::getSource(const style::conversion::Convertible& value) const noexcept { auto sourceValue = objectMember(value, "source"); if (!sourceValue) { - return nullopt; + return std::nullopt; } - optional source = toString(*sourceValue); + auto const source = toString(*sourceValue); if (!source) { - return nullopt; + return std::nullopt; } return source; diff --git a/src/mbgl/layermanager/line_layer_factory.cpp b/src/mbgl/layermanager/line_layer_factory.cpp index 03751fef0..cdffb2661 100644 --- a/src/mbgl/layermanager/line_layer_factory.cpp +++ b/src/mbgl/layermanager/line_layer_factory.cpp @@ -12,7 +12,7 @@ const style::LayerTypeInfo* LineLayerFactory::getTypeInfo() const noexcept { } std::unique_ptr LineLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + auto const source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layermanager/raster_layer_factory.cpp b/src/mbgl/layermanager/raster_layer_factory.cpp index 172d44547..dcc1f817e 100644 --- a/src/mbgl/layermanager/raster_layer_factory.cpp +++ b/src/mbgl/layermanager/raster_layer_factory.cpp @@ -11,7 +11,7 @@ const style::LayerTypeInfo* RasterLayerFactory::getTypeInfo() const noexcept { } std::unique_ptr RasterLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + auto const source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layermanager/symbol_layer_factory.cpp b/src/mbgl/layermanager/symbol_layer_factory.cpp index 5f3de27bb..d307def5d 100644 --- a/src/mbgl/layermanager/symbol_layer_factory.cpp +++ b/src/mbgl/layermanager/symbol_layer_factory.cpp @@ -12,7 +12,7 @@ const style::LayerTypeInfo* SymbolLayerFactory::getTypeInfo() const noexcept { } std::unique_ptr SymbolLayerFactory::createLayer(const std::string& id, const style::conversion::Convertible& value) noexcept { - optional source = getSource(value); + std::optional source = getSource(value); if (!source) { return nullptr; } diff --git a/src/mbgl/layout/symbol_feature.hpp b/src/mbgl/layout/symbol_feature.hpp index f53664270..db7d3c859 100644 --- a/src/mbgl/layout/symbol_feature.hpp +++ b/src/mbgl/layout/symbol_feature.hpp @@ -3,10 +3,10 @@ #include #include #include -#include #include #include +#include namespace mbgl { @@ -18,7 +18,7 @@ public: {} FeatureType getType() const override { return feature->getType(); } - optional getValue(const std::string& key) const override { return feature->getValue(key); } + std::optional getValue(const std::string& key) const override { return feature->getValue(key); } const PropertyMap& getProperties() const override { return feature->getProperties(); } FeatureIdentifier getID() const override { return feature->getID(); }; const GeometryCollection& getGeometries() const override { return feature->getGeometries(); } @@ -29,8 +29,8 @@ public: std::unique_ptr feature; GeometryCollection geometry; - optional formattedText; - optional icon; + std::optional formattedText; + std::optional icon; float sortKey = 0.0f; std::size_t index; bool allowsVerticalWritingMode = false; diff --git a/src/mbgl/layout/symbol_instance.cpp b/src/mbgl/layout/symbol_instance.cpp index 9eda80d4e..217585920 100644 --- a/src/mbgl/layout/symbol_instance.cpp +++ b/src/mbgl/layout/symbol_instance.cpp @@ -20,8 +20,8 @@ const Shaping& getAnyShaping(const ShapedTextOrientations& shapedTextOrientation SymbolInstanceSharedData::SymbolInstanceSharedData(GeometryCoordinates line_, const ShapedTextOrientations& shapedTextOrientations, - const optional& shapedIcon, - const optional& verticallyShapedIcon, + const std::optional& shapedIcon, + const std::optional& verticallyShapedIcon, const style::SymbolLayoutProperties::Evaluated& layout, const style::SymbolPlacementType textPlacement, const std::array& textOffset, @@ -77,8 +77,8 @@ bool SymbolInstanceSharedData::empty() const { SymbolInstance::SymbolInstance(Anchor& anchor_, std::shared_ptr sharedData_, const ShapedTextOrientations& shapedTextOrientations, - const optional& shapedIcon, - const optional& verticallyShapedIcon, + const std::optional& shapedIcon, + const std::optional& verticallyShapedIcon, const float textBoxScale_, const float textPadding, const SymbolPlacementType textPlacement, @@ -167,7 +167,7 @@ const SymbolQuads& SymbolInstance::verticalGlyphQuads() const { return sharedData->verticalGlyphQuads; } -const optional& SymbolInstance::iconQuads() const { +const std::optional& SymbolInstance::iconQuads() const { assert(sharedData); return sharedData->iconQuads; } @@ -184,7 +184,7 @@ bool SymbolInstance::hasSdfIcon() const { return static_cast(symbolContent & SymbolContent::IconSDF); } -const optional& SymbolInstance::verticalIconQuads() const { +const std::optional& SymbolInstance::verticalIconQuads() const { assert(sharedData); return sharedData->verticalIconQuads; } @@ -193,10 +193,10 @@ void SymbolInstance::releaseSharedData() { sharedData.reset(); } -optional SymbolInstance::getDefaultHorizontalPlacedTextIndex() const { +std::optional SymbolInstance::getDefaultHorizontalPlacedTextIndex() const { if (placedRightTextIndex) return placedRightTextIndex; if (placedCenterTextIndex) return placedCenterTextIndex; if (placedLeftTextIndex) return placedLeftTextIndex; - return nullopt; + return std::nullopt; } } // namespace mbgl diff --git a/src/mbgl/layout/symbol_instance.hpp b/src/mbgl/layout/symbol_instance.hpp index b10a3acae..ea109fc4c 100644 --- a/src/mbgl/layout/symbol_instance.hpp +++ b/src/mbgl/layout/symbol_instance.hpp @@ -26,8 +26,8 @@ enum class SymbolContent : uint8_t { None = 0, Text = 1 << 0, IconRGBA = 1 << 1, struct SymbolInstanceSharedData { SymbolInstanceSharedData(GeometryCoordinates line, const ShapedTextOrientations& shapedTextOrientations, - const optional& shapedIcon, - const optional& verticallyShapedIcon, + const std::optional& shapedIcon, + const std::optional& verticallyShapedIcon, const style::SymbolLayoutProperties::Evaluated& layout, style::SymbolPlacementType textPlacement, const std::array& textOffset, @@ -43,8 +43,8 @@ struct SymbolInstanceSharedData { SymbolQuads centerJustifiedGlyphQuads; SymbolQuads leftJustifiedGlyphQuads; SymbolQuads verticalGlyphQuads; - optional iconQuads; - optional verticalIconQuads; + std::optional iconQuads; + std::optional verticalIconQuads; }; class SymbolInstance { @@ -52,8 +52,8 @@ public: SymbolInstance(Anchor& anchor_, std::shared_ptr sharedData, const ShapedTextOrientations& shapedTextOrientations, - const optional& shapedIcon, - const optional& verticallyShapedIcon, + const std::optional& shapedIcon, + const std::optional& verticallyShapedIcon, float textBoxScale, float textPadding, style::SymbolPlacementType textPlacement, @@ -72,7 +72,7 @@ public: bool allowVerticalPlacement, SymbolContent iconType = SymbolContent::None); - optional getDefaultHorizontalPlacedTextIndex() const; + std::optional getDefaultHorizontalPlacedTextIndex() const; const GeometryCoordinates& line() const; const SymbolQuads& rightJustifiedGlyphQuads() const; const SymbolQuads& leftJustifiedGlyphQuads() const; @@ -81,8 +81,8 @@ public: bool hasText() const; bool hasIcon() const; bool hasSdfIcon() const; - const optional& iconQuads() const; - const optional& verticalIconQuads() const; + const std::optional& iconQuads() const; + const std::optional& verticalIconQuads() const; void releaseSharedData(); private: @@ -100,8 +100,8 @@ public: CollisionFeature textCollisionFeature; CollisionFeature iconCollisionFeature; - optional verticalTextCollisionFeature = nullopt; - optional verticalIconCollisionFeature = nullopt; + std::optional verticalTextCollisionFeature = std::nullopt; + std::optional verticalIconCollisionFeature = std::nullopt; WritingModeType writingModes; std::size_t layoutFeatureIndex; // Index into the set of features included at layout time std::size_t dataFeatureIndex; // Index into the underlying tile data feature set @@ -109,12 +109,12 @@ public: std::array iconOffset; std::u16string key; bool isDuplicate; - optional placedRightTextIndex; - optional placedCenterTextIndex; - optional placedLeftTextIndex; - optional placedVerticalTextIndex; - optional placedIconIndex; - optional placedVerticalIconIndex; + std::optional placedRightTextIndex; + std::optional placedCenterTextIndex; + std::optional placedLeftTextIndex; + std::optional placedVerticalTextIndex; + std::optional placedIconIndex; + std::optional placedVerticalIconIndex; float textBoxScale; std::array variableTextOffset; bool singleLine; diff --git a/src/mbgl/layout/symbol_layout.cpp b/src/mbgl/layout/symbol_layout.cpp index 366ad8295..242ce15a0 100644 --- a/src/mbgl/layout/symbol_layout.cpp +++ b/src/mbgl/layout/symbol_layout.cpp @@ -354,7 +354,7 @@ void SymbolLayout::prepareSymbols(const GlyphMap& glyphMap, if (feature.geometry.empty()) continue; ShapedTextOrientations shapedTextOrientations; - optional shapedIcon; + std::optional shapedIcon; std::array textOffset{{0.0f, 0.0f}}; const float layoutTextSize = layout->evaluate(zoom + 1, feature, canonicalID); const float layoutTextSizeAtBucketZoomLevel = layout->evaluate(zoom, feature, canonicalID); @@ -516,7 +516,7 @@ void SymbolLayout::prepareSymbols(const GlyphMap& glyphMap, void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex, const SymbolFeature& feature, const ShapedTextOrientations& shapedTextOrientations, - optional shapedIcon, + std::optional shapedIcon, const ImageMap& imageMap, std::array textOffset, float layoutTextSize, @@ -563,7 +563,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex, const auto iconTextFit = evaluatedLayoutProperties.get(); const bool hasIconTextFit = iconTextFit != IconTextFitType::None; // Adjust shaped icon size when icon-text-fit is used. - optional verticallyShapedIcon; + std::optional verticallyShapedIcon; if (shapedIcon && hasIconTextFit) { // Create vertically shaped icon for vertical writing mode if needed. if (allowVerticalPlacement && shapedTextOrientations.vertical) { @@ -664,7 +664,7 @@ void SymbolLayout::addFeature(const std::size_t layoutFeatureIndex, // "lines" with only one point are ignored as in clipLines for (const auto& line : feature.geometry) { if (line.size() > 1) { - optional anchor = getCenterAnchor(line, + std::optional anchor = getCenterAnchor(line, textMaxAngle, (shapedTextOrientations.vertical ? shapedTextOrientations.vertical : getDefaultHorizontalShaping(shapedTextOrientations)).left, (shapedTextOrientations.vertical ? shapedTextOrientations.vertical : getDefaultHorizontalShaping(shapedTextOrientations)).right, @@ -818,9 +818,9 @@ void SymbolLayout::createBucket(const ImagePositions&, } if (hasText && feature.formattedText) { - optional lastAddedSection; + std::optional lastAddedSection; if (singleLine) { - optional placedTextIndex; + std::optional placedTextIndex; lastAddedSection = addSymbolGlyphQuads(*bucket, symbolInstance, feature, @@ -909,10 +909,10 @@ std::size_t SymbolLayout::addSymbolGlyphQuads(SymbolBucket& bucket, SymbolInstance& symbolInstance, const SymbolFeature& feature, WritingModeType writingMode, - optional& placedIndex, + std::optional& placedIndex, const SymbolQuads& glyphQuads, const CanonicalTileID& canonical, - optional lastAddedSection) { + std::optional lastAddedSection) { const Range sizeData = bucket.textSizeBinder->getVertexSizeData(feature); const bool hasFormatSectionOverrides = bucket.hasFormatSectionOverrides(); const auto& placedIconIndex = writingMode == WritingModeType::Vertical ? symbolInstance.placedVerticalIconIndex : symbolInstance.placedIconIndex; diff --git a/src/mbgl/layout/symbol_layout.hpp b/src/mbgl/layout/symbol_layout.hpp index 915a2ae92..12234fba8 100644 --- a/src/mbgl/layout/symbol_layout.hpp +++ b/src/mbgl/layout/symbol_layout.hpp @@ -68,7 +68,7 @@ private: void addFeature(size_t, const SymbolFeature&, const ShapedTextOrientations& shapedTextOrientations, - optional shapedIcon, + std::optional shapedIcon, const ImageMap&, std::array textOffset, float layoutTextSize, @@ -100,10 +100,10 @@ private: SymbolInstance&, const SymbolFeature&, WritingModeType, - optional& placedIndex, + std::optional& placedIndex, const SymbolQuads&, const CanonicalTileID& canonical, - optional lastAddedSection = nullopt); + std::optional lastAddedSection = std::nullopt); void updatePaintPropertiesForSection(SymbolBucket&, const SymbolFeature&, diff --git a/src/mbgl/layout/symbol_projection.cpp b/src/mbgl/layout/symbol_projection.cpp index b9e57de37..674b0ca96 100644 --- a/src/mbgl/layout/symbol_projection.cpp +++ b/src/mbgl/layout/symbol_projection.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include namespace mbgl { @@ -155,7 +154,7 @@ namespace mbgl { return previousProjectedPoint + (projectedUnitSegment * (minimumLength / util::mag(projectedUnitSegment))); } - optional placeGlyphAlongLine(const float offsetX, const float lineOffsetX, const float lineOffsetY, const bool flip, + std::optional placeGlyphAlongLine(const float offsetX, const float lineOffsetX, const float lineOffsetY, const bool flip, const Point& projectedAnchorPoint, const Point& tileAnchorPoint, const uint16_t anchorSegment, const GeometryCoordinates& line, const std::vector& tileDistances, const mat4& labelPlaneMatrix, const bool returnTileDistance) { const float combinedOffsetX = flip ? @@ -227,11 +226,11 @@ namespace mbgl { (currentIndex - dir) == initialIndex ? 0 : tileDistances[currentIndex - dir], absOffsetX - distanceToPrev ) : - optional() + std::optional() }}; } - optional> placeFirstAndLastGlyph(const float fontScale, + std::optional> placeFirstAndLastGlyph(const float fontScale, const float lineOffsetX, const float lineOffsetY, const bool flip, @@ -248,16 +247,16 @@ namespace mbgl { const float firstGlyphOffset = symbol.glyphOffsets.front(); const float lastGlyphOffset = symbol.glyphOffsets.back();; - optional firstPlacedGlyph = placeGlyphAlongLine(fontScale * firstGlyphOffset, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, static_cast(symbol.segment), symbol.line, symbol.tileDistances, labelPlaneMatrix, returnTileDistance); + std::optional firstPlacedGlyph = placeGlyphAlongLine(fontScale * firstGlyphOffset, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, static_cast(symbol.segment), symbol.line, symbol.tileDistances, labelPlaneMatrix, returnTileDistance); if (!firstPlacedGlyph) return {}; - optional lastPlacedGlyph = placeGlyphAlongLine(fontScale * lastGlyphOffset, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, static_cast(symbol.segment), symbol.line, symbol.tileDistances, labelPlaneMatrix, returnTileDistance); + std::optional lastPlacedGlyph = placeGlyphAlongLine(fontScale * lastGlyphOffset, lineOffsetX, lineOffsetY, flip, anchorPoint, tileAnchorPoint, static_cast(symbol.segment), symbol.line, symbol.tileDistances, labelPlaneMatrix, returnTileDistance); if (!lastPlacedGlyph) return {}; return std::make_pair(*firstPlacedGlyph, *lastPlacedGlyph); } - optional requiresOrientationChange(const WritingModeType writingModes, const Point& firstPoint, const Point& lastPoint, const float aspectRatio) { + std::optional requiresOrientationChange(const WritingModeType writingModes, const Point& firstPoint, const Point& lastPoint, const float aspectRatio) { if (writingModes == (WritingModeType::Horizontal | WritingModeType::Vertical)) { // On top of choosing whether to flip, choose whether to render this version of the glyphs or the alternate // vertical glyphs. We can't just filter out vertical glyphs in the horizontal range because the horizontal @@ -296,7 +295,7 @@ namespace mbgl { std::vector placedGlyphs; if (symbol.glyphOffsets.size() > 1) { - const optional> firstAndLastGlyph = + const std::optional> firstAndLastGlyph = placeFirstAndLastGlyph(fontScale, lineOffsetX, lineOffsetY, flip, projectedAnchorPoint, symbol.anchorPoint, symbol, labelPlaneMatrix, false); if (!firstAndLastGlyph) { return PlacementResult::NotEnoughRoom; @@ -320,7 +319,7 @@ namespace mbgl { if (placedGlyph) { placedGlyphs.push_back(*placedGlyph); } else { - placedGlyphs.emplace_back(Point{-INFINITY, -INFINITY}, 0.0f, nullopt); + placedGlyphs.emplace_back(Point{-INFINITY, -INFINITY}, 0.0f, std::nullopt); } } placedGlyphs.push_back(firstAndLastGlyph->second); @@ -344,7 +343,7 @@ namespace mbgl { } } const float glyphOffsetX = symbol.glyphOffsets.front(); - optional singleGlyph = placeGlyphAlongLine(fontScale * glyphOffsetX, lineOffsetX, lineOffsetY, flip, projectedAnchorPoint, symbol.anchorPoint, static_cast(symbol.segment), + std::optional singleGlyph = placeGlyphAlongLine(fontScale * glyphOffsetX, lineOffsetX, lineOffsetY, flip, projectedAnchorPoint, symbol.anchorPoint, static_cast(symbol.segment), symbol.line, symbol.tileDistances, labelPlaneMatrix, false); if (!singleGlyph) return PlacementResult::NotEnoughRoom; diff --git a/src/mbgl/layout/symbol_projection.hpp b/src/mbgl/layout/symbol_projection.hpp index 598073bf5..afd5fd5a0 100644 --- a/src/mbgl/layout/symbol_projection.hpp +++ b/src/mbgl/layout/symbol_projection.hpp @@ -25,7 +25,7 @@ namespace mbgl { struct PlacedGlyph { PlacedGlyph() = default; - PlacedGlyph(Point point_, float angle_, optional tileDistance_) + PlacedGlyph(Point point_, float angle_, std::optional tileDistance_) : point(point_), angle(angle_), tileDistance(std::move(tileDistance_)) {} PlacedGlyph(PlacedGlyph&& other) noexcept @@ -33,7 +33,7 @@ namespace mbgl { PlacedGlyph(const PlacedGlyph& other) = default; Point point; float angle; - optional tileDistance; + std::optional tileDistance; }; float evaluateSizeForFeature(const ZoomEvaluatedSize& zoomEvaluatedSize, const PlacedSymbol& placedSymbol); @@ -55,7 +55,7 @@ namespace mbgl { const mat4& posMatrix, bool pitchWithMap, bool rotateWithMap, bool keepUpright, const RenderTile&, const SymbolSizeBinder& sizeBinder, const TransformState&); - optional> placeFirstAndLastGlyph(float fontScale, + std::optional> placeFirstAndLastGlyph(float fontScale, float lineOffsetX, float lineOffsetY, bool flip, diff --git a/src/mbgl/map/map.cpp b/src/mbgl/map/map.cpp index d520c9078..1d8e3a3c1 100644 --- a/src/mbgl/map/map.cpp +++ b/src/mbgl/map/map.cpp @@ -129,7 +129,7 @@ bool Map::isPanning() const { // MARK: - -CameraOptions Map::getCameraOptions(const optional& padding) const { +CameraOptions Map::getCameraOptions(const std::optional& padding) const { return impl->transform.getCameraOptions(padding); } @@ -159,7 +159,7 @@ void Map::pitchBy(double pitch, const AnimationOptions& animation) { easeTo(CameraOptions().withPitch((impl->transform.getPitch() * util::RAD2DEG_D) - pitch), animation); } -void Map::scaleBy(double scale, const optional& anchor, const AnimationOptions& animation) { +void Map::scaleBy(double scale, const std::optional& anchor, const AnimationOptions& animation) { const double zoom = impl->transform.getZoom() + impl->transform.getState().scaleZoom(scale); easeTo(CameraOptions().withZoom(zoom).withAnchor(anchor), animation); } @@ -172,8 +172,8 @@ void Map::rotateBy(const ScreenCoordinate& first, const ScreenCoordinate& second CameraOptions Map::cameraForLatLngBounds(const LatLngBounds& bounds, const EdgeInsets& padding, - const optional& bearing, - const optional& pitch) const { + const std::optional& bearing, + const std::optional& pitch) const { return cameraForLatLngs( { bounds.northwest(), @@ -233,8 +233,8 @@ CameraOptions cameraForLatLngs(const std::vector& latLngs, const Transfo CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, const EdgeInsets& padding, - const optional& bearing, - const optional& pitch) const { + const std::optional& bearing, + const std::optional& pitch) const { if (!bearing && !pitch) { return mbgl::cameraForLatLngs(latLngs, impl->transform, padding); } @@ -252,8 +252,8 @@ CameraOptions Map::cameraForLatLngs(const std::vector& latLngs, CameraOptions Map::cameraForGeometry(const Geometry& geometry, const EdgeInsets& padding, - const optional& bearing, - const optional& pitch) const { + const std::optional& bearing, + const std::optional& pitch) const { std::vector latLngs; forEachPoint(geometry, [&](const Point& pt) { latLngs.emplace_back(pt.y, pt.x); diff --git a/src/mbgl/map/map_projection.cpp b/src/mbgl/map/map_projection.cpp index d37664716..26a52eb73 100644 --- a/src/mbgl/map/map_projection.cpp +++ b/src/mbgl/map/map_projection.cpp @@ -26,7 +26,7 @@ void MapProjection::setCamera(const CameraOptions& camera) { } CameraOptions MapProjection::getCamera() const { - return transform->getCameraOptions(nullopt); + return transform->getCameraOptions(std::nullopt); } void MapProjection::setVisibleCoordinates(const std::vector& latLngs, diff --git a/src/mbgl/map/transform.cpp b/src/mbgl/map/transform.cpp index 74eba874c..3616365ca 100644 --- a/src/mbgl/map/transform.cpp +++ b/src/mbgl/map/transform.cpp @@ -67,7 +67,7 @@ void Transform::resize(const Size size) { // MARK: - Camera -CameraOptions Transform::getCameraOptions(const optional& padding) const { +CameraOptions Transform::getCameraOptions(const std::optional& padding) const { return state.getCameraOptions(padding); } @@ -384,8 +384,8 @@ void Transform::setMinPitch(const double minPitch) { if (std::isnan(minPitch)) return; if (minPitch * util::DEG2RAD_D < util::PITCH_MIN) { Log::Warning(Event::General, - "Trying to set minimum pitch below the limit (%.0f degrees), the value will be clamped.", - util::PITCH_MIN * util::RAD2DEG_D); + "Trying to set minimum pitch below the limit (" + std::to_string(util::PITCH_MIN * util::RAD2DEG_D) + + " degrees), the value will be clamped."); } state.setMinPitch(minPitch * util::DEG2RAD_D); } @@ -394,8 +394,8 @@ void Transform::setMaxPitch(const double maxPitch) { if (std::isnan(maxPitch)) return; if (maxPitch * util::DEG2RAD_D > util::PITCH_MAX) { Log::Warning(Event::General, - "Trying to set maximum pitch above the limit (%.0f degrees), the value will be clamped.", - util::PITCH_MAX * util::RAD2DEG_D); + "Trying to set maximum pitch above the limit (" + std::to_string(util::PITCH_MAX * util::RAD2DEG_D) + + " degrees), the value will be clamped."); } state.setMaxPitch(maxPitch * util::DEG2RAD_D); } @@ -505,7 +505,7 @@ void Transform::startTransition(const CameraOptions& camera, // Associate the anchor, if given, with a coordinate. // Anchor and center points are mutually exclusive, with preference for the // center point when both are set. - optional anchor = camera.center ? nullopt : camera.anchor; + std::optional anchor = camera.center ? std::nullopt : camera.anchor; LatLng anchorLatLng; if (anchor) { anchor->y = state.getSize().height - anchor->y; diff --git a/src/mbgl/map/transform.hpp b/src/mbgl/map/transform.hpp index 90be7a9ef..a1458bf8c 100644 --- a/src/mbgl/map/transform.hpp +++ b/src/mbgl/map/transform.hpp @@ -8,11 +8,11 @@ #include #include #include -#include #include #include #include +#include namespace mbgl { @@ -29,7 +29,7 @@ public: // Camera /** Returns the current camera options. */ - CameraOptions getCameraOptions(const optional&) const; + CameraOptions getCameraOptions(const std::optional&) const; /** Instantaneously, synchronously applies the given camera options. */ void jumpTo(const CameraOptions&); diff --git a/src/mbgl/map/transform_state.cpp b/src/mbgl/map/transform_state.cpp index f770293e5..008a8cf58 100644 --- a/src/mbgl/map/transform_state.cpp +++ b/src/mbgl/map/transform_state.cpp @@ -282,7 +282,7 @@ bool TransformState::setCameraOrientation(const Quaternion& orientation_) { return false; } - const optional updatedOrientation = util::Camera::orientationFromFrame(forward, up); + const std::optional updatedOrientation = util::Camera::orientationFromFrame(forward, up); if (!updatedOrientation) return false; camera.setOrientation(updatedOrientation.value()); @@ -415,7 +415,7 @@ void TransformState::setViewportMode(ViewportMode val) { // MARK: - Camera options -CameraOptions TransformState::getCameraOptions(const optional& padding) const { +CameraOptions TransformState::getCameraOptions(const std::optional& padding) const { return CameraOptions() .withCenter(getLatLng()) .withPadding(padding ? padding : edgeInsets) diff --git a/src/mbgl/map/transform_state.hpp b/src/mbgl/map/transform_state.hpp index aa2706717..c4fe5cc2f 100644 --- a/src/mbgl/map/transform_state.hpp +++ b/src/mbgl/map/transform_state.hpp @@ -7,13 +7,13 @@ #include #include #include -#include #include #include #include #include #include +#include namespace mbgl { @@ -21,87 +21,87 @@ class UnwrappedTileID; class TileCoordinate; struct TransformStateProperties { - TransformStateProperties& withX(const optional& val) { + TransformStateProperties& withX(const std::optional& val) { x = val; return *this; } - TransformStateProperties& withY(const optional& val) { + TransformStateProperties& withY(const std::optional& val) { y = val; return *this; } - TransformStateProperties& withScale(const optional& val) { + TransformStateProperties& withScale(const std::optional& val) { scale = val; return *this; } - TransformStateProperties& withBearing(const optional& val) { + TransformStateProperties& withBearing(const std::optional& val) { bearing = val; return *this; } - TransformStateProperties& withPitch(const optional& val) { + TransformStateProperties& withPitch(const std::optional& val) { pitch = val; return *this; } - TransformStateProperties& withXSkew(const optional& val) { + TransformStateProperties& withXSkew(const std::optional& val) { xSkew = val; return *this; } - TransformStateProperties& withYSkew(const optional& val) { + TransformStateProperties& withYSkew(const std::optional& val) { ySkew = val; return *this; } - TransformStateProperties& withAxonometric(const optional& val) { + TransformStateProperties& withAxonometric(const std::optional& val) { axonometric = val; return *this; } - TransformStateProperties& withPanningInProgress(const optional& val) { + TransformStateProperties& withPanningInProgress(const std::optional& val) { panning = val; return *this; } - TransformStateProperties& withScalingInProgress(const optional& val) { + TransformStateProperties& withScalingInProgress(const std::optional& val) { scaling = val; return *this; } - TransformStateProperties& withRotatingInProgress(const optional& val) { + TransformStateProperties& withRotatingInProgress(const std::optional& val) { rotating = val; return *this; } - TransformStateProperties& withEdgeInsets(const optional& val) { + TransformStateProperties& withEdgeInsets(const std::optional& val) { edgeInsets = val; return *this; } - TransformStateProperties& withSize(const optional& val) { + TransformStateProperties& withSize(const std::optional& val) { size = val; return *this; } - TransformStateProperties& withConstrainMode(const optional& val) { + TransformStateProperties& withConstrainMode(const std::optional& val) { constrain = val; return *this; } - TransformStateProperties& withNorthOrientation(const optional& val) { + TransformStateProperties& withNorthOrientation(const std::optional& val) { northOrientation = val; return *this; } - TransformStateProperties& withViewportMode(const optional& val) { + TransformStateProperties& withViewportMode(const std::optional& val) { viewPortMode = val; return *this; } - optional x; - optional y; - optional bearing; - optional scale; - optional pitch; - optional xSkew; - optional ySkew; - optional axonometric; - optional panning; - optional scaling; - optional rotating; - optional edgeInsets; - optional size; - optional constrain; - optional northOrientation; - optional viewPortMode; + std::optional x; + std::optional y; + std::optional bearing; + std::optional scale; + std::optional pitch; + std::optional xSkew; + std::optional ySkew; + std::optional axonometric; + std::optional panning; + std::optional scaling; + std::optional rotating; + std::optional edgeInsets; + std::optional size; + std::optional constrain; + std::optional northOrientation; + std::optional viewPortMode; }; class TransformState { @@ -131,7 +131,7 @@ public: ViewportMode getViewportMode() const; void setViewportMode(ViewportMode val); - CameraOptions getCameraOptions(const optional&) const; + CameraOptions getCameraOptions(const std::optional&) const; // EdgeInsects EdgeInsets getEdgeInsets() const { return edgeInsets; } diff --git a/src/mbgl/platform/gl_functions.cpp b/src/mbgl/platform/gl_functions.cpp index 6eb7790ca..1ffbd47b4 100644 --- a/src/mbgl/platform/gl_functions.cpp +++ b/src/mbgl/platform/gl_functions.cpp @@ -1,6 +1,7 @@ #include #include +#include namespace mbgl { namespace platform { @@ -8,7 +9,7 @@ namespace platform { #ifndef NDEBUG void glCheckError(const char* cmd, const char* file, int line) { if (GLenum err = glGetError()) { - Log::Warning(Event::OpenGL, "Error %d: %s - %s:%d", err, cmd, file, line); + Log::Warning(Event::OpenGL, "Error" + std::to_string(err) + ": " + cmd + " - " + file + ":" + std::to_string(line)); } } #endif diff --git a/src/mbgl/programs/program_parameters.hpp b/src/mbgl/programs/program_parameters.hpp index 8af7ab50c..b471471b1 100644 --- a/src/mbgl/programs/program_parameters.hpp +++ b/src/mbgl/programs/program_parameters.hpp @@ -1,7 +1,5 @@ #pragma once -#include - #include namespace mbgl { diff --git a/src/mbgl/programs/segment.hpp b/src/mbgl/programs/segment.hpp index 908c0b5f3..c263511f5 100644 --- a/src/mbgl/programs/segment.hpp +++ b/src/mbgl/programs/segment.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace mbgl { diff --git a/src/mbgl/programs/symbol_program.hpp b/src/mbgl/programs/symbol_program.hpp index 848fc0b00..8c4bc1f1d 100644 --- a/src/mbgl/programs/symbol_program.hpp +++ b/src/mbgl/programs/symbol_program.hpp @@ -137,8 +137,8 @@ public: } float layoutSize; - optional, Range>> coveringRanges; - optional> expression; + std::optional, Range>> coveringRanges; + std::optional> expression; }; class SourceFunctionSymbolSizeBinder final : public SymbolSizeBinder { diff --git a/src/mbgl/renderer/buckets/circle_bucket.hpp b/src/mbgl/renderer/buckets/circle_bucket.hpp index 1abd9c77f..c1584ec5d 100644 --- a/src/mbgl/renderer/buckets/circle_bucket.hpp +++ b/src/mbgl/renderer/buckets/circle_bucket.hpp @@ -34,8 +34,8 @@ public: gfx::IndexVector triangles; SegmentVector segments; - optional> vertexBuffer; - optional indexBuffer; + std::optional> vertexBuffer; + std::optional indexBuffer; std::map paintPropertyBinders; diff --git a/src/mbgl/renderer/buckets/debug_bucket.cpp b/src/mbgl/renderer/buckets/debug_bucket.cpp index 6bc2d811f..e752a1f1c 100644 --- a/src/mbgl/renderer/buckets/debug_bucket.cpp +++ b/src/mbgl/renderer/buckets/debug_bucket.cpp @@ -12,8 +12,8 @@ namespace mbgl { DebugBucket::DebugBucket(const OverscaledTileID& id, const bool renderable_, const bool complete_, - optional modified_, - optional expires_, + std::optional modified_, + std::optional expires_, MapDebugOptions debugMode_) : renderable(renderable_), complete(complete_), @@ -25,7 +25,7 @@ DebugBucket::DebugBucket(const OverscaledTileID& id, if (c < 32 || c >= 127) continue; - optional> prev; + std::optional> prev; const glyph& glyph = simplex[c - 32]; for (int32_t j = 0; j < glyph.length; j += 2) { diff --git a/src/mbgl/renderer/buckets/debug_bucket.hpp b/src/mbgl/renderer/buckets/debug_bucket.hpp index fb79cc834..34d6f9e8a 100644 --- a/src/mbgl/renderer/buckets/debug_bucket.hpp +++ b/src/mbgl/renderer/buckets/debug_bucket.hpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include @@ -19,16 +18,16 @@ public: DebugBucket(const OverscaledTileID& id, bool renderable, bool complete, - optional modified, - optional expires, + std::optional modified, + std::optional expires, MapDebugOptions); void upload(gfx::UploadPass&); const bool renderable; const bool complete; - const optional modified; - const optional expires; + const std::optional modified; + const std::optional expires; const MapDebugOptions debugMode; @@ -37,9 +36,9 @@ public: SegmentVector segments; SegmentVector tileBorderSegments; - optional> vertexBuffer; - optional indexBuffer; - optional texture; + std::optional> vertexBuffer; + std::optional indexBuffer; + std::optional texture; }; } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/fill_bucket.cpp b/src/mbgl/renderer/buckets/fill_bucket.cpp index 16c3cdf06..6554cb2ab 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.cpp +++ b/src/mbgl/renderer/buckets/fill_bucket.cpp @@ -137,7 +137,7 @@ void FillBucket::upload(gfx::UploadPass& uploadPass) { vertexBuffer = uploadPass.createVertexBuffer(std::move(vertices)); lineIndexBuffer = uploadPass.createIndexBuffer(std::move(lines)); triangleIndexBuffer = - triangles.empty() ? optional{} : uploadPass.createIndexBuffer(std::move(triangles)); + triangles.empty() ? std::optional{} : uploadPass.createIndexBuffer(std::move(triangles)); } for (auto& pair : paintPropertyBinders) { diff --git a/src/mbgl/renderer/buckets/fill_bucket.hpp b/src/mbgl/renderer/buckets/fill_bucket.hpp index 2812e1fde..b3014da76 100644 --- a/src/mbgl/renderer/buckets/fill_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_bucket.hpp @@ -46,9 +46,9 @@ public: SegmentVector lineSegments; SegmentVector triangleSegments; - optional> vertexBuffer; - optional lineIndexBuffer; - optional triangleIndexBuffer; + std::optional> vertexBuffer; + std::optional lineIndexBuffer; + std::optional triangleIndexBuffer; std::map paintPropertyBinders; }; diff --git a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp index 7143d4326..da59981fb 100644 --- a/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp +++ b/src/mbgl/renderer/buckets/fill_extrusion_bucket.hpp @@ -43,8 +43,8 @@ public: gfx::IndexVector triangles; SegmentVector triangleSegments; - optional> vertexBuffer; - optional indexBuffer; + std::optional> vertexBuffer; + std::optional indexBuffer; std::unordered_map paintPropertyBinders; }; diff --git a/src/mbgl/renderer/buckets/heatmap_bucket.hpp b/src/mbgl/renderer/buckets/heatmap_bucket.hpp index 0aaff7f29..33f99822a 100644 --- a/src/mbgl/renderer/buckets/heatmap_bucket.hpp +++ b/src/mbgl/renderer/buckets/heatmap_bucket.hpp @@ -34,8 +34,8 @@ public: gfx::IndexVector triangles; SegmentVector segments; - optional> vertexBuffer; - optional indexBuffer; + std::optional> vertexBuffer; + std::optional indexBuffer; std::map paintPropertyBinders; diff --git a/src/mbgl/renderer/buckets/hillshade_bucket.hpp b/src/mbgl/renderer/buckets/hillshade_bucket.hpp index 60f529916..5d5dfb72a 100644 --- a/src/mbgl/renderer/buckets/hillshade_bucket.hpp +++ b/src/mbgl/renderer/buckets/hillshade_bucket.hpp @@ -11,7 +11,6 @@ #include #include #include -#include namespace mbgl { @@ -28,8 +27,8 @@ public: void clear(); void setMask(TileMask&&); - optional dem; - optional texture; + std::optional dem; + std::optional texture; TileMask mask{ { 0, 0, 0 } }; @@ -49,8 +48,8 @@ public: gfx::IndexVector indices; SegmentVector segments; - optional> vertexBuffer; - optional indexBuffer; + std::optional> vertexBuffer; + std::optional indexBuffer; private: DEMData demdata; bool prepared = false; diff --git a/src/mbgl/renderer/buckets/line_bucket.cpp b/src/mbgl/renderer/buckets/line_bucket.cpp index 8c9559b4a..92e71f377 100644 --- a/src/mbgl/renderer/buckets/line_bucket.cpp +++ b/src/mbgl/renderer/buckets/line_bucket.cpp @@ -125,7 +125,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates, return; } - optional lineDistances; + std::optional lineDistances; const auto &props = feature.getProperties(); auto clip_start_it = props.find("mapbox_clip_start"); @@ -156,11 +156,11 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates, double distance = 0.0; bool startOfLine = true; - optional currentCoordinate; - optional prevCoordinate; - optional nextCoordinate; - optional> prevNormal; - optional> nextNormal; + std::optional currentCoordinate; + std::optional prevCoordinate; + std::optional nextCoordinate; + std::optional> prevNormal; + std::optional> nextNormal; // the last three vertices added e1 = e2 = e3 = -1; @@ -459,7 +459,7 @@ void LineBucket::addCurrentVertex(const GeometryCoordinate& currentCoordinate, bool round, std::size_t startVertex, std::vector& triangleStore, - optional lineDistances) { + std::optional lineDistances) { Point extrude = normal; double scaledDistance = lineDistances ? lineDistances->scaleToMaxLineDistance(distance) : distance; @@ -500,7 +500,7 @@ void LineBucket::addPieSliceVertex(const GeometryCoordinate& currentVertex, bool lineTurnsLeft, std::size_t startVertex, std::vector& triangleStore, - optional lineDistances) { + std::optional lineDistances) { Point flippedExtrude = extrude * (lineTurnsLeft ? -1.0 : 1.0); if (lineDistances) { distance = lineDistances->scaleToMaxLineDistance(distance); diff --git a/src/mbgl/renderer/buckets/line_bucket.hpp b/src/mbgl/renderer/buckets/line_bucket.hpp index 48092f41c..e3daa5177 100644 --- a/src/mbgl/renderer/buckets/line_bucket.hpp +++ b/src/mbgl/renderer/buckets/line_bucket.hpp @@ -46,8 +46,8 @@ public: gfx::IndexVector triangles; SegmentVector segments; - optional> vertexBuffer; - optional indexBuffer; + std::optional> vertexBuffer; + std::optional indexBuffer; std::map paintPropertyBinders; @@ -68,12 +68,12 @@ private: bool round, std::size_t startVertex, std::vector& triangleStore, - optional distances); + std::optional distances); void addPieSliceVertex(const GeometryCoordinate& currentVertex, double distance, const Point& extrude, bool lineTurnsLeft, std::size_t startVertex, std::vector& triangleStore, - optional distances); + std::optional distances); std::ptrdiff_t e1; std::ptrdiff_t e2; diff --git a/src/mbgl/renderer/buckets/raster_bucket.hpp b/src/mbgl/renderer/buckets/raster_bucket.hpp index 0fa3c4299..eeb00afb6 100644 --- a/src/mbgl/renderer/buckets/raster_bucket.hpp +++ b/src/mbgl/renderer/buckets/raster_bucket.hpp @@ -8,7 +8,8 @@ #include #include #include -#include + +#include namespace mbgl { @@ -26,7 +27,7 @@ public: void setMask(TileMask&&); std::shared_ptr image; - optional texture; + std::optional texture; TileMask mask{ { 0, 0, 0 } }; // Bucket specific vertices are used for Image Sources only @@ -35,8 +36,8 @@ public: gfx::IndexVector indices; SegmentVector segments; - optional> vertexBuffer; - optional indexBuffer; + std::optional> vertexBuffer; + std::optional indexBuffer; }; } // namespace mbgl diff --git a/src/mbgl/renderer/buckets/symbol_bucket.cpp b/src/mbgl/renderer/buckets/symbol_bucket.cpp index b8a135dc2..74d04ece7 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.cpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.cpp @@ -294,7 +294,7 @@ SymbolInstanceReferences SymbolBucket::getSortedSymbols(const float angle) const return result; } -SymbolInstanceReferences SymbolBucket::getSymbols(const optional& range) const { +SymbolInstanceReferences SymbolBucket::getSymbols(const std::optional& range) const { if (!range) return SymbolInstanceReferences(symbolInstances.begin(), symbolInstances.end()); assert(range->start < range->end); assert(range->end <= symbolInstances.size()); diff --git a/src/mbgl/renderer/buckets/symbol_bucket.hpp b/src/mbgl/renderer/buckets/symbol_bucket.hpp index c6a07dde1..9f091ac44 100644 --- a/src/mbgl/renderer/buckets/symbol_bucket.hpp +++ b/src/mbgl/renderer/buckets/symbol_bucket.hpp @@ -29,7 +29,7 @@ public: WritingModeType writingModes_, GeometryCoordinates line_, std::vector tileDistances_, - optional placedIconIndex_ = nullopt) + std::optional placedIconIndex_ = std::nullopt) : anchorPoint(anchorPoint_), segment(segment_), lowerSize(lowerSize_), @@ -56,11 +56,11 @@ public: uint32_t crossTileID = 0u; // The placedOrientation is only used when symbol layer's property is set to support // placement for orientation variants. - optional placedOrientation; + std::optional placedOrientation; float angle = 0; // Reference to placed icon, only applicable for text symbols. - optional placedIconIndex; + std::optional placedIconIndex; }; class SymbolBucket final : public Bucket { @@ -100,8 +100,8 @@ public: // Returns references to the `symbolInstances` items, sorted by viewport Y. SymbolInstanceReferences getSortedSymbols(float angle) const; // Returns references to the `symbolInstances` items, which belong to the `sortKeyRange` range; - // returns references to all the symbols if |sortKeyRange| is `nullopt`. - SymbolInstanceReferences getSymbols(const optional& sortKeyRange = nullopt) const; + // returns references to all the symbols if |sortKeyRange| is `std::nullopt`. + SymbolInstanceReferences getSymbols(const std::optional& sortKeyRange = std::nullopt) const; Immutable layout; const std::string bucketLeaderID; @@ -139,10 +139,10 @@ public: SegmentVector segments; std::vector placedSymbols; - optional> vertexBuffer; - optional>> dynamicVertexBuffer; - optional>> opacityVertexBuffer; - optional indexBuffer; + std::optional> vertexBuffer; + std::optional>> dynamicVertexBuffer; + std::optional>> opacityVertexBuffer; + std::optional indexBuffer; } text; std::unique_ptr iconSizeBinder; @@ -155,13 +155,13 @@ public: gfx::VertexVector> dynamicVertices; SegmentVector segments; - optional>> vertexBuffer; - optional>> dynamicVertexBuffer; + std::optional>> vertexBuffer; + std::optional>> dynamicVertexBuffer; }; struct CollisionBoxBuffer : public CollisionBuffer { gfx::IndexVector lines; - optional indexBuffer; + std::optional indexBuffer; }; std::unique_ptr iconCollisionBox; std::unique_ptr textCollisionBox; @@ -178,7 +178,7 @@ public: struct CollisionCircleBuffer : public CollisionBuffer { gfx::IndexVector triangles; - optional indexBuffer; + std::optional indexBuffer; }; std::unique_ptr iconCollisionCircle; std::unique_ptr textCollisionCircle; @@ -197,7 +197,7 @@ public: uint32_t bucketInstanceId; const bool allowVerticalPlacement; const std::vector placementModes; - mutable optional hasFormatSectionOverrides_; + mutable std::optional hasFormatSectionOverrides_; FeatureSortOrder featureSortOrder; }; diff --git a/src/mbgl/renderer/image_atlas.hpp b/src/mbgl/renderer/image_atlas.hpp index 690d6e34b..d8f021faf 100644 --- a/src/mbgl/renderer/image_atlas.hpp +++ b/src/mbgl/renderer/image_atlas.hpp @@ -6,6 +6,7 @@ #include #include +#include namespace mbgl { @@ -26,7 +27,7 @@ public: uint32_t version; style::ImageStretches stretchX; style::ImageStretches stretchY; - optional content; + std::optional content; std::array tl() const { return {{static_cast(paddedRect.x + padding), static_cast(paddedRect.y + padding)}}; diff --git a/src/mbgl/renderer/image_manager.cpp b/src/mbgl/renderer/image_manager.cpp index d862f5874..62df741e1 100644 --- a/src/mbgl/renderer/image_manager.cpp +++ b/src/mbgl/renderer/image_manager.cpp @@ -6,6 +6,8 @@ #include #include +#include + namespace mbgl { static ImageManagerObserver nullObserver; @@ -270,7 +272,9 @@ void ImageManager::notify(ImageRequestor& requestor, const ImageRequestPair& pai } void ImageManager::dumpDebugLogs() const { - Log::Info(Event::General, "ImageManager::loaded: %d", loaded); + std::ostringstream ss; + ss << "ImageManager::loaded: " << loaded; + Log::Info(Event::General, ss.str()); } ImageRequestor::ImageRequestor(ImageManager& imageManager_) : imageManager(imageManager_) { diff --git a/src/mbgl/renderer/layers/render_background_layer.cpp b/src/mbgl/renderer/layers/render_background_layer.cpp index 0a59a73f8..79afb8ac3 100644 --- a/src/mbgl/renderer/layers/render_background_layer.cpp +++ b/src/mbgl/renderer/layers/render_background_layer.cpp @@ -106,9 +106,9 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) { const auto& evaluated = static_cast(*evaluatedProperties).evaluated; const auto& crossfade = static_cast(*evaluatedProperties).crossfade; if (!evaluated.get().to.empty()) { - optional imagePosA = + std::optional imagePosA = parameters.patternAtlas.getPattern(evaluated.get().from.id()); - optional imagePosB = + std::optional imagePosB = parameters.patternAtlas.getPattern(evaluated.get().to.id()); if (!imagePosA || !imagePosB) @@ -152,10 +152,10 @@ void RenderBackgroundLayer::render(PaintParameters& parameters) { } } -optional RenderBackgroundLayer::getSolidBackground() const { +std::optional RenderBackgroundLayer::getSolidBackground() const { const auto& evaluated = getEvaluated(evaluatedProperties); if (!evaluated.get().from.empty() || evaluated.get() <= 0.0f) { - return nullopt; + return std::nullopt; } return { evaluated.get() * evaluated.get() }; diff --git a/src/mbgl/renderer/layers/render_background_layer.hpp b/src/mbgl/renderer/layers/render_background_layer.hpp index dab733172..9770534f0 100644 --- a/src/mbgl/renderer/layers/render_background_layer.hpp +++ b/src/mbgl/renderer/layers/render_background_layer.hpp @@ -17,7 +17,7 @@ private: void evaluate(const PropertyEvaluationParameters&) override; bool hasTransition() const override; bool hasCrossfade() const override; - optional getSolidBackground() const override; + std::optional getSolidBackground() const override; void render(PaintParameters&) override; void prepare(const LayerPrepareParameters&) override; diff --git a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp index 8f7fe7634..0703bb879 100644 --- a/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_extrusion_layer.cpp @@ -86,8 +86,8 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters) { const gfx::ColorMode& colorMode, const auto& tileBucket, const auto& uniformValues, - const optional& patternPositionA, - const optional& patternPositionB, + const std::optional& patternPositionA, + const std::optional& patternPositionB, const auto& textureBindings, const std::string& uniqueName) { const auto& paintPropertyBinders = tileBucket.paintPropertyBinders.at(getID()); @@ -180,8 +180,8 @@ void RenderFillExtrusionLayer::render(PaintParameters& parameters) { continue; } auto& bucket = static_cast(*renderData->bucket); - optional patternPosA = tile.getPattern(fillPatternValue.from.id()); - optional patternPosB = tile.getPattern(fillPatternValue.to.id()); + std::optional patternPosA = tile.getPattern(fillPatternValue.from.id()); + std::optional patternPosB = tile.getPattern(fillPatternValue.to.id()); draw( parameters.programs.getFillExtrusionLayerPrograms().fillExtrusionPattern, diff --git a/src/mbgl/renderer/layers/render_fill_layer.cpp b/src/mbgl/renderer/layers/render_fill_layer.cpp index f85154acf..50369aed8 100644 --- a/src/mbgl/renderer/layers/render_fill_layer.cpp +++ b/src/mbgl/renderer/layers/render_fill_layer.cpp @@ -170,8 +170,8 @@ void RenderFillLayer::render(PaintParameters& parameters) { const auto& crossfade = getCrossfade(renderData->layerProperties); const auto& fillPatternValue = evaluated.get().constantOr(Faded{"", ""}); - optional patternPosA = tile.getPattern(fillPatternValue.from.id()); - optional patternPosB = tile.getPattern(fillPatternValue.to.id()); + std::optional patternPosA = tile.getPattern(fillPatternValue.from.id()); + std::optional patternPosB = tile.getPattern(fillPatternValue.to.id()); auto draw = [&] (auto& programInstance, const auto& drawMode, diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.cpp b/src/mbgl/renderer/layers/render_heatmap_layer.cpp index 708ebf52a..4a5b35140 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.cpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.cpp @@ -206,7 +206,7 @@ void RenderHeatmapLayer::updateColorRamp() { } if (colorRampTexture) { - colorRampTexture = nullopt; + colorRampTexture = std::nullopt; } } diff --git a/src/mbgl/renderer/layers/render_heatmap_layer.hpp b/src/mbgl/renderer/layers/render_heatmap_layer.hpp index 7085a87c9..1d8b12b4a 100644 --- a/src/mbgl/renderer/layers/render_heatmap_layer.hpp +++ b/src/mbgl/renderer/layers/render_heatmap_layer.hpp @@ -6,7 +6,8 @@ #include #include #include -#include + +#include namespace mbgl { @@ -36,7 +37,7 @@ private: style::HeatmapPaintProperties::Unevaluated unevaluated; PremultipliedImage colorRamp; std::unique_ptr renderTexture; - optional colorRampTexture; + std::optional colorRampTexture; SegmentVector segments; }; diff --git a/src/mbgl/renderer/layers/render_line_layer.cpp b/src/mbgl/renderer/layers/render_line_layer.cpp index 43f2d0425..070d3ecf9 100644 --- a/src/mbgl/renderer/layers/render_line_layer.cpp +++ b/src/mbgl/renderer/layers/render_line_layer.cpp @@ -108,8 +108,8 @@ void RenderLineLayer::render(PaintParameters& parameters) { auto draw = [&](auto& programInstance, auto&& uniformValues, - const optional& patternPositionA, - const optional& patternPositionB, auto&& textureBindings) { + const std::optional& patternPositionA, + const std::optional& patternPositionB, auto&& textureBindings) { const auto& paintPropertyBinders = bucket.paintPropertyBinders.at(getID()); paintPropertyBinders.setPatternParameters(patternPositionA, patternPositionB, crossfade); @@ -168,8 +168,8 @@ void RenderLineLayer::render(PaintParameters& parameters) { const auto& linePatternValue = evaluated.get().constantOr(Faded{"", ""}); const Size& texsize = tile.getIconAtlasTexture().size; - optional posA = tile.getPattern(linePatternValue.from.id()); - optional posB = tile.getPattern(linePatternValue.to.id()); + std::optional posA = tile.getPattern(linePatternValue.from.id()); + std::optional posB = tile.getPattern(linePatternValue.to.id()); draw(parameters.programs.getLineLayerPrograms().linePattern, LinePatternProgram::layoutUniformValues( @@ -304,7 +304,7 @@ void RenderLineLayer::updateColorRamp() { } if (colorRampTexture) { - colorRampTexture = nullopt; + colorRampTexture = std::nullopt; } } diff --git a/src/mbgl/renderer/layers/render_line_layer.hpp b/src/mbgl/renderer/layers/render_line_layer.hpp index fb5d64fcb..a5eda223e 100644 --- a/src/mbgl/renderer/layers/render_line_layer.hpp +++ b/src/mbgl/renderer/layers/render_line_layer.hpp @@ -39,7 +39,7 @@ private: void updateColorRamp(); PremultipliedImage colorRamp; - optional colorRampTexture; + std::optional colorRampTexture; }; } // namespace mbgl diff --git a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp index a3f84908c..7276bbf4d 100644 --- a/src/mbgl/renderer/layers/render_location_indicator_layer.cpp +++ b/src/mbgl/renderer/layers/render_location_indicator_layer.cpp @@ -296,7 +296,7 @@ public: height = image->size.height; pixelRatio = img->get()->pixelRatio; } else { - sharedImage = nullopt; + sharedImage = std::nullopt; } } @@ -327,7 +327,7 @@ public: MBGL_CHECK_ERROR(glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, 16)); } detach(); - sharedImage = nullopt; + sharedImage = std::nullopt; } void initialize() { if (texId != 0) return; @@ -345,7 +345,7 @@ public: bool isValid() { return imageDirty || image; } GLuint texId = 0; const mbgl::PremultipliedImage* image = nullptr; - optional> sharedImage; + std::optional> sharedImage; bool imageDirty = false; size_t width = 0; size_t height = 0; diff --git a/src/mbgl/renderer/layers/render_symbol_layer.cpp b/src/mbgl/renderer/layers/render_symbol_layer.cpp index 2080b04c8..c74c71dcc 100644 --- a/src/mbgl/renderer/layers/render_symbol_layer.cpp +++ b/src/mbgl/renderer/layers/render_symbol_layer.cpp @@ -588,7 +588,7 @@ void RenderSymbolLayer::prepare(const LayerPrepareParameters& params) { auto featureIndex = static_cast(tile)->getFeatureIndex(); if (bucket->sortKeyRanges.empty()) { - placementData.push_back({*bucket, renderTile, featureIndex, baseImpl->source, nullopt}); + placementData.push_back({*bucket, renderTile, featureIndex, baseImpl->source, std::nullopt}); } else { for (const auto& sortKeyRange : bucket->sortKeyRanges) { BucketPlacementData layerData{*bucket, renderTile, featureIndex, baseImpl->source, sortKeyRange}; diff --git a/src/mbgl/renderer/paint_property_binder.hpp b/src/mbgl/renderer/paint_property_binder.hpp index 7d340bdc3..53f97e713 100644 --- a/src/mbgl/renderer/paint_property_binder.hpp +++ b/src/mbgl/renderer/paint_property_binder.hpp @@ -109,7 +109,7 @@ public: std::size_t length, std::size_t index, const ImagePositions&, - const optional&, + const std::optional&, const CanonicalTileID& canonical, const style::expression::Value&) = 0; @@ -118,8 +118,8 @@ public: virtual void updateVertexVector(std::size_t, std::size_t, const GeometryTileFeature&, const FeatureState&) = 0; virtual void upload(gfx::UploadPass&) = 0; - virtual void setPatternParameters(const optional&, const optional&, const CrossfadeParameters&) = 0; - virtual std::tuple>...> attributeBinding(const PossiblyEvaluatedType& currentValue) const = 0; + virtual void setPatternParameters(const std::optional&, const std::optional&, const CrossfadeParameters&) = 0; + virtual std::tuple>...> attributeBinding(const PossiblyEvaluatedType& currentValue) const = 0; virtual std::tuple...> interpolationFactor(float currentZoom) const = 0; virtual std::tuple...> uniformValue(const PossiblyEvaluatedType& currentValue) const = 0; @@ -139,14 +139,14 @@ public: std::size_t, std::size_t, const ImagePositions&, - const optional&, + const std::optional&, const CanonicalTileID&, const style::expression::Value&) override {} void updateVertexVector(std::size_t, std::size_t, const GeometryTileFeature&, const FeatureState&) override {} void upload(gfx::UploadPass&) override {} - void setPatternParameters(const optional&, const optional&, const CrossfadeParameters&) override {}; + void setPatternParameters(const std::optional&, const std::optional&, const CrossfadeParameters&) override {}; - std::tuple> attributeBinding(const PossiblyEvaluatedPropertyValue&) const override { + std::tuple> attributeBinding(const PossiblyEvaluatedPropertyValue&) const override { return {}; } @@ -173,13 +173,13 @@ public: std::size_t, std::size_t, const ImagePositions&, - const optional&, + const std::optional&, const CanonicalTileID&, const style::expression::Value&) override {} void updateVertexVector(std::size_t, std::size_t, const GeometryTileFeature&, const FeatureState&) override {} void upload(gfx::UploadPass&) override {} - void setPatternParameters(const optional& posA, const optional& posB, const CrossfadeParameters&) override { + void setPatternParameters(const std::optional& posA, const std::optional& posB, const CrossfadeParameters&) override { if (!posA || !posB) { return; } else { @@ -187,7 +187,7 @@ public: } } - std::tuple, optional> + std::tuple, std::optional> attributeBinding(const PossiblyEvaluatedPropertyValue>&) const override { return {}; } @@ -217,12 +217,12 @@ public: : expression(std::move(expression_)), defaultValue(std::move(defaultValue_)) { } - void setPatternParameters(const optional&, const optional&, const CrossfadeParameters&) override {}; + void setPatternParameters(const std::optional&, const std::optional&, const CrossfadeParameters&) override {}; void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, std::size_t index, const ImagePositions&, - const optional&, + const std::optional&, const CanonicalTileID& canonical, const style::expression::Value& formattedSection) override { using style::expression::EvaluationContext; @@ -235,7 +235,7 @@ public: for (std::size_t i = elements; i < length; ++i) { vertexVector.emplace_back(BaseVertex { value }); } - optional idStr = featureIDtoString(feature.getID()); + std::optional idStr = featureIDtoString(feature.getID()); if (idStr) { featureMap[*idStr].emplace_back(FeatureVertexRange{index, elements, length}); } @@ -274,11 +274,11 @@ public: vertexBuffer = uploadPass.createVertexBuffer(std::move(vertexVector)); } - std::tuple> attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { + std::tuple> attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { return {}; } else { - return std::tuple>{ + return std::tuple>{ gfx::attributeBinding(*vertexBuffer) }; } @@ -301,7 +301,7 @@ private: style::PropertyExpression expression; T defaultValue; gfx::VertexVector vertexVector; - optional> vertexBuffer; + std::optional> vertexBuffer; FeatureVertexRangeMap featureMap; }; @@ -318,12 +318,12 @@ public: defaultValue(std::move(defaultValue_)), zoomRange({zoom, zoom + 1}) { } - void setPatternParameters(const optional&, const optional&, const CrossfadeParameters&) override {}; + void setPatternParameters(const std::optional&, const std::optional&, const CrossfadeParameters&) override {}; void populateVertexVector(const GeometryTileFeature& feature, std::size_t length, std::size_t index, const ImagePositions&, - const optional&, + const std::optional&, const CanonicalTileID& canonical, const style::expression::Value& formattedSection) override { using style::expression::EvaluationContext; @@ -346,7 +346,7 @@ public: for (std::size_t i = elements; i < length; ++i) { vertexVector.emplace_back(Vertex { value }); } - optional idStr = featureIDtoString(feature.getID()); + std::optional idStr = featureIDtoString(feature.getID()); if (idStr) { featureMap[*idStr].emplace_back(FeatureVertexRange{index, elements, length}); } @@ -389,11 +389,11 @@ public: vertexBuffer = uploadPass.createVertexBuffer(std::move(vertexVector)); } - std::tuple> attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { + std::tuple> attributeBinding(const PossiblyEvaluatedPropertyValue& currentValue) const override { if (currentValue.isConstant()) { return {}; } else { - return std::tuple>{ + return std::tuple>{ gfx::attributeBinding(*vertexBuffer) }; } @@ -420,7 +420,7 @@ private: T defaultValue; Range zoomRange; gfx::VertexVector vertexVector; - optional> vertexBuffer; + std::optional> vertexBuffer; FeatureVertexRangeMap featureMap; }; @@ -442,7 +442,7 @@ public: zoomRange({zoom, zoom + 1}) { } - void setPatternParameters(const optional&, const optional&, const CrossfadeParameters& crossfade_) override { + void setPatternParameters(const std::optional&, const std::optional&, const CrossfadeParameters& crossfade_) override { crossfade = crossfade_; }; @@ -450,7 +450,7 @@ public: std::size_t length, std::size_t /* index */, const ImagePositions& patternPositions, - const optional& patternDependencies, + const std::optional& patternDependencies, const CanonicalTileID&, const style::expression::Value&) override { if (!patternDependencies || patternDependencies->mid.empty()) { @@ -494,20 +494,20 @@ public: } } - std::tuple, optional> attributeBinding(const PossiblyEvaluatedPropertyValue>& currentValue) const override { + std::tuple, std::optional> attributeBinding(const PossiblyEvaluatedPropertyValue>& currentValue) const override { if (currentValue.isConstant()) { return {}; } else { if (patternToVertexBuffer) { assert(zoomInVertexBuffer); assert(zoomOutVertexBuffer); - return std::tuple, optional>{ + return std::tuple, std::optional>{ gfx::attributeBinding(*patternToVertexBuffer), gfx::attributeBinding(crossfade.fromScale == 2 ? *zoomInVertexBuffer : *zoomOutVertexBuffer) }; } - return std::tuple, optional>{{}, {}}; + return std::tuple, std::optional>{std::nullopt, std::nullopt}; } } @@ -527,9 +527,9 @@ private: gfx::VertexVector patternToVertexVector; gfx::VertexVector zoomInVertexVector; gfx::VertexVector zoomOutVertexVector; - optional> patternToVertexBuffer; - optional> zoomInVertexBuffer; - optional> zoomOutVertexBuffer; + std::optional> patternToVertexBuffer; + std::optional> zoomInVertexBuffer; + std::optional> zoomOutVertexBuffer; CrossfadeParameters crossfade; }; @@ -626,7 +626,7 @@ public: std::size_t length, std::size_t index, const ImagePositions& patternPositions, - const optional& patternDependencies, + const std::optional& patternDependencies, const CanonicalTileID& canonical, const style::expression::Value& formattedSection = {}) { util::ignore({(binders.template get()->populateVertexVector( @@ -639,7 +639,7 @@ public: util::ignore({(binders.template get()->updateVertexVectors(states, layer, imagePositions), 0)...}); } - void setPatternParameters(const optional& posA, const optional& posB, const CrossfadeParameters& crossfade) const { + void setPatternParameters(const std::optional& posA, const std::optional& posB, const CrossfadeParameters& crossfade) const { util::ignore({ (binders.template get()->setPatternParameters(posA, posB, crossfade), 0)... }); diff --git a/src/mbgl/renderer/paint_property_statistics.hpp b/src/mbgl/renderer/paint_property_statistics.hpp index 017aa5ac3..2533c4c4f 100644 --- a/src/mbgl/renderer/paint_property_statistics.hpp +++ b/src/mbgl/renderer/paint_property_statistics.hpp @@ -1,7 +1,6 @@ #pragma once -#include - +#include #include namespace mbgl { @@ -9,14 +8,14 @@ namespace mbgl { template class PaintPropertyStatistics { public: - optional max() const { return {}; } + std::optional max() const { return std::nullopt; } void add(const T&) {} }; template <> class PaintPropertyStatistics { public: - optional max() const { + std::optional max() const { return _max; } @@ -25,7 +24,7 @@ public: } private: - optional _max; + std::optional _max; }; } // namespace mbgl diff --git a/src/mbgl/renderer/pattern_atlas.cpp b/src/mbgl/renderer/pattern_atlas.cpp index 81223b5ce..0c2c7a8b3 100644 --- a/src/mbgl/renderer/pattern_atlas.cpp +++ b/src/mbgl/renderer/pattern_atlas.cpp @@ -25,24 +25,24 @@ PatternAtlas::PatternAtlas() PatternAtlas::~PatternAtlas() = default; -optional PatternAtlas::getPattern(const std::string& id) const { +std::optional PatternAtlas::getPattern(const std::string& id) const { auto it = patterns.find(id); if (it != patterns.end()) { return it->second.position; } - return nullopt; + return std::nullopt; } -optional PatternAtlas::addPattern(const style::Image::Impl& image) { +std::optional PatternAtlas::addPattern(const style::Image::Impl& image) { if (patterns.find(image.id) != patterns.end()) { - return nullopt; + return std::nullopt; } const uint16_t width = image.image.size.width + padding * 2; const uint16_t height = image.image.size.height + padding * 2; mapbox::Bin* bin = shelfPack.packOne(-1, width, height); if (!bin) { - return nullopt; + return std::nullopt; } atlasImage.resize(getPixelSize()); diff --git a/src/mbgl/renderer/pattern_atlas.hpp b/src/mbgl/renderer/pattern_atlas.hpp index 813c8f024..14c4432c3 100644 --- a/src/mbgl/renderer/pattern_atlas.hpp +++ b/src/mbgl/renderer/pattern_atlas.hpp @@ -4,10 +4,10 @@ #include #include #include -#include #include #include +#include namespace mbgl { @@ -25,8 +25,8 @@ public: PatternAtlas& operator=(const PatternAtlas&) = delete; ~PatternAtlas(); - optional getPattern(const std::string&) const; - optional addPattern(const style::Image::Impl&); + std::optional getPattern(const std::string&) const; + std::optional addPattern(const style::Image::Impl&); void removePattern(const std::string&); gfx::TextureBinding textureBinding() const; @@ -48,7 +48,7 @@ private: mapbox::ShelfPack shelfPack; std::unordered_map patterns; PremultipliedImage atlasImage; - mbgl::optional atlasTexture; + std::optional atlasTexture; bool dirty = true; }; diff --git a/src/mbgl/renderer/possibly_evaluated_property_value.hpp b/src/mbgl/renderer/possibly_evaluated_property_value.hpp index c893db27d..cf706ba3b 100644 --- a/src/mbgl/renderer/possibly_evaluated_property_value.hpp +++ b/src/mbgl/renderer/possibly_evaluated_property_value.hpp @@ -27,10 +27,10 @@ public: return value.template is(); } - optional constant() const { + std::optional constant() const { return value.match( - [&] (const T& t) { return optional(t); }, - [&] (const auto&) { return optional(); }); + [&] (const T& t) { return std::optional(t); }, + [&] (const auto&) { return std::optional(); }); } T constantOr(const T& t) const { @@ -87,10 +87,10 @@ public: return value.template is>(); } - optional> constant() const { + std::optional> constant() const { return value.match( - [&] (const Faded& t) { return optional>(t); }, - [&] (const auto&) { return optional>(); }); + [&] (const Faded& t) { return std::optional>(t); }, + [&] (const auto&) { return std::optional>(); }); } Faded constantOr(const Faded& t) const { diff --git a/src/mbgl/renderer/render_layer.cpp b/src/mbgl/renderer/render_layer.cpp index 3d3f76025..27289f4d6 100644 --- a/src/mbgl/renderer/render_layer.cpp +++ b/src/mbgl/renderer/render_layer.cpp @@ -52,8 +52,8 @@ void RenderLayer::prepare(const LayerPrepareParameters& params) { addRenderPassesFromTiles(); } -optional RenderLayer::getSolidBackground() const { - return nullopt; +std::optional RenderLayer::getSolidBackground() const { + return std::nullopt; } void RenderLayer::markContextDestroyed() { @@ -69,20 +69,18 @@ void RenderLayer::checkRenderability(const PaintParameters& parameters, if (activeBindingCount > parameters.context.maximumVertexBindingCount) { Log::Error(Event::OpenGL, - "The layer '%s' uses more data-driven properties than the current device " + "The layer '" + getID() + "' uses more data-driven properties than the current device " "supports, and will have rendering errors. To ensure compatibility with this " - "device, use %d fewer data driven properties in this layer.", - getID().c_str(), - activeBindingCount - gfx::Context::minimumRequiredVertexBindingCount); + "device, use " + std::to_string(activeBindingCount - gfx::Context::minimumRequiredVertexBindingCount) + + " fewer data driven properties in this layer."); hasRenderFailures = true; } else if (activeBindingCount > gfx::Context::minimumRequiredVertexBindingCount) { Log::Warning(Event::OpenGL, - "The layer '%s' uses more data-driven properties than some devices may support. " + "The layer '" + getID() + "' uses more data-driven properties than some devices may support. " "Though it will render correctly on this device, it may have rendering errors " - "on other devices. To ensure compatibility with all devices, use %d fewer " - "data-driven properties in this layer.", - getID().c_str(), - activeBindingCount - gfx::Context::minimumRequiredVertexBindingCount); + "on other devices. To ensure compatibility with all devices, use " + + std::to_string(activeBindingCount - gfx::Context::minimumRequiredVertexBindingCount) + "fewer " + "data-driven properties in this layer."); hasRenderFailures = true; } } diff --git a/src/mbgl/renderer/render_layer.hpp b/src/mbgl/renderer/render_layer.hpp index 553730de2..b4ea90e27 100644 --- a/src/mbgl/renderer/render_layer.hpp +++ b/src/mbgl/renderer/render_layer.hpp @@ -43,7 +43,7 @@ public: std::reference_wrapper tile; std::shared_ptr featureIndex; std::string sourceId; - optional sortKeyRange; + std::optional sortKeyRange; }; using LayerPlacementData = std::list; @@ -121,7 +121,7 @@ public: virtual void markContextDestroyed(); // TODO: Only for background layers. - virtual optional getSolidBackground() const; + virtual std::optional getSolidBackground() const; protected: // Checks whether the current hardware can render this layer. If it can't, we'll show a warning diff --git a/src/mbgl/renderer/render_orchestrator.cpp b/src/mbgl/renderer/render_orchestrator.cpp index 66881efed..4a2b018bd 100644 --- a/src/mbgl/renderer/render_orchestrator.cpp +++ b/src/mbgl/renderer/render_orchestrator.cpp @@ -103,7 +103,7 @@ public: } // namespace -RenderOrchestrator::RenderOrchestrator(bool backgroundLayerAsColor_, const optional& localFontFamily_) +RenderOrchestrator::RenderOrchestrator(bool backgroundLayerAsColor_, const std::optional& localFontFamily_) : observer(&nullObserver()), glyphManager(std::make_unique(std::make_unique(localFontFamily_))), imageManager(std::make_unique()), @@ -395,7 +395,7 @@ std::unique_ptr RenderOrchestrator::createRenderTree( } if (isMapModeContinuous) { - optional placementUpdatePeriodOverride; + std::optional placementUpdatePeriodOverride; if (symbolBucketsAdded && !tiltedView) { // If the view is not tilted, we want *the new* symbols to show up faster, however simple setting // `placementChanged` to `true` would initiate placement too often as new buckets usually come from several @@ -403,7 +403,7 @@ std::unique_ptr RenderOrchestrator::createRenderTree( // coalesce buckets updates from several tiles. On contrary, with the tilted view it's more important to // make placement rarely for performance reasons and as the new symbols are normally "far away" and the user // is not that interested to see them ASAP. - placementUpdatePeriodOverride = optional(Milliseconds(30)); + placementUpdatePeriodOverride = std::optional(Milliseconds(30)); } renderTreeParameters->placementChanged = !placementController.placementIsRecent( @@ -597,14 +597,14 @@ FeatureExtensionValue RenderOrchestrator::queryFeatureExtensions(const std::stri const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args) const { + const std::optional>& args) const { if (RenderSource* renderSource = getRenderSource(sourceID)) { return renderSource->queryFeatureExtensions(feature, extension, extensionField, args); } return {}; } -void RenderOrchestrator::setFeatureState(const std::string& sourceID, const optional& sourceLayerID, +void RenderOrchestrator::setFeatureState(const std::string& sourceID, const std::optional& sourceLayerID, const std::string& featureID, const FeatureState& state) { if (RenderSource* renderSource = getRenderSource(sourceID)) { renderSource->setFeatureState(sourceLayerID, featureID, state); @@ -612,16 +612,16 @@ void RenderOrchestrator::setFeatureState(const std::string& sourceID, const opti } void RenderOrchestrator::getFeatureState(FeatureState& state, const std::string& sourceID, - const optional& sourceLayerID, + const std::optional& sourceLayerID, const std::string& featureID) const { if (RenderSource* renderSource = getRenderSource(sourceID)) { renderSource->getFeatureState(state, sourceLayerID, featureID); } } -void RenderOrchestrator::removeFeatureState(const std::string& sourceID, const optional& sourceLayerID, - const optional& featureID, - const optional& stateKey) { +void RenderOrchestrator::removeFeatureState(const std::string& sourceID, const std::optional& sourceLayerID, + const std::optional& featureID, + const std::optional& stateKey) { if (RenderSource* renderSource = getRenderSource(sourceID)) { renderSource->removeFeatureState(sourceLayerID, featureID, stateKey); } @@ -719,14 +719,13 @@ void RenderOrchestrator::clearData() { } void RenderOrchestrator::onGlyphsError(const FontStack& fontStack, const GlyphRange& glyphRange, std::exception_ptr error) { - Log::Error(Event::Style, "Failed to load glyph range %d-%d for font stack %s: %s", - glyphRange.first, glyphRange.second, fontStackToString(fontStack).c_str(), util::toString(error).c_str()); + Log::Error(Event::Style, "Failed to load glyph range " + std::to_string(glyphRange.first) + "-" + std::to_string(glyphRange.second) + + " for font stack " + fontStackToString(fontStack) + ": " + util::toString(error)); observer->onResourceError(error); } void RenderOrchestrator::onTileError(RenderSource& source, const OverscaledTileID& tileID, std::exception_ptr error) { - Log::Error(Event::Style, "Failed to load tile %s for source %s: %s", - util::toString(tileID).c_str(), source.baseImpl->id.c_str(), util::toString(error).c_str()); + Log::Error(Event::Style, "Failed to load tile " + util::toString(tileID) + " for source " + source.baseImpl->id + ": " + util::toString(error)); observer->onResourceError(error); } diff --git a/src/mbgl/renderer/render_orchestrator.hpp b/src/mbgl/renderer/render_orchestrator.hpp index 5d698f553..95887e6ff 100644 --- a/src/mbgl/renderer/render_orchestrator.hpp +++ b/src/mbgl/renderer/render_orchestrator.hpp @@ -40,7 +40,7 @@ class RenderOrchestrator final : public GlyphManagerObserver, public ImageManagerObserver, public RenderSourceObserver { public: - RenderOrchestrator(bool backgroundLayerAsColor_, const optional& localFontFamily_); + RenderOrchestrator(bool backgroundLayerAsColor_, const std::optional& localFontFamily_); ~RenderOrchestrator() override; void markContextLost() { @@ -59,16 +59,16 @@ public: const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args) const; + const std::optional>& args) const; - void setFeatureState(const std::string& sourceID, const optional& layerID, + void setFeatureState(const std::string& sourceID, const std::optional& layerID, const std::string& featureID, const FeatureState& state); - void getFeatureState(FeatureState& state, const std::string& sourceID, const optional& layerID, + void getFeatureState(FeatureState& state, const std::string& sourceID, const std::optional& layerID, const std::string& featureID) const; - void removeFeatureState(const std::string& sourceID, const optional& sourceLayerID, - const optional& featureID, const optional& stateKey); + void removeFeatureState(const std::string& sourceID, const std::optional& sourceLayerID, + const std::optional& featureID, const std::optional& stateKey); void reduceMemoryUse(); void dumpDebugLogs(); diff --git a/src/mbgl/renderer/render_source.hpp b/src/mbgl/renderer/render_source.hpp index 8e09b4693..4ed1253f9 100644 --- a/src/mbgl/renderer/render_source.hpp +++ b/src/mbgl/renderer/render_source.hpp @@ -89,16 +89,16 @@ public: queryFeatureExtensions(const Feature&, const std::string&, const std::string&, - const optional>&) const { + const std::optional>&) const { return {}; } - virtual void setFeatureState(const optional&, const std::string&, const FeatureState&) {} + virtual void setFeatureState(const std::optional&, const std::string&, const FeatureState&) {} - virtual void getFeatureState(FeatureState&, const optional&, const std::string&) const {} + virtual void getFeatureState(FeatureState&, const std::optional&, const std::string&) const {} - virtual void removeFeatureState(const optional&, const optional&, - const optional&) {} + virtual void removeFeatureState(const std::optional&, const std::optional&, + const std::optional&) {} virtual void reduceMemoryUse() = 0; diff --git a/src/mbgl/renderer/render_static_data.hpp b/src/mbgl/renderer/render_static_data.hpp index 22b29387d..28296dada 100644 --- a/src/mbgl/renderer/render_static_data.hpp +++ b/src/mbgl/renderer/render_static_data.hpp @@ -7,9 +7,9 @@ #include #include #include -#include #include +#include namespace mbgl { namespace gfx { @@ -23,19 +23,19 @@ public: void upload(gfx::UploadPass&); - optional>> tileVertexBuffer; - optional> rasterVertexBuffer; - optional> heatmapTextureVertexBuffer; + std::optional>> tileVertexBuffer; + std::optional> rasterVertexBuffer; + std::optional> heatmapTextureVertexBuffer; - optional quadTriangleIndexBuffer; - optional tileBorderIndexBuffer; + std::optional quadTriangleIndexBuffer; + std::optional tileBorderIndexBuffer; static SegmentVector tileTriangleSegments(); static SegmentVector tileBorderSegments(); static SegmentVector rasterSegments(); static SegmentVector heatmapTextureSegments(); - optional> depthRenderbuffer; + std::optional> depthRenderbuffer; bool has3D = false; bool uploaded = false; Size backendSize; diff --git a/src/mbgl/renderer/render_tile.cpp b/src/mbgl/renderer/render_tile.cpp index 01b364bf4..dfb65214a 100644 --- a/src/mbgl/renderer/render_tile.cpp +++ b/src/mbgl/renderer/render_tile.cpp @@ -74,7 +74,7 @@ const LayerRenderData* RenderTile::getLayerRenderData(const style::Layer::Impl& return renderData->getLayerRenderData(impl); } -optional RenderTile::getPattern(const std::string& pattern) const { +std::optional RenderTile::getPattern(const std::string& pattern) const { assert(renderData); return renderData->getPattern(pattern); } diff --git a/src/mbgl/renderer/render_tile.hpp b/src/mbgl/renderer/render_tile.hpp index f2ea1a22c..9f4dc0db2 100644 --- a/src/mbgl/renderer/render_tile.hpp +++ b/src/mbgl/renderer/render_tile.hpp @@ -54,7 +54,7 @@ public: Bucket* getBucket(const style::Layer::Impl&) const; const LayerRenderData* getLayerRenderData(const style::Layer::Impl&) const; - optional getPattern(const std::string& pattern) const; + std::optional getPattern(const std::string& pattern) const; const gfx::Texture& getGlyphAtlasTexture() const; const gfx::Texture& getIconAtlasTexture() const; diff --git a/src/mbgl/renderer/renderer.cpp b/src/mbgl/renderer/renderer.cpp index ac9fac899..5a2110b32 100644 --- a/src/mbgl/renderer/renderer.cpp +++ b/src/mbgl/renderer/renderer.cpp @@ -8,7 +8,7 @@ namespace mbgl { -Renderer::Renderer(gfx::RendererBackend& backend, float pixelRatio_, const optional& localFontFamily_) +Renderer::Renderer(gfx::RendererBackend& backend, float pixelRatio_, const std::optional& localFontFamily_) : impl(std::make_unique(backend, pixelRatio_, localFontFamily_)) {} Renderer::~Renderer() { @@ -102,22 +102,22 @@ FeatureExtensionValue Renderer::queryFeatureExtensions(const std::string& source const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args) const { + const std::optional>& args) const { return impl->orchestrator.queryFeatureExtensions(sourceID, feature, extension, extensionField, args); } -void Renderer::setFeatureState(const std::string& sourceID, const optional& sourceLayerID, +void Renderer::setFeatureState(const std::string& sourceID, const std::optional& sourceLayerID, const std::string& featureID, const FeatureState& state) { impl->orchestrator.setFeatureState(sourceID, sourceLayerID, featureID, state); } void Renderer::getFeatureState(FeatureState& state, const std::string& sourceID, - const optional& sourceLayerID, const std::string& featureID) const { + const std::optional& sourceLayerID, const std::string& featureID) const { impl->orchestrator.getFeatureState(state, sourceID, sourceLayerID, featureID); } -void Renderer::removeFeatureState(const std::string& sourceID, const optional& sourceLayerID, - const optional& featureID, const optional& stateKey) { +void Renderer::removeFeatureState(const std::string& sourceID, const std::optional& sourceLayerID, + const std::optional& featureID, const std::optional& stateKey) { impl->orchestrator.removeFeatureState(sourceID, sourceLayerID, featureID, stateKey); } diff --git a/src/mbgl/renderer/renderer_impl.cpp b/src/mbgl/renderer/renderer_impl.cpp index dd850d9bf..25a8020c8 100644 --- a/src/mbgl/renderer/renderer_impl.cpp +++ b/src/mbgl/renderer/renderer_impl.cpp @@ -24,7 +24,7 @@ static RendererObserver& nullObserver() { return observer; } -Renderer::Impl::Impl(gfx::RendererBackend& backend_, float pixelRatio_, const optional& localFontFamily_) +Renderer::Impl::Impl(gfx::RendererBackend& backend_, float pixelRatio_, const std::optional& localFontFamily_) : orchestrator(!backend_.contextIsShared(), localFontFamily_), backend(backend_), observer(&nullObserver()), @@ -123,13 +123,13 @@ void Renderer::Impl::render(const RenderTree& renderTree) { // Renders the backdrop of the OpenGL view. This also paints in areas where we don't have any // tiles whatsoever. { - optional color; + std::optional color; if (parameters.debugOptions & MapDebugOptions::Overdraw) { color = Color::black(); } else if (!backend.contextIsShared()) { color = renderTreeParameters.backgroundColor; } - parameters.renderPass = parameters.encoder->createRenderPass("main buffer", { parameters.backend.getDefaultRenderable(), color, 1, 0 }); + parameters.renderPass = parameters.encoder->createRenderPass("main buffer", { parameters.backend.getDefaultRenderable(), color, 1.0f, 0 }); } // Actually render the layers diff --git a/src/mbgl/renderer/renderer_impl.hpp b/src/mbgl/renderer/renderer_impl.hpp index 53c5b8d4d..2a058c605 100644 --- a/src/mbgl/renderer/renderer_impl.hpp +++ b/src/mbgl/renderer/renderer_impl.hpp @@ -17,7 +17,7 @@ class RendererBackend; class Renderer::Impl { public: - Impl(gfx::RendererBackend&, float pixelRatio_, const optional& localFontFamily_); + Impl(gfx::RendererBackend&, float pixelRatio_, const std::optional& localFontFamily_); ~Impl(); private: diff --git a/src/mbgl/renderer/source_state.cpp b/src/mbgl/renderer/source_state.cpp index d057c211b..1c734225a 100644 --- a/src/mbgl/renderer/source_state.cpp +++ b/src/mbgl/renderer/source_state.cpp @@ -5,7 +5,7 @@ namespace mbgl { -void SourceFeatureState::updateState(const optional& sourceLayerID, const std::string& featureID, +void SourceFeatureState::updateState(const std::optional& sourceLayerID, const std::string& featureID, const FeatureState& newState) { std::string sourceLayer = sourceLayerID.value_or(std::string()); for (const auto& state : newState) { @@ -15,7 +15,7 @@ void SourceFeatureState::updateState(const optional& sourceLayerID, } } -void SourceFeatureState::getState(FeatureState& result, const optional& sourceLayerID, +void SourceFeatureState::getState(FeatureState& result, const std::optional& sourceLayerID, const std::string& featureID) const { std::string sourceLayer = sourceLayerID.value_or(std::string()); FeatureState current; @@ -101,8 +101,8 @@ void SourceFeatureState::coalesceChanges(std::vector& tiles) { } } -void SourceFeatureState::removeState(const optional& sourceLayerID, const optional& featureID, - const optional& stateKey) { +void SourceFeatureState::removeState(const std::optional& sourceLayerID, const std::optional& featureID, + const std::optional& stateKey) { std::string sourceLayer = sourceLayerID.value_or(std::string()); bool sourceLayerDeleted = (deletedStates.count(sourceLayer) > 0) && deletedStates[sourceLayer].empty(); diff --git a/src/mbgl/renderer/source_state.hpp b/src/mbgl/renderer/source_state.hpp index 721730263..ff775fa2f 100644 --- a/src/mbgl/renderer/source_state.hpp +++ b/src/mbgl/renderer/source_state.hpp @@ -12,11 +12,11 @@ public: SourceFeatureState() = default; ~SourceFeatureState() = default; - void updateState(const optional& sourceLayerID, const std::string& featureID, + void updateState(const std::optional& sourceLayerID, const std::string& featureID, const FeatureState& newState); - void getState(FeatureState& result, const optional& sourceLayerID, const std::string& featureID) const; - void removeState(const optional& sourceLayerID, const optional& featureID, - const optional& stateKey); + void getState(FeatureState& result, const std::optional& sourceLayerID, const std::string& featureID) const; + void removeState(const std::optional& sourceLayerID, const std::optional& featureID, + const std::optional& stateKey); void coalesceChanges(std::vector& tiles); diff --git a/src/mbgl/renderer/sources/render_geojson_source.cpp b/src/mbgl/renderer/sources/render_geojson_source.cpp index 8e87881eb..e0cb9f3b4 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.cpp +++ b/src/mbgl/renderer/sources/render_geojson_source.cpp @@ -13,29 +13,29 @@ using namespace style; namespace { template -optional getProperty(const C& cont, const typename C::key_type& name) { +std::optional getProperty(const C& cont, const typename C::key_type& name) { const auto it = cont.find(name); if (it == cont.end() || !(it->second.template is())) { - return nullopt; + return std::nullopt; } return it->second.template get(); } using FeatureExtensionGetterPtr = FeatureExtensionValue (*)(std::shared_ptr, std::uint32_t, - const optional>&); + const std::optional>&); // NOLINTNEXTLINE(performance-unnecessary-value-param) FeatureExtensionValue getChildren(std::shared_ptr clusterData, std::uint32_t clusterID, - const optional>&) { + const std::optional>&) { return clusterData->getChildren(clusterID); } // NOLINTNEXTLINE(performance-unnecessary-value-param) FeatureExtensionValue getLeaves(std::shared_ptr clusterData, std::uint32_t clusterID, - const optional>& args) { + const std::optional>& args) { if (args) { const auto limit = getProperty(*args, "limit"); const auto offset = getProperty(*args, "offset"); @@ -56,7 +56,7 @@ FeatureExtensionValue getLeaves(std::shared_ptr clusterData, // NOLINTNEXTLINE(performance-unnecessary-value-param) FeatureExtensionValue getClusterExpansionZoom(std::shared_ptr clusterData, std::uint32_t clusterID, - const optional>&) { + const std::optional>&) { return Value{static_cast(clusterData->getClusterExpansionZoom(clusterID))}; } @@ -113,7 +113,7 @@ void RenderGeoJSONSource::update(Immutable baseImpl_, *baseImpl, util::tileSize_I, impl().getZoomRange(), - optional{}, + std::optional{}, [&, data_](const OverscaledTileID& tileID) { return std::make_unique(tileID, impl().id, parameters, data_); }); @@ -123,7 +123,7 @@ mapbox::util::variant RenderGeoJSONSource::queryFeatureExtensions(const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args) const { + const std::optional>& args) const { if (extension != "supercluster") { return {}; } diff --git a/src/mbgl/renderer/sources/render_geojson_source.hpp b/src/mbgl/renderer/sources/render_geojson_source.hpp index 8e923362b..8d3061444 100644 --- a/src/mbgl/renderer/sources/render_geojson_source.hpp +++ b/src/mbgl/renderer/sources/render_geojson_source.hpp @@ -24,7 +24,7 @@ public: queryFeatureExtensions(const Feature& feature, const std::string& extension, const std::string& extensionField, - const optional>& args) const override; + const std::optional>& args) const override; private: const style::GeoJSONSource::Impl& impl() const; diff --git a/src/mbgl/renderer/sources/render_image_source.cpp b/src/mbgl/renderer/sources/render_image_source.cpp index cb3ab3908..38db2569a 100644 --- a/src/mbgl/renderer/sources/render_image_source.cpp +++ b/src/mbgl/renderer/sources/render_image_source.cpp @@ -228,8 +228,8 @@ void RenderImageSource::update(Immutable baseImpl_, } void RenderImageSource::dumpDebugLogs() const { - Log::Info(Event::General, "RenderImageSource::id: %s", impl().id.c_str()); - Log::Info(Event::General, "RenderImageSource::loaded: %s", isLoaded() ? "yes" : "no"); + Log::Info(Event::General, "RenderImageSource::id: " + impl().id); + Log::Info(Event::General, "RenderImageSource::loaded: " + std::string(isLoaded() ? "yes" : "no")); } } // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_image_source.hpp b/src/mbgl/renderer/sources/render_image_source.hpp index 1b3afd6dd..41b6e02fb 100644 --- a/src/mbgl/renderer/sources/render_image_source.hpp +++ b/src/mbgl/renderer/sources/render_image_source.hpp @@ -27,7 +27,7 @@ private: bool hasRenderPass(RenderPass) const override { return false; } const std::string& getName() const override { return name; } std::string name; - mutable optional debugTexture; + mutable std::optional debugTexture; }; class RenderImageSource final : public RenderSource { diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.cpp b/src/mbgl/renderer/sources/render_raster_dem_source.cpp index 7b0db8a87..fd2a3e9f1 100644 --- a/src/mbgl/renderer/sources/render_raster_dem_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_dem_source.cpp @@ -18,7 +18,7 @@ const style::RasterSource::Impl& RenderRasterDEMSource::impl() const { return static_cast(*baseImpl); } -const optional& RenderRasterDEMSource::getTileset() const { +const std::optional& RenderRasterDEMSource::getTileset() const { return impl().tileset; } diff --git a/src/mbgl/renderer/sources/render_raster_dem_source.hpp b/src/mbgl/renderer/sources/render_raster_dem_source.hpp index 72a3779e9..6e6d25c67 100644 --- a/src/mbgl/renderer/sources/render_raster_dem_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_dem_source.hpp @@ -26,7 +26,7 @@ private: bool needsRendering, bool needsRelayout, const TileParameters&) override; - const optional& getTileset() const override; + const std::optional& getTileset() const override; const style::RasterSource::Impl& impl() const; diff --git a/src/mbgl/renderer/sources/render_raster_source.cpp b/src/mbgl/renderer/sources/render_raster_source.cpp index f1a4a6128..6f491d696 100644 --- a/src/mbgl/renderer/sources/render_raster_source.cpp +++ b/src/mbgl/renderer/sources/render_raster_source.cpp @@ -16,7 +16,7 @@ inline const style::RasterSource::Impl& RenderRasterSource::impl() const { return static_cast(*baseImpl); } -const optional& RenderRasterSource::getTileset() const { +const std::optional& RenderRasterSource::getTileset() const { return impl().tileset; } diff --git a/src/mbgl/renderer/sources/render_raster_source.hpp b/src/mbgl/renderer/sources/render_raster_source.hpp index 0760b7fa2..7675e2644 100644 --- a/src/mbgl/renderer/sources/render_raster_source.hpp +++ b/src/mbgl/renderer/sources/render_raster_source.hpp @@ -28,7 +28,7 @@ private: bool needsRendering, bool needsRelayout, const TileParameters&) override; - const optional& getTileset() const override; + const std::optional& getTileset() const override; const style::RasterSource::Impl& impl() const; }; diff --git a/src/mbgl/renderer/sources/render_tile_source.cpp b/src/mbgl/renderer/sources/render_tile_source.cpp index af488d864..6d24f29f7 100644 --- a/src/mbgl/renderer/sources/render_tile_source.cpp +++ b/src/mbgl/renderer/sources/render_tile_source.cpp @@ -134,19 +134,19 @@ std::vector RenderTileSource::querySourceFeatures(const SourceQueryOpti return tilePyramid.querySourceFeatures(options); } -void RenderTileSource::setFeatureState(const optional& sourceLayerID, const std::string& featureID, +void RenderTileSource::setFeatureState(const std::optional& sourceLayerID, const std::string& featureID, const FeatureState& state) { featureState.updateState(sourceLayerID, featureID, state); } -void RenderTileSource::getFeatureState(FeatureState& state, const optional& sourceLayerID, +void RenderTileSource::getFeatureState(FeatureState& state, const std::optional& sourceLayerID, const std::string& featureID) const { featureState.getState(state, sourceLayerID, featureID); } -void RenderTileSource::removeFeatureState(const optional& sourceLayerID, - const optional& featureID, - const optional& stateKey) { +void RenderTileSource::removeFeatureState(const std::optional& sourceLayerID, + const std::optional& featureID, + const std::optional& stateKey) { featureState.removeState(sourceLayerID, featureID, stateKey); } @@ -179,7 +179,7 @@ void RenderTileSetSource::update(Immutable baseImpl_, enabled = needsRendering; - const optional& implTileset = getTileset(); + const auto& implTileset = getTileset(); // In Continuous mode, keep the existing tiles if the new cachedTileset is not // yet available, thus providing smart style transitions without flickering. // In other modes, allow clearing the tile pyramid first, before the early diff --git a/src/mbgl/renderer/sources/render_tile_source.hpp b/src/mbgl/renderer/sources/render_tile_source.hpp index 7756bd8ed..bd929678f 100644 --- a/src/mbgl/renderer/sources/render_tile_source.hpp +++ b/src/mbgl/renderer/sources/render_tile_source.hpp @@ -35,12 +35,12 @@ public: std::vector querySourceFeatures(const SourceQueryOptions&) const override; - void setFeatureState(const optional&, const std::string&, const FeatureState&) override; + void setFeatureState(const std::optional&, const std::string&, const FeatureState&) override; - void getFeatureState(FeatureState& state, const optional&, const std::string&) const override; + void getFeatureState(FeatureState& state, const std::optional&, const std::string&) const override; - void removeFeatureState(const optional&, const optional&, - const optional&) override; + void removeFeatureState(const std::optional&, const std::optional&, + const std::optional&) override; void reduceMemoryUse() override; void dumpDebugLogs() const override; @@ -71,7 +71,7 @@ protected: bool needsRelayout, const TileParameters&) = 0; // Returns tileset from the current impl. - virtual const optional& getTileset() const = 0; + virtual const std::optional& getTileset() const = 0; private: uint8_t getMaxZoom() const final; @@ -81,7 +81,7 @@ private: bool needsRelayout, const TileParameters&) final; - optional cachedTileset; + std::optional cachedTileset; }; } // namespace mbgl diff --git a/src/mbgl/renderer/sources/render_vector_source.cpp b/src/mbgl/renderer/sources/render_vector_source.cpp index 2e12ef4c1..ca60d575b 100644 --- a/src/mbgl/renderer/sources/render_vector_source.cpp +++ b/src/mbgl/renderer/sources/render_vector_source.cpp @@ -12,7 +12,7 @@ RenderVectorSource::RenderVectorSource(Immutable impl : RenderTileSetSource(std::move(impl_)) { } -const optional& RenderVectorSource::getTileset() const { +const std::optional& RenderVectorSource::getTileset() const { return static_cast(*baseImpl).tileset; } diff --git a/src/mbgl/renderer/sources/render_vector_source.hpp b/src/mbgl/renderer/sources/render_vector_source.hpp index b83402ddb..19c39e719 100644 --- a/src/mbgl/renderer/sources/render_vector_source.hpp +++ b/src/mbgl/renderer/sources/render_vector_source.hpp @@ -15,7 +15,7 @@ private: bool needsRendering, bool needsRelayout, const TileParameters&) override; - const optional& getTileset() const override; + const std::optional& getTileset() const override; }; } // namespace mbgl diff --git a/src/mbgl/renderer/tile_pyramid.cpp b/src/mbgl/renderer/tile_pyramid.cpp index 41b0f1cb3..b4d2e5512 100644 --- a/src/mbgl/renderer/tile_pyramid.cpp +++ b/src/mbgl/renderer/tile_pyramid.cpp @@ -56,7 +56,7 @@ void TilePyramid::update(const std::vector>& l const style::Source::Impl& sourceImpl, const uint16_t tileSize, const Range zoomRange, - optional bounds, + std::optional bounds, std::function(const OverscaledTileID&)> createTile) { // If we need a relayout, abandon any cached tiles; they're now stale. if (needsRelayout) { @@ -90,8 +90,8 @@ void TilePyramid::update(const std::vector>& l int32_t tileZoom = overscaledZoom; int32_t panZoom = zoomRange.max; - const optional& sourcePrefetchZoomDelta = sourceImpl.getPrefetchZoomDelta(); - const optional& maxParentTileOverscaleFactor = sourceImpl.getMaxOverscaleFactorForParentTiles(); + const std::optional& sourcePrefetchZoomDelta = sourceImpl.getPrefetchZoomDelta(); + const std::optional& maxParentTileOverscaleFactor = sourceImpl.getMaxOverscaleFactorForParentTiles(); const Duration minimumUpdateInterval = sourceImpl.getMinimumTileUpdateInterval(); const bool isVolatile = sourceImpl.isVolatile(); @@ -126,9 +126,8 @@ void TilePyramid::update(const std::vector>& l if (parameters.mode == MapMode::Tile && type != SourceType::Raster && type != SourceType::RasterDEM && idealTiles.size() > 1) { mbgl::Log::Warning(mbgl::Event::General, - "Provided camera options returned %zu tiles, only %s is taken in Tile mode.", - idealTiles.size(), - util::toString(idealTiles[0]).c_str()); + "Provided camera options returned " + std::to_string(idealTiles.size()) + + " tiles, only " + util::toString(idealTiles[0]) + " is taken in Tile mode."); idealTiles = {idealTiles[0]}; } } @@ -157,7 +156,7 @@ void TilePyramid::update(const std::vector>& l // The min and max zoom for TileRange are based on the updateRenderables algorithm. // Tiles are created at the ideal tile zoom or at lower zoom levels. Child // tiles are used from the cache, but not created. - optional tileRange = {}; + std::optional tileRange = std::nullopt; if (bounds) { tileRange = util::TileRange::fromLatLngBounds( *bounds, zoomRange.min, std::min(tileZoom, static_cast(zoomRange.max))); diff --git a/src/mbgl/renderer/tile_pyramid.hpp b/src/mbgl/renderer/tile_pyramid.hpp index f1c310849..b04d2c6bb 100644 --- a/src/mbgl/renderer/tile_pyramid.hpp +++ b/src/mbgl/renderer/tile_pyramid.hpp @@ -41,7 +41,7 @@ public: const style::Source::Impl&, uint16_t tileSize, Range zoomRange, - optional bounds, + std::optional bounds, std::function(const OverscaledTileID&)> createTile); const std::map>& getRenderedTiles() const { return renderedTiles; } diff --git a/src/mbgl/renderer/tile_render_data.cpp b/src/mbgl/renderer/tile_render_data.cpp index 300e8d848..5f8c2498b 100644 --- a/src/mbgl/renderer/tile_render_data.cpp +++ b/src/mbgl/renderer/tile_render_data.cpp @@ -22,9 +22,9 @@ const gfx::Texture& TileRenderData::getIconAtlasTexture() const { return *atlasTextures->icon; } -optional TileRenderData::getPattern(const std::string&) const { +std::optional TileRenderData::getPattern(const std::string&) const { assert(false); - return nullopt; + return std::nullopt; } const LayerRenderData* TileRenderData::getLayerRenderData(const style::Layer::Impl&) const { diff --git a/src/mbgl/renderer/tile_render_data.hpp b/src/mbgl/renderer/tile_render_data.hpp index 85bbc4956..85b26754e 100644 --- a/src/mbgl/renderer/tile_render_data.hpp +++ b/src/mbgl/renderer/tile_render_data.hpp @@ -5,6 +5,7 @@ #include #include +#include namespace mbgl { @@ -18,8 +19,8 @@ class SourcePrepareParameters; class TileAtlasTextures { public: - optional glyph; - optional icon; + std::optional glyph; + std::optional icon; }; class TileRenderData { @@ -28,7 +29,7 @@ public: const gfx::Texture& getGlyphAtlasTexture() const; const gfx::Texture& getIconAtlasTexture() const; // To be implemented for concrete tile types. - virtual optional getPattern(const std::string&) const; + virtual std::optional getPattern(const std::string&) const; virtual const LayerRenderData* getLayerRenderData(const style::Layer::Impl&) const; virtual Bucket* getBucket(const style::Layer::Impl&) const; virtual void upload(gfx::UploadPass&) {} diff --git a/src/mbgl/sprite/sprite_parser.cpp b/src/mbgl/sprite/sprite_parser.cpp index 720a5d843..3ac93d335 100644 --- a/src/mbgl/sprite/sprite_parser.cpp +++ b/src/mbgl/sprite/sprite_parser.cpp @@ -12,6 +12,7 @@ #include #include #include +#include namespace mbgl { @@ -25,21 +26,19 @@ std::unique_ptr createStyleImage(const std::string& id, const bool sdf, style::ImageStretches&& stretchX, style::ImageStretches&& stretchY, - const optional& content) { + const std::optional& content) { // Disallow invalid parameter configurations. if (width <= 0 || height <= 0 || width > 1024 || height > 1024 || ratio <= 0 || ratio > 10 || srcX < 0 || srcY < 0 || srcX >= static_cast(image.size.width) || srcY >= static_cast(image.size.height) || srcX + width > static_cast(image.size.width) || srcY + height > static_cast(image.size.height)) { - Log::Error(Event::Sprite, - "Can't create image with invalid metrics: %dx%d@%d,%d in %ux%u@%sx sprite", - width, - height, - srcX, - srcY, - image.size.width, - image.size.height, - util::toString(ratio).c_str()); + std::ostringstream ss; + ss << "Can't create image with invalid metrics: " + << width << "x" << height << "@" << srcX << "," << srcY + << " in " << image.size.width << "x" << image.size.height + << "@" << util::toString(ratio) << "x" + << " sprite"; + Log::Error(Event::Sprite, ss.str()); return nullptr; } @@ -53,7 +52,7 @@ std::unique_ptr createStyleImage(const std::string& id, return std::make_unique( id, std::move(dstImage), static_cast(ratio), sdf, std::move(stretchX), std::move(stretchY), content); } catch (const util::StyleImageException& ex) { - Log::Error(Event::Sprite, "Can't create image with invalid metadata: %s", ex.what()); + Log::Error(Event::Sprite, std::string("Can't create image with invalid metadata: ") + ex.what()); return nullptr; } } @@ -67,9 +66,7 @@ uint16_t getUInt16(const JSValue& value, const char* property, const char* name, return v.GetUint(); } else { Log::Warning(Event::Sprite, - "Invalid sprite image '%s': value of '%s' must be an integer between 0 and 65535", - name, - property); + std::string("Invalid sprite image '") + name + "': value of '" + property + "' must be an integer between 0 and 65535"); } } @@ -82,7 +79,7 @@ double getDouble(const JSValue& value, const char* property, const char* name, c if (v.IsNumber()) { return v.GetDouble(); } else { - Log::Warning(Event::Sprite, "Invalid sprite image '%s': value of '%s' must be a number", name, property); + Log::Warning(Event::Sprite, std::string("Invalid sprite image '") + name + "': value of '" + property + "' must be a number"); } } @@ -95,7 +92,7 @@ bool getBoolean(const JSValue& value, const char* property, const char* name, co if (v.IsBool()) { return v.GetBool(); } else { - Log::Warning(Event::Sprite, "Invalid sprite image '%s': value of '%s' must be a boolean", name, property); + Log::Warning(Event::Sprite, std::string("Invalid sprite image '") + name + "': value of '" + property + "' must be a boolean"); } } @@ -116,20 +113,18 @@ style::ImageStretches getStretches(const JSValue& value, const char* property, c stretch[rapidjson::SizeType(1)].GetFloat()}); } else { Log::Warning(Event::Sprite, - "Invalid sprite image '%s': members of '%s' must be an array of two numbers", - name, - property); + "Invalid sprite image '" + std::string(name) + "': members of '" + property + "' must be an array of two numbers"); } } } else { - Log::Warning(Event::Sprite, "Invalid sprite image '%s': value of '%s' must be an array", name, property); + Log::Warning(Event::Sprite, "Invalid sprite image '" + std::string(name) + "': value of '" + property + "' must be an array"); } } return stretches; } -optional getContent(const JSValue& value, const char* property, const char* name) { +std::optional getContent(const JSValue& value, const char* property, const char* name) { if (value.HasMember(property)) { auto& content = value[property]; if (content.IsArray() && content.Size() == 4 && content[rapidjson::SizeType(0)].IsNumber() && @@ -141,13 +136,11 @@ optional getContent(const JSValue& value, const char* prope content[rapidjson::SizeType(3)].GetFloat()}; } else { Log::Warning(Event::Sprite, - "Invalid sprite image '%s': value of '%s' must be an array of four numbers", - name, - property); + "Invalid sprite image '" + std::string(name) + "': value of '" + property + "' must be an array of four numbers"); } } - return nullopt; + return std::nullopt; } } // namespace @@ -181,7 +174,7 @@ std::vector> parseSprite(const std::string& encode const bool sdf = getBoolean(value, "sdf", name.c_str(), false); style::ImageStretches stretchX = getStretches(value, "stretchX", name.c_str()); style::ImageStretches stretchY = getStretches(value, "stretchY", name.c_str()); - optional content = getContent(value, "content", name.c_str()); + std::optional content = getContent(value, "content", name.c_str()); auto image = createStyleImage( name, raster, x, y, width, height, pixelRatio, sdf, std::move(stretchX), std::move(stretchY), content); diff --git a/src/mbgl/sprite/sprite_parser.hpp b/src/mbgl/sprite/sprite_parser.hpp index baba427f4..54a0746cb 100644 --- a/src/mbgl/sprite/sprite_parser.hpp +++ b/src/mbgl/sprite/sprite_parser.hpp @@ -17,7 +17,7 @@ std::unique_ptr createStyleImage(const std::string& id, bool sdf, style::ImageStretches&& stretchX = {}, style::ImageStretches&& stretchY = {}, - const optional& content = nullopt); + const std::optional& content = std::nullopt); // Parses an image and an associated JSON file and returns the sprite objects. std::vector> parseSprite(const std::string& image, const std::string& json); diff --git a/src/mbgl/storage/resource.cpp b/src/mbgl/storage/resource.cpp index 8045c1f09..7461364a8 100644 --- a/src/mbgl/storage/resource.cpp +++ b/src/mbgl/storage/resource.cpp @@ -79,7 +79,7 @@ Resource Resource::spriteJSON(const std::string& base, float pixelRatio) { Resource Resource::glyphs(const std::string& urlTemplate, const FontStack& fontStack, const std::pair& glyphRange) { return Resource { Resource::Kind::Glyphs, - util::replaceTokens(urlTemplate, [&](const std::string& token) -> optional { + util::replaceTokens(urlTemplate, [&](const std::string& token) -> std::optional { if (token == "fontstack") { return util::percentEncode(fontStackToString(fontStack)); } else if (token == "range") { @@ -104,7 +104,7 @@ Resource Resource::tile(const std::string& urlTemplate, } return Resource { Resource::Kind::Tile, - util::replaceTokens(urlTemplate, [&](const std::string& token) -> optional { + util::replaceTokens(urlTemplate, [&](const std::string& token) -> std::optional { if (token == "z") { return util::toString(z); } else if (token == "x") { diff --git a/src/mbgl/storage/response.cpp b/src/mbgl/storage/response.cpp index ba075c326..1922d319c 100644 --- a/src/mbgl/storage/response.cpp +++ b/src/mbgl/storage/response.cpp @@ -18,7 +18,7 @@ Response& Response::operator=(const Response& res) { return *this; } -Response::Error::Error(Reason reason_, std::string message_, optional retryAfter_) +Response::Error::Error(Reason reason_, std::string message_, std::optional retryAfter_) : reason(reason_), message(std::move(message_)), retryAfter(std::move(retryAfter_)) { } diff --git a/src/mbgl/style/collection.hpp b/src/mbgl/style/collection.hpp index 7d67fac94..36d5176d4 100644 --- a/src/mbgl/style/collection.hpp +++ b/src/mbgl/style/collection.hpp @@ -1,10 +1,10 @@ #pragma once #include -#include #include #include +#include namespace mbgl { namespace style { @@ -62,7 +62,7 @@ class Collection : public CollectionBase { using Base = CollectionBase; public: - T* add(std::unique_ptr wrapper, const optional& before = nullopt) { + T* add(std::unique_ptr wrapper, const std::optional& before = std::nullopt) { std::size_t idx = before ? Base::index(*before) : Base::size(); return Base::add(idx, idx, std::move(wrapper)); } diff --git a/src/mbgl/style/conversion/color_ramp_property_value.cpp b/src/mbgl/style/conversion/color_ramp_property_value.cpp index 0da16c67e..f31ad47b6 100644 --- a/src/mbgl/style/conversion/color_ramp_property_value.cpp +++ b/src/mbgl/style/conversion/color_ramp_property_value.cpp @@ -10,7 +10,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error, bool, bool) const { +std::optional Converter::operator()(const Convertible& value, Error& error, bool, bool) const { using namespace mbgl::style::expression; if (isUndefined(value)) { return ColorRampPropertyValue(); @@ -19,21 +19,21 @@ optional Converter::operator()(c ParseResult expression = ctx.parseLayerPropertyExpression(value); if (!expression) { error.message = ctx.getCombinedErrors(); - return nullopt; + return std::nullopt; } assert(*expression); if (!isFeatureConstant(**expression)) { error.message = "data expressions not supported"; - return nullopt; + return std::nullopt; } if (!isZoomConstant(**expression)) { error.message = "zoom expressions not supported"; - return nullopt; + return std::nullopt; } return ColorRampPropertyValue(std::move(*expression)); } else { error.message = "color ramp must be an expression"; - return nullopt; + return std::nullopt; } } diff --git a/src/mbgl/style/conversion/constant.cpp b/src/mbgl/style/conversion/constant.cpp index bd3f80470..6e82047ac 100644 --- a/src/mbgl/style/conversion/constant.cpp +++ b/src/mbgl/style/conversion/constant.cpp @@ -5,64 +5,64 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { - optional converted = toBool(value); +std::optional Converter::operator()(const Convertible& value, Error& error) const { + std::optional converted = toBool(value); if (!converted) { error.message = "value must be a boolean"; - return nullopt; + return std::nullopt; } return *converted; } -optional Converter::operator()(const Convertible& value, Error& error) const { - optional converted = toNumber(value); +std::optional Converter::operator()(const Convertible& value, Error& error) const { + std::optional converted = toNumber(value); if (!converted) { error.message = "value must be a number"; - return nullopt; + return std::nullopt; } return *converted; } -optional Converter::operator()(const Convertible& value, Error& error) const { - optional converted = toString(value); +std::optional Converter::operator()(const Convertible& value, Error& error) const { + std::optional converted = toString(value); if (!converted) { error.message = "value must be a string"; - return nullopt; + return std::nullopt; } return *converted; } template -optional Converter>>::operator()(const Convertible& value, Error& error) const { - optional string = toString(value); +std::optional Converter>>::operator()(const Convertible& value, Error& error) const { + std::optional string = toString(value); if (!string) { error.message = "value must be a string"; - return nullopt; + return std::nullopt; } const auto result = Enum::toEnum(*string); if (!result) { error.message = "value must be a valid enumeration value"; - return nullopt; + return std::nullopt; } return *result; } template -auto Converter, typename std::enable_if_t>>::operator()(const Convertible& value, Error& error) const -> optional> { +auto Converter, typename std::enable_if_t>>::operator()(const Convertible& value, Error& error) const -> std::optional> { if (!isArray(value)) { error.message = "value must be an array"; - return nullopt; + return std::nullopt; } std::vector result; result.reserve(arrayLength(value)); for (std::size_t i = 0; i < arrayLength(value); ++i) { - optional enumItem = Converter{}(arrayMember(value, i), error); + std::optional enumItem = Converter{}(arrayMember(value, i), error); if (!enumItem) { - return nullopt; + return std::nullopt; } result.push_back(*enumItem); } @@ -70,99 +70,99 @@ auto Converter, typename std::enable_if_t>>::op return result; } -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional Converter::operator()(const Convertible&, Error&) const; -template optional> Converter>::operator()(const Convertible&, Error&) const; -template optional> Converter>::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional Converter::operator()(const Convertible&, Error&) const; +template std::optional> Converter>::operator()(const Convertible&, Error&) const; +template std::optional> Converter>::operator()(const Convertible&, Error&) const; -optional Converter::operator()(const Convertible& value, Error& error) const { - optional string = toString(value); +std::optional Converter::operator()(const Convertible& value, Error& error) const { + std::optional string = toString(value); if (!string) { error.message = "value must be a string"; - return nullopt; + return std::nullopt; } - optional color = Color::parse(*string); + std::optional color = Color::parse(*string); if (!color) { error.message = "value must be a valid color"; - return nullopt; + return std::nullopt; } return *color; } template -optional> Converter>::operator()(const Convertible& value, Error& error) const { +std::optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isArray(value) || arrayLength(value) != N) { error.message = "value must be an array of " + util::toString(N) + " numbers"; - return nullopt; + return std::nullopt; } std::array result; for (size_t i = 0; i < N; i++) { - optional n = toNumber(arrayMember(value, i)); + std::optional n = toNumber(arrayMember(value, i)); if (!n) { error.message = "value must be an array of " + util::toString(N) + " numbers"; - return nullopt; + return std::nullopt; } result[i] = *n; } return result; } -template optional> Converter>::operator()(const Convertible&, Error&) const; -template optional> Converter>::operator()(const Convertible&, Error&) const; -template optional> Converter>::operator()(const Convertible&, Error&) const; +template std::optional> Converter>::operator()(const Convertible&, Error&) const; +template std::optional> Converter>::operator()(const Convertible&, Error&) const; +template std::optional> Converter>::operator()(const Convertible&, Error&) const; template -optional> Converter>::operator()(const Convertible& value, +std::optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isArray(value) || arrayLength(value) != N) { error.message = "value must be an array of " + util::toString(N) + " numbers"; - return nullopt; + return std::nullopt; } std::array result; for (size_t i = 0; i < N; i++) { - optional n = toDouble(arrayMember(value, i)); + std::optional n = toDouble(arrayMember(value, i)); if (!n) { error.message = "value must be an array of " + util::toString(N) + " numbers"; - return nullopt; + return std::nullopt; } result[i] = *n; } return result; } -template optional> Converter>::operator()(const Convertible&, Error&) const; +template std::optional> Converter>::operator()(const Convertible&, Error&) const; -optional> Converter>::operator()(const Convertible& value, Error& error) const { +std::optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isArray(value)) { error.message = "value must be an array"; - return nullopt; + return std::nullopt; } std::vector result; result.reserve(arrayLength(value)); for (std::size_t i = 0; i < arrayLength(value); ++i) { - optional number = toNumber(arrayMember(value, i)); + std::optional number = toNumber(arrayMember(value, i)); if (!number) { error.message = "value must be an array of numbers"; - return nullopt; + return std::nullopt; } result.push_back(*number); } @@ -170,20 +170,20 @@ optional> Converter>::operator()(const Con return result; } -optional> Converter>::operator()(const Convertible& value, Error& error) const { +std::optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isArray(value)) { error.message = "value must be an array"; - return nullopt; + return std::nullopt; } std::vector result; result.reserve(arrayLength(value)); for (std::size_t i = 0; i < arrayLength(value); ++i) { - optional string = toString(arrayMember(value, i)); + std::optional string = toString(arrayMember(value, i)); if (!string) { error.message = "value must be an array of strings"; - return nullopt; + return std::nullopt; } result.push_back(*string); } diff --git a/src/mbgl/style/conversion/coordinate.cpp b/src/mbgl/style/conversion/coordinate.cpp index ee03bffb3..9f554518b 100644 --- a/src/mbgl/style/conversion/coordinate.cpp +++ b/src/mbgl/style/conversion/coordinate.cpp @@ -5,22 +5,22 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator() (const Convertible& value, Error& error) const { +std::optional Converter::operator() (const Convertible& value, Error& error) const { if (!isArray(value) || arrayLength(value) < 2 ) { error.message = "coordinate array must contain numeric longitude and latitude values"; - return nullopt; + return std::nullopt; } //Style spec uses GeoJSON convention for specifying coordinates - optional latitude = toDouble(arrayMember(value, 1)); - optional longitude = toDouble(arrayMember(value, 0)); + std::optional latitude = toDouble(arrayMember(value, 1)); + std::optional longitude = toDouble(arrayMember(value, 0)); if (!latitude || !longitude) { error.message = "coordinate array must contain numeric longitude and latitude values"; - return nullopt; + return std::nullopt; } if (*latitude < -90 || *latitude > 90 ){ error.message = "coordinate latitude must be between -90 and 90"; - return nullopt; + return std::nullopt; } return LatLng(*latitude, *longitude); } diff --git a/src/mbgl/style/conversion/custom_geometry_source_options.cpp b/src/mbgl/style/conversion/custom_geometry_source_options.cpp index 491509c28..4b0f715c0 100644 --- a/src/mbgl/style/conversion/custom_geometry_source_options.cpp +++ b/src/mbgl/style/conversion/custom_geometry_source_options.cpp @@ -5,7 +5,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { CustomGeometrySource::Options options; const auto minzoomValue = objectMember(value, "minzoom"); @@ -14,7 +14,7 @@ optional Converter options.zoomRange.min = static_cast(*toNumber(*minzoomValue)); } else { error.message = "GeoJSON source minzoom value must be a number"; - return nullopt; + return std::nullopt; } } @@ -24,7 +24,7 @@ optional Converter options.zoomRange.max = static_cast(*toNumber(*maxzoomValue)); } else { error.message = "GeoJSON source maxzoom value must be a number"; - return nullopt; + return std::nullopt; } } @@ -34,7 +34,7 @@ optional Converter options.tileOptions.buffer = static_cast(*toNumber(*bufferValue)); } else { error.message = "GeoJSON source buffer value must be a number"; - return nullopt; + return std::nullopt; } } @@ -44,7 +44,7 @@ optional Converter options.tileOptions.tolerance = static_cast(*toNumber(*toleranceValue)); } else { error.message = "GeoJSON source tolerance value must be a number"; - return nullopt; + return std::nullopt; } } @@ -54,7 +54,7 @@ optional Converter options.tileOptions.wrap = static_cast(*toBool(*wrapValue)); } else { error.message = "CustomGeometrySource TileOptions wrap value must be a boolean"; - return nullopt; + return std::nullopt; } } @@ -64,7 +64,7 @@ optional Converter options.tileOptions.clip = static_cast(*toBool(*clipValue)); } else { error.message = "CustomGeometrySource TileOptiosn clip value must be a boolean"; - return nullopt; + return std::nullopt; } } diff --git a/src/mbgl/style/conversion/filter.cpp b/src/mbgl/style/conversion/filter.cpp index 8c3e92559..d354d23e8 100644 --- a/src/mbgl/style/conversion/filter.cpp +++ b/src/mbgl/style/conversion/filter.cpp @@ -16,15 +16,15 @@ using namespace mbgl::style::expression; static bool isExpression(const Convertible& filter); ParseResult convertLegacyFilter(const Convertible& values, Error& error); -optional serializeLegacyFilter(const Convertible& values); +std::optional serializeLegacyFilter(const Convertible& values); -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { if (isExpression(value)) { ParsingContext parsingContext(type::Boolean); ParseResult parseResult = parsingContext.parseExpression(value); if (!parseResult) { error.message = parsingContext.getCombinedErrors(); - return nullopt; + return std::nullopt; } else { return { Filter(std::move(parseResult)) }; } @@ -32,9 +32,9 @@ optional Converter::operator()(const Convertible& value, Error& ParseResult expression = convertLegacyFilter(value, error); if (!expression) { assert(error.message.size() > 0); - return nullopt; + return std::nullopt; } - return Filter(optional>(std::move(*expression)), serializeLegacyFilter(value)); + return Filter(std::optional>(std::move(*expression)), serializeLegacyFilter(value)); } } @@ -44,21 +44,21 @@ bool isExpression(const Convertible& filter) { return false; } - optional op = toString(arrayMember(filter, 0)); + auto op = toString(arrayMember(filter, 0)); if (!op) { return false; } else if (*op == "has") { if (arrayLength(filter) < 2) return false; - optional operand = toString(arrayMember(filter, 1)); + auto operand = toString(arrayMember(filter, 1)); return operand && *operand != "$id" && *operand != "$type"; } else if (*op == "!in" || *op == "!has" || *op == "none") { return false; } else if (*op == "in") { - optional str = toString(arrayMember(filter, 1)); + auto str = toString(arrayMember(filter, 1)); return arrayLength(filter) >= 3 && (!str || isArray(arrayMember(filter, 2))); @@ -80,7 +80,7 @@ bool isExpression(const Convertible& filter) { } ParseResult createExpression(const std::string& op, - optional>> args, + std::optional>> args, Error& error) { if (!args) return {}; assert(std::all_of(args->begin(), args->end(), [](const std::unique_ptr &e) { @@ -124,13 +124,13 @@ ParseResult convertLiteral(const Convertible& convertible, Error& error) { } } -optional>> convertLiteralArray(const Convertible &input, Error& error, std::size_t startIndex = 0) { +std::optional>> convertLiteralArray(const Convertible &input, Error& error, std::size_t startIndex = 0) { std::vector> output; output.reserve(arrayLength(input)); for (std::size_t i = startIndex; i < arrayLength(input); ++i) { ParseResult literal = convertLiteral(arrayMember(input, i), error); if (!literal) { - return nullopt; + return std::nullopt; } output.push_back(std::move(*literal)); } @@ -139,9 +139,9 @@ optional>> convertLiteralArray(const Con ParseResult convertLegacyComparisonFilter(const Convertible& values, Error& error, - const optional& opOverride = {}) { - optional op = opOverride ? opOverride : toString(arrayMember(values, 0)); - optional property = toString(arrayMember(values, 1)); + const std::optional& opOverride = std::nullopt) { + auto op = opOverride ? opOverride : toString(arrayMember(values, 0)); + auto property = toString(arrayMember(values, 1)); if (!property) { error.message = "filter property must be a string"; @@ -156,7 +156,7 @@ ParseResult convertLegacyComparisonFilter(const Convertible& values, } ParseResult convertLegacyHasFilter(const Convertible& values, Error& error) { - optional property = toString(arrayMember(values, 1)); + std::optional property = toString(arrayMember(values, 1)); if (!property) { error.message = "filter property must be a string"; @@ -171,7 +171,7 @@ ParseResult convertLegacyHasFilter(const Convertible& values, Error& error) { } ParseResult convertLegacyInFilter(const Convertible& values, Error& error) { - optional property = toString(arrayMember(values, 1)); + std::optional property = toString(arrayMember(values, 1)); if (!property) { error.message = "filter property must be a string"; @@ -187,13 +187,13 @@ ParseResult convertLegacyInFilter(const Convertible& values, Error& error) { } } -optional>> convertLegacyFilterArray(const Convertible &input, Error& error, std::size_t startIndex = 0) { +std::optional>> convertLegacyFilterArray(const Convertible &input, Error& error, std::size_t startIndex = 0) { std::vector> output; output.reserve(arrayLength(input)); for (std::size_t i = startIndex; i < arrayLength(input); ++i) { - optional> child = convertLegacyFilter(arrayMember(input, i), error); + auto child = convertLegacyFilter(arrayMember(input, i), error); if (!child) { - return nullopt; + return std::nullopt; } output.push_back(std::move(*child)); } @@ -207,14 +207,14 @@ ParseResult convertLegacyFilter(const Convertible& values, Error& error) { if (!isArray(values) || arrayLength(values) == 0) { error.message = "filter value must be a non empty array"; - return nullopt; + return std::nullopt; } - optional op = toString(arrayMember(values, 0)); + std::optional op = toString(arrayMember(values, 0)); if (!op) { error.message = "filter operator must be a string"; - return nullopt; + return std::nullopt; } else if (arrayLength(values) <= 1) { return {std::make_unique(*op != "any")}; } else if (*op == "within") { @@ -240,9 +240,9 @@ ParseResult convertLegacyFilter(const Convertible& values, Error& error) { } } -optional serializeLegacyFilter(const Convertible& values) { +std::optional serializeLegacyFilter(const Convertible& values) { if (isUndefined(values)) { - return nullopt; + return std::nullopt; } else if (isArray(values)) { std::vector result; result.reserve(arrayLength(values)); diff --git a/src/mbgl/style/conversion/function.cpp b/src/mbgl/style/conversion/function.cpp index df4883fe6..8824aeed8 100644 --- a/src/mbgl/style/conversion/function.cpp +++ b/src/mbgl/style/conversion/function.cpp @@ -87,90 +87,90 @@ std::unique_ptr convertTokenStringToExpression(const std::string& so } template -optional> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) { +std::optional> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens) { auto expression = convertFunctionToExpression(expression::valueTypeToExpressionType(), value, error, convertTokens); if (!expression) { - return nullopt; + return std::nullopt; } - optional defaultValue{}; + std::optional defaultValue{}; auto defaultValueValue = objectMember(value, "default"); if (defaultValueValue) { defaultValue = convert(*defaultValueValue, error); if (!defaultValue) { error.message = R"(wrong type for "default": )" + error.message; - return nullopt; + return std::nullopt; } } return PropertyExpression(std::move(*expression), defaultValue); } -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional>> +template std::optional>> convertFunctionToExpression>(const Convertible&, Error&, bool); -template optional>> +template std::optional>> convertFunctionToExpression>(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional>> +template std::optional>> convertFunctionToExpression>(const Convertible&, Error&, bool); -template optional>> +template std::optional>> convertFunctionToExpression>(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional>> +template std::optional>> convertFunctionToExpression>(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional>> +template std::optional>> convertFunctionToExpression>(const Convertible&, Error&, bool); -template optional> convertFunctionToExpression(const Convertible&, Error&, bool); -template optional> convertFunctionToExpression(const Convertible&, Error&, bool); +template std::optional> convertFunctionToExpression(const Convertible&, Error&, bool); +template std::optional> convertFunctionToExpression(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 { - optional operator()(const Convertible& value, Error& error) const { + std::optional operator()(const Convertible& value, Error& error) const { auto converted = convert(value, error); if (!converted) { - return nullopt; + return std::nullopt; } return *converted; } @@ -178,10 +178,10 @@ struct Converter { template <> struct Converter { - optional operator()(const Convertible& value, Error& error) const { + std::optional operator()(const Convertible& value, Error& error) const { auto converted = convert(value, error); if (!converted) { - return nullopt; + return std::nullopt; } return static_cast(*converted); } @@ -212,135 +212,135 @@ static bool interpolatable(type::Type type) { ); } -static optional> convertLiteral(type::Type type, const Convertible& value, Error& error, bool convertTokens = false) { +static std::optional> convertLiteral(type::Type type, const Convertible& value, Error& error, bool convertTokens = false) { return type.match( - [&](const type::NumberType&) -> optional> { + [&](const type::NumberType&) -> std::optional> { auto result = convert(value, error); if (!result) { - return nullopt; + return std::nullopt; } return literal(static_cast(*result)); }, - [&](const type::BooleanType&) -> optional> { + [&](const type::BooleanType&) -> std::optional> { auto result = convert(value, error); if (!result) { - return nullopt; + return std::nullopt; } return literal(*result); }, - [&](const type::StringType&) -> optional> { + [&](const type::StringType&) -> std::optional> { auto result = convert(value, error); if (!result) { - return nullopt; + return std::nullopt; } return convertTokens ? convertTokenStringToExpression(*result) : literal(*result); }, - [&](const type::ColorType&) -> optional> { + [&](const type::ColorType&) -> std::optional> { auto result = convert(value, error); if (!result) { - return nullopt; + return std::nullopt; } return literal(*result); }, - [&](const type::Array& array) -> optional> { + [&](const type::Array& array) -> std::optional> { 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> { + [&] (const type::NumberType&) -> std::optional> { std::vector result; result.reserve(arrayLength(value)); for (std::size_t i = 0; i < arrayLength(value); ++i) { - optional number = toNumber(arrayMember(value, i)); + std::optional 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(*number)); } return literal(result); }, - [&] (const type::StringType&) -> optional> { + [&] (const type::StringType&) -> std::optional> { std::vector result; result.reserve(arrayLength(value)); for (std::size_t i = 0; i < arrayLength(value); ++i) { - optional string = toString(arrayMember(value, i)); + std::optional 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> { + [&] (const auto&) -> std::optional> { assert(false); // No properties use this type. - return nullopt; + return std::nullopt; } ); }, - [&](const type::NullType&) -> optional> { + [&](const type::NullType&) -> std::optional> { assert(false); // No properties use this type. - return nullopt; + return std::nullopt; }, - [&](const type::ObjectType&) -> optional> { + [&](const type::ObjectType&) -> std::optional> { assert(false); // No properties use this type. - return nullopt; + return std::nullopt; }, - [&](const type::ErrorType&) -> optional> { + [&](const type::ErrorType&) -> std::optional> { assert(false); // No properties use this type. - return nullopt; + return std::nullopt; }, - [&](const type::ValueType&) -> optional> { + [&](const type::ValueType&) -> std::optional> { assert(false); // No properties use this type. - return nullopt; + return std::nullopt; }, - [&](const type::CollatorType&) -> optional> { + [&](const type::CollatorType&) -> std::optional> { assert(false); // No properties use this type. - return nullopt; + return std::nullopt; }, - [&](const type::FormattedType&) -> optional> { + [&](const type::FormattedType&) -> std::optional> { auto result = convert(value, error); if (!result) { - return nullopt; + return std::nullopt; } return convertTokens ? convertTokenStringToFormatExpression(*result) : literal(Formatted(result->c_str())); }, - [&](const type::ImageType&) -> optional> { + [&](const type::ImageType&) -> std::optional> { auto result = convert(value, error); if (!result) { - return nullopt; + return std::nullopt; } return convertTokens ? std::make_unique(convertTokenStringToImageExpression(*result)) : literal(Image(result->c_str())); }); } -static optional>> convertStops(const type::Type& type, +static std::optional>> 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> stops; @@ -349,22 +349,22 @@ static optional>> 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 t = convert(arrayMember(stopValue, 0), error); + std::optional t = convert(arrayMember(stopValue, 0), error); if (!t) { - return nullopt; + return std::nullopt; } - optional> e = convertLiteral(type, arrayMember(stopValue, 1), error, convertTokens); + std::optional> 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>& stops) } template -optional>> convertBranches(const type::Type& type, +std::optional>> 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> stops; @@ -410,22 +410,22 @@ optional>> 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 = convert(arrayMember(stopValue, 0), error); + std::optional t = convert(arrayMember(stopValue, 0), error); if (!t) { - return nullopt; + return std::nullopt; } - optional> e = convertLiteral(type, arrayMember(stopValue, 1), error); + std::optional> 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>> convertBranches(const type::T return { std::move(stops) }; } -static optional convertBase(const Convertible& value, Error& error) { +static std::optional convertBase(const Convertible& value, Error& error) { auto baseValue = objectMember(value, "base"); if (!baseValue) { @@ -444,7 +444,7 @@ static optional 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 numberOrDefault(const type::Type& type, return std::make_unique(type, std::move(branches), std::move(def)); } -static optional> convertIntervalFunction( +static std::optional> convertIntervalFunction( const type::Type& type, const Convertible& value, Error& error, @@ -527,7 +527,7 @@ static optional> 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> convertIntervalFunction( std::move(def)); } -static optional> convertExponentialFunction( +static std::optional> convertExponentialFunction( const type::Type& type, const Convertible& value, Error& error, @@ -546,11 +546,11 @@ static optional> 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> convertExponentialFunction( std::move(def)); } -static optional> convertCategoricalFunction(const type::Type& type, +static std::optional> convertCategoricalFunction(const type::Type& type, const Convertible& value, Error& err, const std::string& property, @@ -567,35 +567,35 @@ static optional> 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(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> convertCategoricalFunction(const ty if (toNumber(arrayMember(first, 0))) { auto branches = convertBranches(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> convertCategoricalFunction(const ty if (toString(arrayMember(first, 0))) { auto branches = convertBranches(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 -optional> composite(type::Type type, +std::optional> 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> 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 z = convert(*zoomValue, error); + std::optional z = convert(*zoomValue, error); if (!z) { - return nullopt; + return std::nullopt; } - optional d = convert(*sourceValue, error); + std::optional d = convert(*sourceValue, error); if (!d) { - return nullopt; + return std::nullopt; } - optional> r = convertLiteral(type, arrayMember(stopValue, 1), error); + std::optional> 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> composite(type::Type type, } } -optional> convertFunctionToExpression(type::Type type, +std::optional> 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> convertFunctionToExpression(type::Type typ if (!typeValue) { functionType = interpolatable(type) ? FunctionType::Exponential : FunctionType::Interval; } else { - optional string = toString(*typeValue); + auto string = toString(*typeValue); if (string) { if (*string == "interval") functionType = FunctionType::Interval; @@ -749,77 +749,77 @@ optional> 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> { + [&](const type::StringType&) -> std::optional> { return string(get(literal(*property)), defaultExpr()); }, - [&](const type::NumberType&) -> optional> { + [&](const type::NumberType&) -> std::optional> { return number(get(literal(*property)), defaultExpr()); }, - [&](const type::BooleanType&) -> optional> { + [&](const type::BooleanType&) -> std::optional> { return boolean(get(literal(*property)), defaultExpr()); }, - [&](const type::ColorType&) -> optional> { + [&](const type::ColorType&) -> std::optional> { return toColor(get(literal(*property)), defaultExpr()); }, - [&](const type::Array& array) -> optional> { + [&](const type::Array& array) -> std::optional> { return assertion(array, get(literal(*property)), defaultExpr()); }, - [&](const type::FormattedType&) -> optional> { + [&](const type::FormattedType&) -> std::optional> { return toFormatted(get(literal(*property)), defaultExpr()); }, - [&](const type::ImageType&) -> optional> { + [&](const type::ImageType&) -> std::optional> { return toImage(get(literal(*property)), defaultExpr()); }, - [&](const auto&) -> optional> { + [&](const auto&) -> std::optional> { 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> 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> convertFunctionToExpression(type::Type typ }); default: err.message = "unsupported function type"; - return nullopt; + return std::nullopt; } } @@ -903,7 +903,7 @@ optional> convertFunctionToExpression(type::Type typ }); default: err.message = "unsupported function type"; - return nullopt; + return std::nullopt; } } @@ -919,12 +919,12 @@ optional> 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; } } diff --git a/src/mbgl/style/conversion/geojson.cpp b/src/mbgl/style/conversion/geojson.cpp index c2d34c549..0a64ca61f 100644 --- a/src/mbgl/style/conversion/geojson.cpp +++ b/src/mbgl/style/conversion/geojson.cpp @@ -6,11 +6,11 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { return toGeoJSON(value, error); } -optional parseGeoJSON(const std::string& value, Error& error) { +std::optional parseGeoJSON(const std::string& value, Error& error) { return convertJSON(value, error); } diff --git a/src/mbgl/style/conversion/geojson_options.cpp b/src/mbgl/style/conversion/geojson_options.cpp index a7ca9b7da..6aad28d15 100644 --- a/src/mbgl/style/conversion/geojson_options.cpp +++ b/src/mbgl/style/conversion/geojson_options.cpp @@ -8,7 +8,7 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, +std::optional Converter::operator()(const Convertible& value, Error& error) const { GeoJSONOptions options; @@ -18,7 +18,7 @@ optional Converter::operator()(const Convertible options.minzoom = static_cast(*toNumber(*minzoomValue)); } else { error.message = "GeoJSON source minzoom value must be a number"; - return nullopt; + return std::nullopt; } } @@ -28,7 +28,7 @@ optional Converter::operator()(const Convertible options.maxzoom = static_cast(*toNumber(*maxzoomValue)); } else { error.message = "GeoJSON source maxzoom value must be a number"; - return nullopt; + return std::nullopt; } } @@ -38,7 +38,7 @@ optional Converter::operator()(const Convertible options.buffer = static_cast(*toNumber(*bufferValue)); } else { error.message = "GeoJSON source buffer value must be a number"; - return nullopt; + return std::nullopt; } } @@ -48,7 +48,7 @@ optional Converter::operator()(const Convertible options.tolerance = static_cast(*toNumber(*toleranceValue)); } else { error.message = "GeoJSON source tolerance value must be a number"; - return nullopt; + return std::nullopt; } } @@ -58,7 +58,7 @@ optional Converter::operator()(const Convertible options.cluster = *toBool(*clusterValue); } else { error.message = "GeoJSON source cluster value must be a boolean"; - return nullopt; + return std::nullopt; } } @@ -68,7 +68,7 @@ optional Converter::operator()(const Convertible options.clusterMaxZoom = static_cast(*toNumber(*clusterMaxZoomValue)); } else { error.message = "GeoJSON source clusterMaxZoom value must be a number"; - return nullopt; + return std::nullopt; } } @@ -78,7 +78,7 @@ optional Converter::operator()(const Convertible options.clusterRadius = static_cast(*toNumber(*clusterRadiusValue)); } else { error.message = "GeoJSON source clusterRadius value must be a number"; - return nullopt; + return std::nullopt; } } @@ -88,7 +88,7 @@ optional Converter::operator()(const Convertible options.lineMetrics = *toBool(*lineMetricsValue); } else { error.message = "GeoJSON source lineMetrics value must be a boolean"; - return nullopt; + return std::nullopt; } } @@ -96,26 +96,26 @@ optional Converter::operator()(const Convertible if (clusterProperties) { if (!isObject(*clusterProperties)) { error.message = "GeoJSON source clusterProperties value must be an object"; - return nullopt; + return std::nullopt; } GeoJSONOptions::ClusterProperties result; assert(error.message.empty()); eachMember( *clusterProperties, [&](const std::string& k, - const mbgl::style::conversion::Convertible& v) -> optional { + const mbgl::style::conversion::Convertible& v) -> std::optional { // Each property shall be formed as ["key" : [operator, [mapExpression]]] // or ["key" : [[operator, ['accumulated'], ['get', key]], [mapExpression]]] if (!isArray(v) || arrayLength(v) != 2) { error.message = "GeoJSON source clusterProperties member must be an array with length of 2"; - return nullopt; + return std::nullopt; } auto map = expression::dsl::createExpression(arrayMember(v, 1)); if (!map) { error.message = "Failed to convert GeoJSON source clusterProperties map expression"; - return nullopt; + return std::nullopt; } std::unique_ptr reduce; if (isArray(arrayMember(v, 0))) { @@ -125,7 +125,7 @@ optional Converter::operator()(const Convertible if (!reduceOp) { error.message = "GeoJSON source clusterProperties member must contain a valid operator"; - return nullopt; + return std::nullopt; } std::stringstream ss; // Reformulate reduce expression to [operator, ['accumulated'], ['get', key]] @@ -140,13 +140,13 @@ optional Converter::operator()(const Convertible if (!reduce) { error.message = "Failed to convert GeoJSON source clusterProperties reduce expression"; - return nullopt; + return std::nullopt; } result.emplace(k, std::make_pair(std::move(map), std::move(reduce))); - return nullopt; + return std::nullopt; }); if (!error.message.empty()) { - return nullopt; + return std::nullopt; } options.clusterProperties = std::move(result); } diff --git a/src/mbgl/style/conversion/get_json_type.cpp b/src/mbgl/style/conversion/get_json_type.cpp index 06becbb12..cef5fa985 100644 --- a/src/mbgl/style/conversion/get_json_type.cpp +++ b/src/mbgl/style/conversion/get_json_type.cpp @@ -16,7 +16,7 @@ std::string getJSONType(const Convertible& value) { if (isObject(value)) { return "object"; } - optional v = toValue(value); + std::optional v = toValue(value); // Since we've already checked the non-atomic types above, value must then // be a string, number, or boolean -- thus, assume that the toValue() diff --git a/src/mbgl/style/conversion/json.hpp b/src/mbgl/style/conversion/json.hpp index 503f60a38..f10da67ab 100644 --- a/src/mbgl/style/conversion/json.hpp +++ b/src/mbgl/style/conversion/json.hpp @@ -10,7 +10,7 @@ namespace style { namespace conversion { template -optional convertJSON(const std::string& json, Error& error, Args&&...args) { +std::optional convertJSON(const std::string& json, Error& error, Args&&...args) { JSDocument document; document.Parse<0>(json.c_str()); diff --git a/src/mbgl/style/conversion/layer.cpp b/src/mbgl/style/conversion/layer.cpp index 50401d167..8842cc2ac 100644 --- a/src/mbgl/style/conversion/layer.cpp +++ b/src/mbgl/style/conversion/layer.cpp @@ -21,10 +21,10 @@ bool setObjectMember(std::unique_ptr& layer, const Convertible& value, co } } // namespace -optional setPaintProperties(Layer& layer, const Convertible& value) { +std::optional setPaintProperties(Layer& layer, const Convertible& value) { auto paintValue = objectMember(value, "paint"); if (!paintValue) { - return nullopt; + return std::nullopt; } if (!isObject(*paintValue)) { return { { "paint must be an object" } }; @@ -32,64 +32,64 @@ optional setPaintProperties(Layer& layer, const Convertible& value) { return eachMember(*paintValue, [&](const std::string& k, const Convertible& v) { return layer.setProperty(k, v); }); } -optional> Converter>::operator()(const Convertible& value, Error& error) const { +std::optional> Converter>::operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error.message = "layer must be an object"; - return nullopt; + return std::nullopt; } auto idValue = objectMember(value, "id"); if (!idValue) { error.message = "layer must have an id"; - return nullopt; + return std::nullopt; } - optional id = toString(*idValue); + std::optional id = toString(*idValue); if (!id) { error.message = "layer id must be a string"; - return nullopt; + return std::nullopt; } auto typeValue = objectMember(value, "type"); if (!typeValue) { error.message = "layer must have a type"; - return nullopt; + return std::nullopt; } - optional type = toString(*typeValue); + auto type = toString(*typeValue); if (!type) { error.message = "layer type must be a string"; - return nullopt; + return std::nullopt; } std::unique_ptr layer = LayerManager::get()->createLayer(*type, *id, value, error); - if (!layer) return nullopt; + if (!layer) return std::nullopt; - if (!setObjectMember(layer, value, "minzoom", error)) return nullopt; - if (!setObjectMember(layer, value, "maxzoom", error)) return nullopt; - if (!setObjectMember(layer, value, "filter", error)) return nullopt; + if (!setObjectMember(layer, value, "minzoom", error)) return std::nullopt; + if (!setObjectMember(layer, value, "maxzoom", error)) return std::nullopt; + if (!setObjectMember(layer, value, "filter", error)) return std::nullopt; if (layer->getTypeInfo()->source == LayerTypeInfo::Source::Required) { - if (!setObjectMember(layer, value, "source-layer", error)) return nullopt; + if (!setObjectMember(layer, value, "source-layer", error)) return std::nullopt; } auto layoutValue = objectMember(value, "layout"); if (layoutValue) { if (!isObject(*layoutValue)) { error.message = "layout must be an object"; - return nullopt; + return std::nullopt; } - optional error_ = eachMember( + auto error_ = eachMember( *layoutValue, [&](const std::string& k, const Convertible& v) { return layer->setProperty(k, v); }); if (error_) { error = *error_; - return nullopt; + return std::nullopt; } } - optional error_ = setPaintProperties(*layer, value); + auto error_ = setPaintProperties(*layer, value); if (error_) { error = *error_; - return nullopt; + return std::nullopt; } return layer; diff --git a/src/mbgl/style/conversion/light.cpp b/src/mbgl/style/conversion/light.cpp index e8723216e..e003ea052 100644 --- a/src/mbgl/style/conversion/light.cpp +++ b/src/mbgl/style/conversion/light.cpp @@ -8,103 +8,94 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error.message = "light must be an object"; - return nullopt; + return std::nullopt; } Light light; const auto anchor = objectMember(value, "anchor"); if (anchor) { - optional> convertedAnchor = - convert>(*anchor, error, false, false); - + auto convertedAnchor = convert>(*anchor, error, false, false); if (convertedAnchor) { light.setAnchor(*convertedAnchor); } else { - return nullopt; + return std::nullopt; } } const auto anchorTransition = objectMember(value, "anchor-transition"); if (anchorTransition) { - optional transition = - convert(*anchorTransition, error); + auto transition = convert(*anchorTransition, error); if (transition) { light.setAnchorTransition(*transition); } else { - return nullopt; + return std::nullopt; } } const auto color = objectMember(value, "color"); if (color) { - optional> convertedColor = - convert>(*color, error, false, false); + auto convertedColor = convert>(*color, error, false, false); if (convertedColor) { light.setColor(*convertedColor); } else { - return nullopt; + return std::nullopt; } } const auto colorTransition = objectMember(value, "color-transition"); if (colorTransition) { - optional transition = - convert(*colorTransition, error); + auto transition = convert(*colorTransition, error); if (transition) { light.setColorTransition(*transition); } else { - return nullopt; + return std::nullopt; } } const auto position = objectMember(value, "position"); if (position) { - optional> convertedPosition = - convert>(*position, error, false, false); + auto convertedPosition = convert>(*position, error, false, false); if (convertedPosition) { light.setPosition(*convertedPosition); } else { - return nullopt; + return std::nullopt; } } const auto positionTransition = objectMember(value, "position-transition"); if (positionTransition) { - optional transition = - convert(*positionTransition, error); + auto transition = convert(*positionTransition, error); if (transition) { light.setPositionTransition(*transition); } else { - return nullopt; + return std::nullopt; } } const auto intensity = objectMember(value, "intensity"); if (intensity) { - optional> convertedIntensity = - convert>(*intensity, error, false, false); + auto convertedIntensity = convert>(*intensity, error, false, false); if (convertedIntensity) { light.setIntensity(*convertedIntensity); } else { - return nullopt; + return std::nullopt; } } const auto intensityTransition = objectMember(value, "intensity-transition"); if (intensityTransition) { - optional transition = - convert(*intensityTransition, error); + auto transition = convert(*intensityTransition, error); if (transition) { light.setIntensityTransition(*transition); } else { - return nullopt; + return std::nullopt; } } diff --git a/src/mbgl/style/conversion/position.cpp b/src/mbgl/style/conversion/position.cpp index df6c868ee..975c4e2f9 100644 --- a/src/mbgl/style/conversion/position.cpp +++ b/src/mbgl/style/conversion/position.cpp @@ -8,11 +8,11 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { - optional> spherical = convert>(value, error); +std::optional Converter::operator()(const Convertible& value, Error& error) const { + std::optional> spherical = convert>(value, error); if (!spherical) { - return nullopt; + return std::nullopt; } return Position(*spherical); diff --git a/src/mbgl/style/conversion/property_value.cpp b/src/mbgl/style/conversion/property_value.cpp index 2fbeb4dd4..2357a3040 100644 --- a/src/mbgl/style/conversion/property_value.cpp +++ b/src/mbgl/style/conversion/property_value.cpp @@ -8,96 +8,96 @@ namespace style { namespace conversion { template -optional> Converter>::operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const { +std::optional> Converter>::operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const { using namespace mbgl::style::expression; if (isUndefined(value)) { return PropertyValue(); } - optional> expression; + std::optional> expression; if (isExpression(value)) { ParsingContext ctx(valueTypeToExpressionType()); ParseResult parsed = ctx.parseLayerPropertyExpression(value); if (!parsed) { error.message = ctx.getCombinedErrors(); - return nullopt; + return std::nullopt; } expression = PropertyExpression(std::move(*parsed)); } else if (isObject(value)) { expression = convertFunctionToExpression(value, error, convertTokens); } else { - optional constant = convert(value, error); + std::optional constant = convert(value, error); if (!constant) { - return nullopt; + return std::nullopt; } return convertTokens ? maybeConvertTokens(*constant) : PropertyValue(*constant); } if (!expression) { - return nullopt; + return std::nullopt; } else if (!allowDataExpressions && !(*expression).isFeatureConstant()) { error.message = "data expressions not supported"; - return nullopt; + return std::nullopt; } else if (!(*expression).isFeatureConstant() || !(*expression).isZoomConstant() || !(*expression).isRuntimeConstant()) { return { std::move(*expression) }; } else if ((*expression).getExpression().getKind() == Kind::Literal) { - optional constant = fromExpressionValue( + std::optional constant = fromExpressionValue( static_cast((*expression).getExpression()).getValue()); if (!constant) { - return nullopt; + return std::nullopt; } return PropertyValue(*constant); } else { assert(false); error.message = "expected a literal expression"; - return nullopt; + return std::nullopt; } } -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -template optional> +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional>> Converter>>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; +template std::optional> Converter>::operator()(conversion::Convertible const&, conversion::Error&, bool, bool) const; -optional>> +std::optional>> mbgl::style::conversion::Converter>, void>::operator()(const Convertible& value, Error& error, bool, bool) const { - optional> a = convert>(value, error); + std::optional> a = convert>(value, error); if (!a) { - return nullopt; + return std::nullopt; } std::array res; res[0] = (*a)[0]; @@ -108,7 +108,7 @@ mbgl::style::conversion::Converter>, void>:: return r; } -template optional> Converter>::operator()( +template std::optional> Converter>::operator()( conversion::Convertible const&, conversion::Error&, bool, bool) const; } // namespace conversion diff --git a/src/mbgl/style/conversion/rotation.cpp b/src/mbgl/style/conversion/rotation.cpp index 11431437d..f2fc5e033 100644 --- a/src/mbgl/style/conversion/rotation.cpp +++ b/src/mbgl/style/conversion/rotation.cpp @@ -6,11 +6,11 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { - optional converted = toDouble(value); +std::optional Converter::operator()(const Convertible& value, Error& error) const { + std::optional converted = toDouble(value); if (!converted) { error.message = "value must be a number"; - return nullopt; + return std::nullopt; } return {*converted}; } diff --git a/src/mbgl/style/conversion/source.cpp b/src/mbgl/style/conversion/source.cpp index a3ba8f3f5..55223a2a9 100644 --- a/src/mbgl/style/conversion/source.cpp +++ b/src/mbgl/style/conversion/source.cpp @@ -16,40 +16,40 @@ namespace style { namespace conversion { // A tile source can either specify a URL to TileJSON, or inline TileJSON. -static optional> convertURLOrTileset(const Convertible& value, Error& error) { +static std::optional> convertURLOrTileset(const Convertible& value, Error& error) { auto urlVal = objectMember(value, "url"); if (!urlVal) { - optional tileset = convert(value, error); + std::optional tileset = convert(value, error); if (!tileset) { - return nullopt; + return std::nullopt; } return { *tileset }; } - optional url = toString(*urlVal); + std::optional url = toString(*urlVal); if (!url) { error.message = "source url must be a string"; - return nullopt; + return std::nullopt; } return { *url }; } -static optional> convertRasterSource(const std::string& id, +static std::optional> convertRasterSource(const std::string& id, const Convertible& value, Error& error) { - optional> urlOrTileset = convertURLOrTileset(value, error); + std::optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { - return nullopt; + return std::nullopt; } uint16_t tileSize = util::tileSize_I; auto tileSizeValue = objectMember(value, "tileSize"); if (tileSizeValue) { - optional size = toNumber(*tileSizeValue); + std::optional size = toNumber(*tileSizeValue); if (!size || *size < 0 || *size > std::numeric_limits::max()) { error.message = "invalid tileSize"; - return nullopt; + return std::nullopt; } tileSize = static_cast(*size); } @@ -57,21 +57,21 @@ static optional> convertRasterSource(const std::string& return { std::make_unique(id, std::move(*urlOrTileset), tileSize) }; } -static optional> convertRasterDEMSource(const std::string& id, +static std::optional> convertRasterDEMSource(const std::string& id, const Convertible& value, Error& error) { - optional> urlOrTileset = convertURLOrTileset(value, error); + std::optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { - return nullopt; + return std::nullopt; } uint16_t tileSize = util::tileSize_I; auto tileSizeValue = objectMember(value, "tileSize"); if (tileSizeValue) { - optional size = toNumber(*tileSizeValue); + std::optional size = toNumber(*tileSizeValue); if (!size || *size < 0 || *size > std::numeric_limits::max()) { error.message = "invalid tileSize"; - return nullopt; + return std::nullopt; } tileSize = static_cast(*size); } @@ -79,97 +79,97 @@ static optional> convertRasterDEMSource(const std::strin return { std::make_unique(id, std::move(*urlOrTileset), tileSize) }; } -static optional> convertVectorSource(const std::string& id, +static std::optional> convertVectorSource(const std::string& id, const Convertible& value, Error& error) { - optional> urlOrTileset = convertURLOrTileset(value, error); + std::optional> urlOrTileset = convertURLOrTileset(value, error); if (!urlOrTileset) { - return nullopt; + return std::nullopt; } auto maxzoomValue = objectMember(value, "maxzoom"); - optional maxzoom; + std::optional maxzoom; if (maxzoomValue) { maxzoom = toNumber(*maxzoomValue); if (!maxzoom || *maxzoom < 0 || *maxzoom > std::numeric_limits::max()) { error.message = "invalid maxzoom"; - return nullopt; + return std::nullopt; } } auto minzoomValue = objectMember(value, "minzoom"); - optional minzoom; + std::optional minzoom; if (minzoomValue) { minzoom = toNumber(*minzoomValue); if (!minzoom || *minzoom < 0 || *minzoom > std::numeric_limits::max()) { error.message = "invalid minzoom"; - return nullopt; + return std::nullopt; } } return {std::make_unique(id, std::move(*urlOrTileset), std::move(maxzoom), std::move(minzoom))}; } -static optional> convertGeoJSONSource(const std::string& id, +static std::optional> convertGeoJSONSource(const std::string& id, const Convertible& value, Error& error) { auto dataValue = objectMember(value, "data"); if (!dataValue) { error.message = "GeoJSON source must have a data value"; - return nullopt; + return std::nullopt; } Immutable options = GeoJSONOptions::defaultOptions(); - if (optional converted = convert(value, error)) { + if (std::optional converted = convert(value, error)) { options = makeMutable(std::move(*converted)); } auto result = std::make_unique(id, std::move(options)); if (isObject(*dataValue)) { - optional geoJSON = convert(*dataValue, error); + auto geoJSON = convert(*dataValue, error); if (!geoJSON) { - return nullopt; + return std::nullopt; } result->setGeoJSON(*geoJSON); } else if (toString(*dataValue)) { result->setURL(*toString(*dataValue)); } else { error.message = "GeoJSON data must be a URL or an object"; - return nullopt; + return std::nullopt; } return { std::move(result) }; } -static optional> convertImageSource(const std::string& id, +static std::optional> convertImageSource(const std::string& id, const Convertible& value, Error& error) { auto urlValue = objectMember(value, "url"); if (!urlValue) { error.message = "Image source must have a url value"; - return nullopt; + return std::nullopt; } auto urlString = toString(*urlValue); if (!urlString) { error.message = "Image url must be a URL string"; - return nullopt; + return std::nullopt; } auto coordinatesValue = objectMember(value, "coordinates"); if (!coordinatesValue) { error.message = "Image source must have a coordinates values"; - return nullopt; + return std::nullopt; } if (!isArray(*coordinatesValue) || arrayLength(*coordinatesValue) != 4) { error.message = "Image coordinates must be an array of four longitude latitude pairs"; - return nullopt; + return std::nullopt; } std::array coordinates; for (std::size_t i=0; i < 4; i++) { auto latLng = conversion::convert(arrayMember(*coordinatesValue,i), error); if (!latLng) { - return nullopt; + return std::nullopt; } coordinates[i] = *latLng; } @@ -179,22 +179,22 @@ static optional> convertImageSource(const std::string& i return { std::move(result) }; } -optional> Converter>::operator()(const Convertible& value, Error& error, const std::string& id) const { +std::optional> Converter>::operator()(const Convertible& value, Error& error, const std::string& id) const { if (!isObject(value)) { error.message = "source must be an object"; - return nullopt; + return std::nullopt; } auto typeValue = objectMember(value, "type"); if (!typeValue) { error.message = "source must have a type"; - return nullopt; + return std::nullopt; } - optional type = toString(*typeValue); + std::optional type = toString(*typeValue); if (!type) { error.message = "source type must be a string"; - return nullopt; + return std::nullopt; } const std::string& tname = type.value(); if (tname == "raster") { @@ -209,7 +209,7 @@ optional> Converter>::operator() return convertImageSource(id, value, error); } else { error.message = "invalid source type"; - return nullopt; + return std::nullopt; } } diff --git a/src/mbgl/style/conversion/tileset.cpp b/src/mbgl/style/conversion/tileset.cpp index 567024d36..a64f2f961 100644 --- a/src/mbgl/style/conversion/tileset.cpp +++ b/src/mbgl/style/conversion/tileset.cpp @@ -7,32 +7,32 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { Tileset result; auto tiles = objectMember(value, "tiles"); if (!tiles) { error.message = "source must have tiles"; - return nullopt; + return std::nullopt; } if (!isArray(*tiles)) { error.message = "source tiles must be an array"; - return nullopt; + return std::nullopt; } for (std::size_t i = 0; i < arrayLength(*tiles); i++) { - optional urlTemplate = toString(arrayMember(*tiles, i)); + std::optional urlTemplate = toString(arrayMember(*tiles, i)); if (!urlTemplate) { error.message = "source tiles member must be a string"; - return nullopt; + return std::nullopt; } result.tiles.push_back(std::move(*urlTemplate)); } auto schemeValue = objectMember(value, "scheme"); if (schemeValue) { - optional scheme = toString(*schemeValue); + std::optional scheme = toString(*schemeValue); if (scheme && *scheme == "tms") { result.scheme = Tileset::Scheme::TMS; } @@ -40,7 +40,7 @@ optional Converter::operator()(const Convertible& value, Error auto encodingValue = objectMember(value, "encoding"); if (encodingValue) { - optional encoding = toString(*encodingValue); + std::optional encoding = toString(*encodingValue); if (encoding && *encoding == "terrarium") { result.encoding = Tileset::DEMEncoding::Terrarium; } else if (encoding && *encoding != "mapbox") { @@ -50,30 +50,30 @@ optional Converter::operator()(const Convertible& value, Error auto minzoomValue = objectMember(value, "minzoom"); if (minzoomValue) { - optional minzoom = toNumber(*minzoomValue); + std::optional minzoom = toNumber(*minzoomValue); if (!minzoom || *minzoom < 0 || *minzoom > std::numeric_limits::max()) { error.message = "invalid minzoom"; - return nullopt; + return std::nullopt; } result.zoomRange.min = static_cast(*minzoom); } auto maxzoomValue = objectMember(value, "maxzoom"); if (maxzoomValue) { - optional maxzoom = toNumber(*maxzoomValue); + std::optional maxzoom = toNumber(*maxzoomValue); if (!maxzoom || *maxzoom < 0 || *maxzoom > std::numeric_limits::max()) { error.message = "invalid maxzoom"; - return nullopt; + return std::nullopt; } result.zoomRange.max = static_cast(*maxzoom); } auto attributionValue = objectMember(value, "attribution"); if (attributionValue) { - optional attribution = toString(*attributionValue); + std::optional attribution = toString(*attributionValue); if (!attribution) { error.message = "source attribution must be a string"; - return nullopt; + return std::nullopt; } result.attribution = std::move(*attribution); } @@ -82,28 +82,28 @@ optional Converter::operator()(const Convertible& value, Error if (boundsValue) { if (!isArray(*boundsValue) || arrayLength(*boundsValue) != 4) { error.message = "bounds must be an array with left, bottom, top, and right values"; - return nullopt; + return std::nullopt; } - optional left = toDouble(arrayMember(*boundsValue, 0)); - optional bottom = toDouble(arrayMember(*boundsValue, 1)); - optional right = toDouble(arrayMember(*boundsValue, 2)); - optional top = toDouble(arrayMember(*boundsValue, 3)); + std::optional left = toDouble(arrayMember(*boundsValue, 0)); + std::optional bottom = toDouble(arrayMember(*boundsValue, 1)); + std::optional right = toDouble(arrayMember(*boundsValue, 2)); + std::optional top = toDouble(arrayMember(*boundsValue, 3)); if (!left || !right || !bottom || !top) { error.message = "bounds array must contain numeric longitude and latitude values"; - return nullopt; + return std::nullopt; } bottom = util::clamp(*bottom, -90.0, 90.0); top = util::clamp(*top, -90.0, 90.0); if (*top < *bottom){ error.message = "bounds bottom latitude must be less than or equal to top latitude"; - return nullopt; + return std::nullopt; } if(*left > *right) { error.message = "bounds left longitude must be less than or equal to right longitude"; - return nullopt; + return std::nullopt; } left = util::max(-180.0, *left); right = util::min(180.0, *right); diff --git a/src/mbgl/style/conversion/transition_options.cpp b/src/mbgl/style/conversion/transition_options.cpp index 6e39dca24..f41e13800 100644 --- a/src/mbgl/style/conversion/transition_options.cpp +++ b/src/mbgl/style/conversion/transition_options.cpp @@ -5,20 +5,20 @@ namespace mbgl { namespace style { namespace conversion { -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { if (!isObject(value)) { error.message = "transition must be an object"; - return nullopt; + return std::nullopt; } - optional result = TransitionOptions{}; + std::optional result = TransitionOptions{}; auto duration = objectMember(value, "duration"); if (duration) { auto number = toNumber(*duration); if (!number) { error.message = "duration must be a number"; - return nullopt; + return std::nullopt; } result->duration = { std::chrono::milliseconds(int64_t(*number)) }; } @@ -28,7 +28,7 @@ optional Converter::operator()(const Conve auto number = toNumber(*delay); if (!number) { error.message = "delay must be a number"; - return nullopt; + return std::nullopt; } result->delay = { std::chrono::milliseconds(int64_t(*number)) }; } diff --git a/src/mbgl/style/expression/assertion.cpp b/src/mbgl/style/expression/assertion.cpp index c20b3edd8..982557aed 100644 --- a/src/mbgl/style/expression/assertion.cpp +++ b/src/mbgl/style/expression/assertion.cpp @@ -34,9 +34,9 @@ ParseResult Assertion::parse(const Convertible& value, ParsingContext& ctx) { std::string name = *toString(arrayMember(value, 0)); if (name == "array") { - optional itemType; + std::optional itemType; if (length > 2) { - optional itemTypeName = toString(arrayMember(value, 1)); + std::optional itemTypeName = toString(arrayMember(value, 1)); auto it = itemTypeName ? types.find(*itemTypeName) : types.end(); if (it == types.end() || it->second == type::Object) { ctx.error( @@ -51,10 +51,10 @@ ParseResult Assertion::parse(const Convertible& value, ParsingContext& ctx) { itemType = {type::Value}; } - optional N; + std::optional N; if (length > 3) { auto m = arrayMember(value, 2); - optional n = toNumber(m); + std::optional n = toNumber(m); if (!isUndefined(m) && (!n || *n < 0 || *n != std::floor(*n))) { ctx.error( @@ -121,8 +121,8 @@ bool Assertion::operator==(const Expression& e) const { return false; } -std::vector> Assertion::possibleOutputs() const { - std::vector> result; +std::vector> Assertion::possibleOutputs() const { + std::vector> result; for (const auto& input : inputs) { for (auto& output : input->possibleOutputs()) { result.push_back(std::move(output)); diff --git a/src/mbgl/style/expression/boolean_operator.cpp b/src/mbgl/style/expression/boolean_operator.cpp index 6beae6062..37ebc02c7 100644 --- a/src/mbgl/style/expression/boolean_operator.cpp +++ b/src/mbgl/style/expression/boolean_operator.cpp @@ -28,7 +28,7 @@ bool Any::operator==(const Expression& e) const { return false; } -std::vector> Any::possibleOutputs() const { +std::vector> Any::possibleOutputs() const { return {{ true }, { false }}; } @@ -56,7 +56,7 @@ bool All::operator==(const Expression& e) const { return false; } -std::vector> All::possibleOutputs() const { +std::vector> All::possibleOutputs() const { return {{ true }, { false }}; } diff --git a/src/mbgl/style/expression/case.cpp b/src/mbgl/style/expression/case.cpp index 314551592..e8e7c64b7 100644 --- a/src/mbgl/style/expression/case.cpp +++ b/src/mbgl/style/expression/case.cpp @@ -36,8 +36,8 @@ bool Case::operator==(const Expression& e) const { return false; } -std::vector> Case::possibleOutputs() const { - std::vector> result; +std::vector> Case::possibleOutputs() const { + std::vector> result; for (const auto& branch : branches) { for (auto& output : branch.second->possibleOutputs()) { result.push_back(std::move(output)); @@ -64,7 +64,7 @@ ParseResult Case::parse(const Convertible& value, ParsingContext& ctx) { return ParseResult(); } - optional outputType; + std::optional outputType; if (ctx.getExpected() && *ctx.getExpected() != type::Value) { outputType = ctx.getExpected(); } diff --git a/src/mbgl/style/expression/check_subtype.cpp b/src/mbgl/style/expression/check_subtype.cpp index 9895bce66..9f8686765 100644 --- a/src/mbgl/style/expression/check_subtype.cpp +++ b/src/mbgl/style/expression/check_subtype.cpp @@ -10,11 +10,11 @@ std::string errorMessage(const Type& expected, const Type& t) { return {"Expected " + toString(expected) + " but found " + toString(t) + " instead."}; } -optional checkSubtype(const Type& expected, const Type& t) { +std::optional checkSubtype(const Type& expected, const Type& t) { if (t.is()) return {}; - optional result = expected.match( - [&] (const Array& expectedArray) -> optional { + std::optional result = expected.match( + [&] (const Array& expectedArray) -> std::optional { if (!t.is()) { return {errorMessage(expected, t)}; } @@ -30,7 +30,7 @@ optional checkSubtype(const Type& expected, const Type& t) { } return {}; }, - [&] (const ValueType&) -> optional { + [&] (const ValueType&) -> std::optional { if (t.is()) return {}; const Type members[] = {Null, Boolean, Number, String, Object, Color, Formatted, Image, Array(Value)}; @@ -43,7 +43,7 @@ optional checkSubtype(const Type& expected, const Type& t) { } return { errorMessage(expected, t) }; }, - [&] (const auto&) -> optional { + [&] (const auto&) -> std::optional { if (expected != t) { return { errorMessage(expected, t) }; } diff --git a/src/mbgl/style/expression/coalesce.cpp b/src/mbgl/style/expression/coalesce.cpp index ab30e7a8d..71cb9ae0e 100644 --- a/src/mbgl/style/expression/coalesce.cpp +++ b/src/mbgl/style/expression/coalesce.cpp @@ -9,7 +9,7 @@ namespace expression { EvaluationResult Coalesce::evaluate(const EvaluationContext& params) const { EvaluationResult result = Null; std::size_t argsCount = args.size(); - optional requestedImage; + std::optional requestedImage; for (const auto& arg : args) { --argsCount; result = arg->evaluate(params); @@ -43,8 +43,8 @@ bool Coalesce::operator==(const Expression& e) const { return false; } -std::vector> Coalesce::possibleOutputs() const { - std::vector> result; +std::vector> Coalesce::possibleOutputs() const { + std::vector> result; for (const auto& arg : args) { for (auto& output : arg->possibleOutputs()) { result.push_back(std::move(output)); @@ -62,8 +62,8 @@ ParseResult Coalesce::parse(const Convertible& value, ParsingContext& ctx) { return ParseResult(); } - optional outputType; - optional expectedType = ctx.getExpected(); + std::optional outputType; + std::optional expectedType = ctx.getExpected(); if (expectedType && *expectedType != type::Value) { outputType = expectedType; } diff --git a/src/mbgl/style/expression/coercion.cpp b/src/mbgl/style/expression/coercion.cpp index 5cfe6c2b4..e04a86d03 100644 --- a/src/mbgl/style/expression/coercion.cpp +++ b/src/mbgl/style/expression/coercion.cpp @@ -18,17 +18,17 @@ EvaluationResult toBoolean(const Value& v) { } EvaluationResult toNumber(const Value& v) { - optional result = v.match( - [](NullValue) -> optional { return 0.0; }, - [](const double f) -> optional { return f; }, - [](const std::string& s) -> optional { + std::optional result = v.match( + [](NullValue) -> std::optional { return 0.0; }, + [](const double f) -> std::optional { return f; }, + [](const std::string& s) -> std::optional { try { return util::stof(s); } catch (...) { return {}; } }, - [](const auto&) { return optional(); } + [](const auto&) { return std::optional(); } ); if (!result) { return EvaluationError { @@ -44,7 +44,7 @@ EvaluationResult toColor(const Value& colorValue) { return color; }, [&](const std::string& colorString) -> EvaluationResult { - const optional result = Color::parse(colorString); + const std::optional result = Color::parse(colorString); if (result) { return *result; } else { @@ -207,8 +207,8 @@ bool Coercion::operator==(const Expression& e) const { return false; } -std::vector> Coercion::possibleOutputs() const { - std::vector> result; +std::vector> Coercion::possibleOutputs() const { + std::vector> result; for (const auto& input : inputs) { for (auto& output : input->possibleOutputs()) { result.push_back(std::move(output)); diff --git a/src/mbgl/style/expression/collator.cpp b/src/mbgl/style/expression/collator.cpp index a5dbc614a..dc68df5ee 100644 --- a/src/mbgl/style/expression/collator.cpp +++ b/src/mbgl/style/expression/collator.cpp @@ -4,7 +4,7 @@ namespace mbgl { namespace style { namespace expression { -Collator::Collator(bool caseSensitive, bool diacriticSensitive, const optional& locale) +Collator::Collator(bool caseSensitive, bool diacriticSensitive, const std::optional& locale) : collator(platform::Collator(caseSensitive, diacriticSensitive, locale)) {} bool Collator::operator==(const Collator& other) const { diff --git a/src/mbgl/style/expression/collator_expression.cpp b/src/mbgl/style/expression/collator_expression.cpp index 07346633a..5e489c514 100644 --- a/src/mbgl/style/expression/collator_expression.cpp +++ b/src/mbgl/style/expression/collator_expression.cpp @@ -10,7 +10,7 @@ namespace expression { CollatorExpression::CollatorExpression(std::unique_ptr caseSensitive_, std::unique_ptr diacriticSensitive_, - optional> locale_) + std::optional> locale_) : Expression(Kind::CollatorExpression, type::Collator) , caseSensitive(std::move(caseSensitive_)) , diacriticSensitive(std::move(diacriticSensitive_)) @@ -31,7 +31,7 @@ ParseResult CollatorExpression::parse(const Convertible& value, ParsingContext& return ParseResult(); } - const optional caseSensitiveOption = objectMember(options, "case-sensitive"); + const std::optional caseSensitiveOption = objectMember(options, "case-sensitive"); ParseResult caseSensitive; if (caseSensitiveOption) { caseSensitive = ctx.parse(*caseSensitiveOption, 1, {type::Boolean}); @@ -42,7 +42,7 @@ ParseResult CollatorExpression::parse(const Convertible& value, ParsingContext& return ParseResult(); } - const optional diacriticSensitiveOption = objectMember(options, "diacritic-sensitive"); + const std::optional diacriticSensitiveOption = objectMember(options, "diacritic-sensitive"); ParseResult diacriticSensitive; if (diacriticSensitiveOption) { diacriticSensitive = ctx.parse(*diacriticSensitiveOption, 1, {type::Boolean}); @@ -53,7 +53,7 @@ ParseResult CollatorExpression::parse(const Convertible& value, ParsingContext& return ParseResult(); } - const optional localeOption = objectMember(options, "locale"); + const std::optional localeOption = objectMember(options, "locale"); ParseResult locale; if (localeOption) { locale = ctx.parse(*localeOption, 1, {type::String}); diff --git a/src/mbgl/style/expression/comparison.cpp b/src/mbgl/style/expression/comparison.cpp index ca29ace0d..4fe4c5899 100644 --- a/src/mbgl/style/expression/comparison.cpp +++ b/src/mbgl/style/expression/comparison.cpp @@ -156,7 +156,7 @@ bool BasicComparison::operator==(const Expression& e) const { return false; } -std::vector> BasicComparison::possibleOutputs() const { +std::vector> BasicComparison::possibleOutputs() const { return {{ true }, { false }}; } @@ -217,7 +217,7 @@ bool CollatorComparison::operator==(const Expression& e) const { return false; } -std::vector> CollatorComparison::possibleOutputs() const { +std::vector> CollatorComparison::possibleOutputs() const { return {{ true }, { false }}; } diff --git a/src/mbgl/style/expression/compound_expression.cpp b/src/mbgl/style/expression/compound_expression.cpp index 0a5c2ba3c..a814343c9 100644 --- a/src/mbgl/style/expression/compound_expression.cpp +++ b/src/mbgl/style/expression/compound_expression.cpp @@ -222,58 +222,58 @@ Value featureIdAsExpressionValue(const EvaluationContext& params) { }); }; -optional featurePropertyAsExpressionValue(const EvaluationContext& params, const std::string& key) { +std::optional featurePropertyAsExpressionValue(const EvaluationContext& params, const std::string& key) { assert(params.feature); auto property = params.feature->getValue(key); - return property ? optional(toExpressionValue(*property)) : optional(); + return property ? std::optional(toExpressionValue(*property)) : std::optional(); }; -optional featureTypeAsString(FeatureType type) { +std::optional featureTypeAsString(FeatureType type) { switch(type) { case FeatureType::Point: - return optional("Point"); + return std::optional("Point"); case FeatureType::LineString: - return optional("LineString"); + return std::optional("LineString"); case FeatureType::Polygon: - return optional("Polygon"); + return std::optional("Polygon"); case FeatureType::Unknown: - return optional("Unknown"); + return std::optional("Unknown"); default: return {}; } }; -optional featurePropertyAsDouble(const EvaluationContext& params, const std::string& key) { +std::optional featurePropertyAsDouble(const EvaluationContext& params, const std::string& key) { assert(params.feature); auto property = params.feature->getValue(key); if (!property) return {}; return property->match([](double value) { return value; }, - [](uint64_t value) -> optional { return {static_cast(value)}; }, - [](int64_t value) -> optional { return {static_cast(value)}; }, - [](const auto&) -> optional { return {}; }); + [](uint64_t value) -> std::optional { return {static_cast(value)}; }, + [](int64_t value) -> std::optional { return {static_cast(value)}; }, + [](const auto&) -> std::optional { return std::nullopt; }); }; -optional featurePropertyAsString(const EvaluationContext& params, const std::string& key) { +std::optional featurePropertyAsString(const EvaluationContext& params, const std::string& key) { assert(params.feature); auto property = params.feature->getValue(key); if (!property) return {}; return property->match([](std::string value) { return value; }, - [](const auto&) { return optional(); }); + [](const auto&) { return std::optional(); }); }; -optional featureIdAsDouble(const EvaluationContext& params) { +std::optional featureIdAsDouble(const EvaluationContext& params) { assert(params.feature); auto id = params.feature->getID(); return id.match([](double value) { return value; }, - [](uint64_t value) -> optional { return {static_cast(value)}; }, - [](int64_t value) -> optional { return {static_cast(value)}; }, - [](const auto&) -> optional { return {}; }); + [](uint64_t value) -> std::optional { return {static_cast(value)}; }, + [](int64_t value) -> std::optional { return {static_cast(value)}; }, + [](const auto&) -> std::optional { return std::nullopt; }); }; -optional featureIdAsString(const EvaluationContext& params) { +std::optional featureIdAsString(const EvaluationContext& params) { assert(params.feature); auto id = params.feature->getID(); - return id.match([](std::string value) { return value; }, [](const auto&) { return optional(); }); + return id.match([](std::string value) { return value; }, [](const auto&) { return std::optional(); }); }; const auto& eCompoundExpression() { @@ -862,7 +862,7 @@ const auto& filterHasIdCompoundExpression() { const auto& filterTypeInCompoundExpression() { static auto signature = detail::makeSignature("filter-type-in", [](const EvaluationContext& params, const Varargs& types) -> Result { assert(params.feature); - optional type = featureTypeAsString(params.feature->getType()); + std::optional type = featureTypeAsString(params.feature->getType()); return std::find(types.begin(), types.end(), type) != types.end(); }); return signature; @@ -1036,7 +1036,7 @@ static ParseResult createCompoundExpression(const Definitions& definitions, for (std::size_t i = 0; i < args.size(); i++) { const std::unique_ptr& arg = args[i]; - optional err = type::checkSubtype(params.at(i), arg->getType()); + std::optional err = type::checkSubtype(params.at(i), arg->getType()); if (err) { signatureContext.error(*err, i + 1); } @@ -1045,7 +1045,7 @@ static ParseResult createCompoundExpression(const Definitions& definitions, const type::Type& paramType = signature->params.get().type; for (std::size_t i = 0; i < args.size(); i++) { const std::unique_ptr& arg = args[i]; - optional err = type::checkSubtype(paramType, arg->getType()); + std::optional err = type::checkSubtype(paramType, arg->getType()); if (err) { signatureContext.error(*err, i + 1); } @@ -1095,7 +1095,7 @@ ParseResult parseCompoundExpression(const std::string& name, const Convertible& args.reserve(length - 1); for (std::size_t i = 1; i < length; i++) { - optional expected = signature->params.match( + std::optional expected = signature->params.match( [](const VarargsType& varargs) { return varargs.type; }, [&](const std::vector& params_) { return params_[i - 1]; } ); @@ -1159,13 +1159,13 @@ EvaluationResult CompoundExpression::evaluate(const EvaluationContext& evaluatio return signature.apply(evaluationParams, args); } -optional CompoundExpression::getParameterCount() const { - return signature.params.match([&](const VarargsType&) -> optional { return {}; }, - [&](const std::vector& p) -> optional { return p.size(); }); +std::optional CompoundExpression::getParameterCount() const { + return signature.params.match([&](const VarargsType&) -> std::optional { return std::nullopt; }, + [&](const std::vector& p) -> std::optional { return p.size(); }); } -std::vector> CompoundExpression::possibleOutputs() const { - return { nullopt }; +std::vector> CompoundExpression::possibleOutputs() const { + return { std::nullopt }; } void CompoundExpression::eachChild(const std::function& visit) const { diff --git a/src/mbgl/style/expression/distance.cpp b/src/mbgl/style/expression/distance.cpp index 3072ab0c1..d5cbdfd9f 100644 --- a/src/mbgl/style/expression/distance.cpp +++ b/src/mbgl/style/expression/distance.cpp @@ -41,12 +41,12 @@ bool isRangeSafe(const IndexRange& range, const std::size_t threshold) { return ret; } -std::pair, mbgl::optional> splitRange(const IndexRange& range, bool isLine) { - if (range.first > range.second) return std::make_pair(nullopt, nullopt); +std::pair, std::optional> splitRange(const IndexRange& range, bool isLine) { + if (range.first > range.second) return std::make_pair(std::nullopt, std::nullopt); auto size = getRangeSize(range); if (isLine) { if (size == 2) { - return std::make_pair(range, nullopt); + return std::make_pair(range, std::nullopt); } auto size1 = size / 2; IndexRange range1(range.first, range.first + size1); @@ -54,7 +54,7 @@ std::pair, mbgl::optional> splitRange(con return std::make_pair(std::move(range1), std::move(range2)); } else { if (size == 1) { - return std::make_pair(range, nullopt); + return std::make_pair(range, std::nullopt); } auto size1 = size / 2 - 1; IndexRange range1(range.first, range.first + size1); @@ -340,7 +340,7 @@ double pointsToPolygonDistance(const mapbox::geometry::multi_point& poin } else { auto newRangesA = splitRange(range, false /*isLine*/); const auto updateQueue = - [&distQueue, &miniDist, &ruler, &points, &polyBBox](mbgl::optional& rangeA) { + [&distQueue, &miniDist, &ruler, &points, &polyBBox](std::optional& rangeA) { if (!rangeA) return; auto tempDist = bboxToBBoxDistance(getBBox(points, *rangeA), polyBBox, ruler); // Insert new pair to the queue if the bbox distance is less than miniDist, @@ -380,7 +380,7 @@ double lineToPolygonDistance(const mapbox::geometry::line_string& line, } else { auto newRangesA = splitRange(range, true /*isLine*/); const auto updateQueue = - [&distQueue, &miniDist, &ruler, &line, &polyBBox](mbgl::optional& rangeA) { + [&distQueue, &miniDist, &ruler, &line, &polyBBox](std::optional& rangeA) { if (!rangeA) return; auto tempDist = bboxToBBoxDistance(getBBox(line, *rangeA), polyBBox, ruler); // Insert new pair to the queue if the bbox distance is less than miniDist, @@ -421,7 +421,7 @@ double lineToLineDistance(const mapbox::geometry::line_string& line1, auto newRangesA = splitRange(rangeA, true /*isLine*/); auto newRangesB = splitRange(rangeB, true /*isLine*/); const auto updateQueue = [&distQueue, &miniDist, &ruler, &line1, &line2]( - mbgl::optional& range1, mbgl::optional& range2) { + std::optional& range1, std::optional& range2) { if (!range1 || !range2) return; auto tempDist = bboxToBBoxDistance(getBBox(line1, *range1), getBBox(line2, *range2), ruler); // Insert new pair to the queue if the bbox distance is less than miniDist, @@ -465,7 +465,7 @@ double pointsToPointsDistance(const mapbox::geometry::multi_point& point auto newRangesA = splitRange(rangeA, false /*isLine*/); auto newRangesB = splitRange(rangeB, false /*isLine*/); const auto updateQueue = [&distQueue, &miniDist, &ruler, &pointSet1, &pointSet2]( - mbgl::optional& range1, mbgl::optional& range2) { + std::optional& range1, std::optional& range2) { if (!range1 || !range2) return; auto tempDist = bboxToBBoxDistance(getBBox(pointSet1, *range1), getBBox(pointSet2, *range2), ruler); // Insert new pair to the queue if the bbox distance is less than miniDist, @@ -515,7 +515,7 @@ double pointsToLineDistance(const mapbox::geometry::multi_point& points, auto newRangesA = splitRange(rangeA, false /*isLine*/); auto newRangesB = splitRange(rangeB, true /*isLine*/); const auto updateQueue = [&distQueue, &miniDist, &ruler, &points, &line]( - mbgl::optional& range1, mbgl::optional& range2) { + std::optional& range1, std::optional& range2) { if (!range1 || !range2) return; auto tempDist = bboxToBBoxDistance(getBBox(points, *range1), getBBox(line, *range2), ruler); // Insert new pair to the queue if the bbox distance is less than miniDist, @@ -718,14 +718,14 @@ double calculateDistance(const GeometryTileFeature& feature, [](const auto&) -> double { return InvalidDistance; }); } -optional parseValue(const style::conversion::Convertible& value, style::expression::ParsingContext& ctx) { +std::optional parseValue(const style::conversion::Convertible& value, style::expression::ParsingContext& ctx) { if (isArray(value)) { // object value, quoted with ["distance", GeoJSONObj] auto length = arrayLength(value); if (length != 2) { ctx.error("'distance' expression requires one argument, but found " + util::toString(arrayLength(value) - 1) + " instead."); - return nullopt; + return std::nullopt; } // Parse geometry info @@ -740,17 +740,17 @@ optional parseValue(const style::conversion::Convertible& value, style: } } ctx.error("'distance' expression needs to be an array with format [\"distance\", GeoJSONObj]."); - return nullopt; + return std::nullopt; } -optional getGeometry(const Feature& feature, mbgl::style::expression::ParsingContext& ctx) { +std::optional getGeometry(const Feature& feature, mbgl::style::expression::ParsingContext& ctx) { const auto type = apply_visitor(ToFeatureType(), feature.geometry); if (type == FeatureType::Point || type == FeatureType::LineString || type == FeatureType::Polygon) { return feature.geometry; } ctx.error( "'distance' expression requires valid geojson object with valid geometry type: Point, LineString or Polygon."); - return nullopt; + return std::nullopt; } } // namespace @@ -870,8 +870,8 @@ bool Distance::operator==(const Expression& e) const { return false; } -std::vector> Distance::possibleOutputs() const { - return {nullopt}; +std::vector> Distance::possibleOutputs() const { + return { std::nullopt }; } std::string Distance::getOperator() const { diff --git a/src/mbgl/style/expression/expression.cpp b/src/mbgl/style/expression/expression.cpp index 28004bb3e..ce07d4643 100644 --- a/src/mbgl/style/expression/expression.cpp +++ b/src/mbgl/style/expression/expression.cpp @@ -10,7 +10,7 @@ namespace expression { class GeoJSONFeature : public GeometryTileFeature { public: const Feature& feature; - mutable optional geometry; + mutable std::optional geometry; explicit GeoJSONFeature(const Feature& feature_) : feature(feature_) {} GeoJSONFeature(const Feature& feature_, const CanonicalTileID& canonical) : feature(feature_) { @@ -25,12 +25,12 @@ public: const PropertyMap& getProperties() const override { return feature.properties; } FeatureIdentifier getID() const override { return feature.id; } - optional getValue(const std::string& key) const override { + std::optional getValue(const std::string& key) const override { auto it = feature.properties.find(key); if (it != feature.properties.end()) { - return optional(it->second); + return std::optional(it->second); } - return optional(); + return std::optional(); } const GeometryCollection& getGeometries() const override { if (geometry) return *geometry; @@ -42,25 +42,25 @@ private: FeatureType getTypeImpl() const { return apply_visitor(ToFeatureType(), feature.geometry); } }; -EvaluationResult Expression::evaluate(optional zoom, +EvaluationResult Expression::evaluate(std::optional zoom, const Feature& feature, - optional colorRampParameter) const { + std::optional colorRampParameter) const { GeoJSONFeature f(feature); return this->evaluate(EvaluationContext(std::move(zoom), &f, std::move(colorRampParameter))); } -EvaluationResult Expression::evaluate(optional zoom, +EvaluationResult Expression::evaluate(std::optional zoom, const Feature& feature, - optional colorRampParameter, + std::optional colorRampParameter, const std::set& availableImages) const { GeoJSONFeature f(feature); return this->evaluate( EvaluationContext(std::move(zoom), &f, std::move(colorRampParameter)).withAvailableImages(&availableImages)); } -EvaluationResult Expression::evaluate(optional zoom, +EvaluationResult Expression::evaluate(std::optional zoom, const Feature& feature, - optional colorRampParameter, + std::optional colorRampParameter, const std::set& availableImages, const CanonicalTileID& canonical) const { GeoJSONFeature f(feature, canonical); @@ -69,7 +69,7 @@ EvaluationResult Expression::evaluate(optional zoom, .withCanonicalTileID(&canonical)); } -EvaluationResult Expression::evaluate(optional accumulated, const Feature& feature) const { +EvaluationResult Expression::evaluate(std::optional accumulated, const Feature& feature) const { GeoJSONFeature f(feature); return this->evaluate(EvaluationContext(std::move(accumulated), &f)); } diff --git a/src/mbgl/style/expression/find_zoom_curve.cpp b/src/mbgl/style/expression/find_zoom_curve.cpp index 457ae8c92..d888272dd 100644 --- a/src/mbgl/style/expression/find_zoom_curve.cpp +++ b/src/mbgl/style/expression/find_zoom_curve.cpp @@ -5,14 +5,15 @@ #include #include -#include + +#include namespace mbgl { namespace style { namespace expression { -optional> findZoomCurve(const expression::Expression* e) { - optional> result; +std::optional> findZoomCurve(const expression::Expression* e) { + std::optional> result; switch (e->getKind()) { case Kind::Let: { @@ -60,7 +61,7 @@ optional> findZoomCurve(c } e->eachChild([&](const Expression& child) { - optional> childResult(findZoomCurve(&child)); + std::optional> childResult(findZoomCurve(&child)); if (childResult) { if (childResult->is()) { result = childResult; diff --git a/src/mbgl/style/expression/format_expression.cpp b/src/mbgl/style/expression/format_expression.cpp index 201e189f4..f88096f84 100644 --- a/src/mbgl/style/expression/format_expression.cpp +++ b/src/mbgl/style/expression/format_expression.cpp @@ -8,9 +8,9 @@ namespace expression { FormatExpressionSection::FormatExpressionSection(std::unique_ptr content_) : content(std::move(content_)) {} -void FormatExpressionSection::setTextSectionOptions(optional> fontScale_, - optional> textFont_, - optional> textColor_) { +void FormatExpressionSection::setTextSectionOptions(std::optional> fontScale_, + std::optional> textFont_, + std::optional> textColor_) { if (fontScale_) { assert(*fontScale_); fontScale = std::shared_ptr(std::move(*fontScale_)); @@ -54,7 +54,7 @@ ParseResult FormatExpression::parse(const Convertible& value, ParsingContext& ct if (nextTokenMayBeObject && isObject(arg)) { nextTokenMayBeObject = false; - const optional fontScaleOption = objectMember(arg, kFormattedSectionFontScale); + auto fontScaleOption = objectMember(arg, kFormattedSectionFontScale); ParseResult fontScale; if (fontScaleOption) { fontScale = ctx.parse(*fontScaleOption, 1, {type::Number}); @@ -63,7 +63,7 @@ ParseResult FormatExpression::parse(const Convertible& value, ParsingContext& ct } } - const optional textFontOption = objectMember(arg, kFormattedSectionTextFont); + auto textFontOption = objectMember(arg, kFormattedSectionTextFont); ParseResult textFont; if (textFontOption) { textFont = ctx.parse(*textFontOption, 1, {type::Array(type::String)}); @@ -71,7 +71,7 @@ ParseResult FormatExpression::parse(const Convertible& value, ParsingContext& ct return ParseResult(); } } - const optional textColorOption = objectMember(arg, kFormattedSectionTextColor); + auto textColorOption = objectMember(arg, kFormattedSectionTextColor); ParseResult textColor; if (textColorOption) { textColor = ctx.parse(*textColorOption, 1, {type::Color}); @@ -168,7 +168,7 @@ EvaluationResult FormatExpression::evaluate(const EvaluationContext& params) con return contentResult.error(); } - optional evaluatedText; + std::optional evaluatedText; if (typeOf(*contentResult) == type::Image) { const auto& image = contentResult->get(); // Omit sections with empty image ids. @@ -184,7 +184,7 @@ EvaluationResult FormatExpression::evaluate(const EvaluationContext& params) con } } - optional evaluatedFontScale; + std::optional evaluatedFontScale; if (section.fontScale) { auto fontScaleResult = (*section.fontScale)->evaluate(params); if (!fontScaleResult) { @@ -193,7 +193,7 @@ EvaluationResult FormatExpression::evaluate(const EvaluationContext& params) con evaluatedFontScale = fontScaleResult->get(); } - optional evaluatedTextFont; + std::optional evaluatedTextFont; if (section.textFont) { auto textFontResult = (*section.textFont)->evaluate(params); if (!textFontResult) { @@ -206,7 +206,7 @@ EvaluationResult FormatExpression::evaluate(const EvaluationContext& params) con evaluatedTextFont = *textFontValue; } - optional evaluatedTextColor; + std::optional evaluatedTextColor; if (section.textColor) { auto textColorResult = (*section.textColor)->evaluate(params); if (!textColorResult) { diff --git a/src/mbgl/style/expression/formatted.cpp b/src/mbgl/style/expression/formatted.cpp index 9041bb312..5ad34a578 100644 --- a/src/mbgl/style/expression/formatted.cpp +++ b/src/mbgl/style/expression/formatted.cpp @@ -17,7 +17,7 @@ bool Formatted::operator==(const Formatted& other) const { for (std::size_t i = 0; i < sections.size(); i++) { const auto& thisSection = sections.at(i); const auto& otherSection = other.sections.at(i); - if (thisSection.text != otherSection.text || thisSection.image != otherSection.image || + if (thisSection.text != otherSection.text || !(thisSection.image == otherSection.image) || thisSection.fontScale != otherSection.fontScale || thisSection.fontStack != otherSection.fontStack || thisSection.textColor != otherSection.textColor) { return false; @@ -80,7 +80,7 @@ namespace conversion { using namespace mbgl::style::expression; -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { using namespace mbgl::style::expression; if (isArray(value)) { @@ -89,55 +89,55 @@ optional Converter::operator()(const Convertible& value, E const Convertible& section = arrayMember(value, i); std::size_t sectionLength = arrayLength(section); if (sectionLength < 1) { - error.message = "Section has to contain a text and optional parameters or an image."; - return nullopt; + error.message = "Section has to contain a text and std::optional parameters or an image."; + return std::nullopt; } const Convertible& firstElement = arrayMember(section, 0); if (isArray(firstElement)) { if (arrayLength(firstElement) < 2) { error.message = "Image section has to contain image name."; - return nullopt; + return std::nullopt; } - optional imageOp = toString(arrayMember(firstElement, 0)); + std::optional imageOp = toString(arrayMember(firstElement, 0)); if (!imageOp || *imageOp != "image") { error.message = "Serialized image section has to contain 'image' operator."; - return nullopt; + return std::nullopt; } - optional imageArg = toString(arrayMember(firstElement, 1)); + std::optional imageArg = toString(arrayMember(firstElement, 1)); if (!imageArg) { error.message = "Serialized image section agument has to be of a String type."; - return nullopt; + return std::nullopt; } sections.emplace_back(Image(*imageArg)); continue; } - optional sectionText = toString(firstElement); + std::optional sectionText = toString(firstElement); if (!sectionText) { error.message = "Section has to contain a text."; - return nullopt; + return std::nullopt; } - optional fontScale; - optional textFont; - optional textColor; + std::optional fontScale; + std::optional textFont; + std::optional textColor; if (sectionLength > 1) { const Convertible& sectionParams = arrayMember(section, 1); if (!isObject(sectionParams)) { error.message = "Parameters have to be enclosed in an object."; - return nullopt; + return std::nullopt; } - optional fontScaleMember = objectMember(sectionParams, kFormattedSectionFontScale); + std::optional fontScaleMember = objectMember(sectionParams, kFormattedSectionFontScale); if (fontScaleMember) { fontScale = toDouble(*fontScaleMember); } - optional textFontMember = objectMember(sectionParams, kFormattedSectionTextFont); + std::optional textFontMember = objectMember(sectionParams, kFormattedSectionTextFont); if (textFontMember) { if (isArray(*textFontMember)) { std::vector fontsVector; @@ -147,21 +147,21 @@ optional Converter::operator()(const Convertible& value, E fontsVector.push_back(*font); } else { error.message = "Font has to be a string."; - return nullopt; + return std::nullopt; } } textFont = fontsVector; } else { error.message = "Font stack has to be an array."; - return nullopt; + return std::nullopt; } } - optional textColorMember = objectMember(sectionParams, kFormattedSectionTextColor); + std::optional textColorMember = objectMember(sectionParams, kFormattedSectionTextColor); if (textColorMember) { textColor = convert(*textColorMember, error); if (!textColor) { - return nullopt; + return std::nullopt; } } } @@ -169,11 +169,11 @@ optional Converter::operator()(const Convertible& value, E sections.emplace_back(*sectionText, fontScale, textFont, textColor); } return Formatted(sections); - } else if (optional result = toString(value)) { + } else if (std::optional result = toString(value)) { return Formatted(result->c_str()); } else { error.message = "Formatted must be plain string or array type."; - return nullopt; + return std::nullopt; } } diff --git a/src/mbgl/style/expression/image.cpp b/src/mbgl/style/expression/image.cpp index 1dc7acde5..d8c5d9818 100644 --- a/src/mbgl/style/expression/image.cpp +++ b/src/mbgl/style/expression/image.cpp @@ -38,27 +38,27 @@ bool Image::empty() const { namespace conversion { using namespace mbgl::style::expression; -optional Converter::operator()(const Convertible& value, Error& error) const { +std::optional Converter::operator()(const Convertible& value, Error& error) const { if (isArray(value)) { Convertible imageParameters = arrayMember(value, 0); std::size_t imageParametersLength = arrayLength(imageParameters); if (imageParametersLength < 1) { error.message = "Image has to contain an ID."; - return nullopt; + return std::nullopt; } - optional imageID = toString(arrayMember(imageParameters, 0)); + std::optional imageID = toString(arrayMember(imageParameters, 0)); if (!imageID) { error.message = "Image has to contain an ID."; - return nullopt; + return std::nullopt; } return Image(*imageID, false); - } else if (optional result = toString(value)) { + } else if (std::optional result = toString(value)) { return Image(*result, false); } else { error.message = "Image must be plain string or array type."; - return nullopt; + return std::nullopt; } } diff --git a/src/mbgl/style/expression/image_expression.cpp b/src/mbgl/style/expression/image_expression.cpp index df535d4e8..ed3a4f3bd 100644 --- a/src/mbgl/style/expression/image_expression.cpp +++ b/src/mbgl/style/expression/image_expression.cpp @@ -54,7 +54,7 @@ EvaluationResult ImageExpression::evaluate(const EvaluationContext& ctx) const { return imageIDResult.error(); } - optional evaluatedImageID = toString(*imageIDResult); + std::optional evaluatedImageID = toString(*imageIDResult); if (!evaluatedImageID) { return EvaluationError({"Could not evaluate ID for 'image' expression."}); } diff --git a/src/mbgl/style/expression/in.cpp b/src/mbgl/style/expression/in.cpp index 6413b0305..2fa1a69d3 100644 --- a/src/mbgl/style/expression/in.cpp +++ b/src/mbgl/style/expression/in.cpp @@ -118,7 +118,7 @@ bool In::operator==(const Expression& e) const { return false; } -std::vector> In::possibleOutputs() const { +std::vector> In::possibleOutputs() const { return {{true}, {false}}; } diff --git a/src/mbgl/style/expression/interpolate.cpp b/src/mbgl/style/expression/interpolate.cpp index d6c693fba..cec6e9414 100644 --- a/src/mbgl/style/expression/interpolate.cpp +++ b/src/mbgl/style/expression/interpolate.cpp @@ -93,13 +93,13 @@ ParseResult parseInterpolate(const Convertible& value, ParsingContext& ctx) { return ParseResult(); } - optional interpolator; + std::optional interpolator; - const optional interpName = toString(arrayMember(interp, 0)); + const std::optional interpName = toString(arrayMember(interp, 0)); if (interpName && *interpName == "linear") { interpolator = {ExponentialInterpolator(1.0)}; } else if (interpName && *interpName == "exponential") { - optional base; + std::optional base; if (arrayLength(interp) == 2) { base = toDouble(arrayMember(interp, 1)); } @@ -109,10 +109,10 @@ ParseResult parseInterpolate(const Convertible& value, ParsingContext& ctx) { } interpolator = {ExponentialInterpolator(*base)}; } else if (interpName && *interpName == "cubic-bezier") { - optional x1; - optional y1; - optional x2; - optional y2; + std::optional x1; + std::optional y1; + std::optional x2; + std::optional y2; if (arrayLength(interp) == 5) { x1 = toDouble(arrayMember(interp, 1)); y1 = toDouble(arrayMember(interp, 2)); @@ -156,7 +156,7 @@ ParseResult parseInterpolate(const Convertible& value, ParsingContext& ctx) { } std::map> stops; - optional outputType; + std::optional outputType; if (ctx.getExpected() && *ctx.getExpected() != type::Value) { outputType = ctx.getExpected(); } @@ -164,30 +164,30 @@ ParseResult parseInterpolate(const Convertible& value, ParsingContext& ctx) { double previous = - std::numeric_limits::infinity(); for (std::size_t i = 3; i + 1 < length; i += 2) { - const optional labelValue = toValue(arrayMember(value, i)); - optional label; - optional labelError; + const std::optional labelValue = toValue(arrayMember(value, i)); + std::optional label; + std::optional labelError; if (labelValue) { labelValue->match( [&](uint64_t n) { if (n > std::numeric_limits::max()) { - label = optional{std::numeric_limits::infinity()}; + label = std::optional{std::numeric_limits::infinity()}; } else { - label = optional{static_cast(n)}; + label = std::optional{static_cast(n)}; } }, [&](int64_t n) { if (n > std::numeric_limits::max()) { - label = optional{std::numeric_limits::infinity()}; + label = std::optional{std::numeric_limits::infinity()}; } else { - label = optional{static_cast(n)}; + label = std::optional{static_cast(n)}; } }, [&](double n) { if (n > std::numeric_limits::max()) { - label = optional{std::numeric_limits::infinity()}; + label = std::optional{std::numeric_limits::infinity()}; } else { - label = optional{n}; + label = std::optional{n}; } }, [&](const auto&) {} @@ -272,8 +272,8 @@ Interpolate::Interpolate(const type::Type& type_, assert(input->getType() == type::Number); } -std::vector> Interpolate::possibleOutputs() const { - std::vector> result; +std::vector> Interpolate::possibleOutputs() const { + std::vector> result; for (const auto& stop : stops) { for (auto& output : stop.second->possibleOutputs()) { result.push_back(std::move(output)); diff --git a/src/mbgl/style/expression/is_constant.cpp b/src/mbgl/style/expression/is_constant.cpp index 7b14e79ed..4ae2c1829 100644 --- a/src/mbgl/style/expression/is_constant.cpp +++ b/src/mbgl/style/expression/is_constant.cpp @@ -12,7 +12,7 @@ bool isFeatureConstant(const Expression& expression) { if (expression.getKind() == Kind::CompoundExpression) { auto e = static_cast(&expression); const std::string name = e->getOperator(); - optional parameterCount = e->getParameterCount(); + std::optional parameterCount = e->getParameterCount(); if (name == "get" && parameterCount && *parameterCount == 1) { return false; } else if (name == "has" && parameterCount && *parameterCount == 1) { diff --git a/src/mbgl/style/expression/is_expression.cpp b/src/mbgl/style/expression/is_expression.cpp index cf2618216..245dd3831 100644 --- a/src/mbgl/style/expression/is_expression.cpp +++ b/src/mbgl/style/expression/is_expression.cpp @@ -13,7 +13,7 @@ using namespace mbgl::style::conversion; bool isExpression(const Convertible& value) { if (!isArray(value) || arrayLength(value) == 0) return false; - optional name = toString(arrayMember(value, 0)); + std::optional name = toString(arrayMember(value, 0)); if (!name) return false; return isExpression(*name) || CompoundExpression::exists(*name); diff --git a/src/mbgl/style/expression/length.cpp b/src/mbgl/style/expression/length.cpp index 095e209fa..2ce7fa901 100644 --- a/src/mbgl/style/expression/length.cpp +++ b/src/mbgl/style/expression/length.cpp @@ -38,8 +38,8 @@ bool Length::operator==(const Expression& e) const { return false; } -std::vector> Length::possibleOutputs() const { - return { nullopt }; +std::vector> Length::possibleOutputs() const { + return { std::nullopt }; } using namespace mbgl::style::conversion; diff --git a/src/mbgl/style/expression/let.cpp b/src/mbgl/style/expression/let.cpp index 029c800ef..cb3ca68c3 100644 --- a/src/mbgl/style/expression/let.cpp +++ b/src/mbgl/style/expression/let.cpp @@ -18,7 +18,7 @@ void Let::eachChild(const std::function& visit) const { visit(*result); } -std::vector> Let::possibleOutputs() const { +std::vector> Let::possibleOutputs() const { return result->possibleOutputs(); } @@ -36,7 +36,7 @@ ParseResult Let::parse(const Convertible& value, ParsingContext& ctx) { std::map> bindings_; for(std::size_t i = 1; i < length - 1; i += 2) { - optional name = toString(arrayMember(value, i)); + std::optional name = toString(arrayMember(value, i)); if (!name) { ctx.error("Expected string, but found " + getJSONType(arrayMember(value, i)) + " instead.", i); return ParseResult(); @@ -83,8 +83,8 @@ EvaluationResult Var::evaluate(const EvaluationContext& params) const { void Var::eachChild(const std::function&) const {} -std::vector> Var::possibleOutputs() const { - return { nullopt }; +std::vector> Var::possibleOutputs() const { + return { std::nullopt }; } ParseResult Var::parse(const Convertible& value_, ParsingContext& ctx) { @@ -97,7 +97,7 @@ ParseResult Var::parse(const Convertible& value_, ParsingContext& ctx) { std::string name_ = *toString(arrayMember(value_, 1)); - optional> bindingValue = ctx.getBinding(name_); + std::optional> bindingValue = ctx.getBinding(name_); if (!bindingValue) { ctx.error(R"(Unknown variable ")" + name_ + R"(". Make sure ")" + name_ + R"(" has been bound in an enclosing "let" expression before using it.)", 1); diff --git a/src/mbgl/style/expression/literal.cpp b/src/mbgl/style/expression/literal.cpp index c69341d29..9b0713140 100644 --- a/src/mbgl/style/expression/literal.cpp +++ b/src/mbgl/style/expression/literal.cpp @@ -7,7 +7,7 @@ namespace style { namespace expression { template -optional checkNumber(T n) { +std::optional checkNumber(T n) { if (n > std::numeric_limits::max()) { return {std::numeric_limits::infinity()}; } else { @@ -16,14 +16,14 @@ optional checkNumber(T n) { } using namespace mbgl::style::conversion; -optional parseValue(const Convertible& value, ParsingContext& ctx) { +std::optional parseValue(const Convertible& value, ParsingContext& ctx) { if (isUndefined(value)) return {Null}; if (isObject(value)) { std::unordered_map result; bool error = false; - eachMember(value, [&] (const std::string& k, const mbgl::style::conversion::Convertible& v) -> optional { + eachMember(value, [&] (const std::string& k, const mbgl::style::conversion::Convertible& v) -> std::optional { if (!error) { - optional memberValue = parseValue(v, ctx); + std::optional memberValue = parseValue(v, ctx); if (memberValue) { result.emplace(k, *memberValue); } else { @@ -32,24 +32,24 @@ optional parseValue(const Convertible& value, ParsingContext& ctx) { } return {}; }); - return error ? optional() : optional(result); + return error ? std::optional() : std::optional(result); } if (isArray(value)) { std::vector result; const auto length = arrayLength(value); for(std::size_t i = 0; i < length; i++) { - optional item = parseValue(arrayMember(value, i), ctx); + std::optional item = parseValue(arrayMember(value, i), ctx); if (item) { result.emplace_back(*item); } else { - return optional(); + return std::optional(); } } - return optional(result); + return std::optional(result); } - optional v = toValue(value); + std::optional v = toValue(value); // since value represents a JSON value, if it's not undefined, object, or // array, it must be convertible to mbgl::Value assert(v); @@ -59,7 +59,7 @@ optional parseValue(const Convertible& value, ParsingContext& ctx) { [&](int64_t n) { return checkNumber(n); }, [&](double n) { return checkNumber(n); }, [&](const auto&) { - return optional(toExpressionValue(*v)); + return std::optional(toExpressionValue(*v)); } ); } @@ -74,7 +74,7 @@ ParseResult Literal::parse(const Convertible& value, ParsingContext& ctx) { ctx.error("'literal' expression requires exactly one argument, but found " + util::toString(arrayLength(value) - 1) + " instead."); return ParseResult(); } - const optional parsedValue = parseValue(arrayMember(value, 1), ctx); + const std::optional parsedValue = parseValue(arrayMember(value, 1), ctx); if (!parsedValue) { return ParseResult(); } @@ -98,7 +98,7 @@ ParseResult Literal::parse(const Convertible& value, ParsingContext& ctx) { return ParseResult(std::make_unique(*parsedValue)); } else { // bare primitive value (string, number, boolean, null) - const optional parsedValue = parseValue(value, ctx); + const std::optional parsedValue = parseValue(value, ctx); return ParseResult(std::make_unique(*parsedValue)); } } diff --git a/src/mbgl/style/expression/match.cpp b/src/mbgl/style/expression/match.cpp index 8ad9f5466..740e00189 100644 --- a/src/mbgl/style/expression/match.cpp +++ b/src/mbgl/style/expression/match.cpp @@ -29,8 +29,8 @@ bool Match::operator==(const Expression& e) const { } template -std::vector> Match::possibleOutputs() const { - std::vector> result; +std::vector> Match::possibleOutputs() const { + std::vector> result; for (const auto& branch : branches) { for (auto& output : branch.second->possibleOutputs()) { result.push_back(std::move(output)); @@ -125,10 +125,10 @@ template class Match; using InputType = variant; using namespace mbgl::style::conversion; -optional parseInputValue(const Convertible& input, ParsingContext& parentContext, std::size_t index, optional& inputType) { +std::optional parseInputValue(const Convertible& input, ParsingContext& parentContext, std::size_t index, std::optional& inputType) { using namespace mbgl::style::conversion; - optional result; - optional type; + std::optional result; + std::optional type; auto value = toValue(input); @@ -139,7 +139,7 @@ optional parseInputValue(const Convertible& input, ParsingContext& pa parentContext.error("Branch labels must be integers no larger than " + util::toString(Value::maxSafeInteger()) + ".", index); } else { type = {type::Number}; - result = optional{static_cast(n)}; + result = std::optional{static_cast(n)}; } }, [&] (int64_t n) { @@ -147,7 +147,7 @@ optional parseInputValue(const Convertible& input, ParsingContext& pa parentContext.error("Branch labels must be integers no larger than " + util::toString(Value::maxSafeInteger()) + ".", index); } else { type = {type::Number}; - result = optional{n}; + result = std::optional{n}; } }, [&] (double n) { @@ -157,7 +157,7 @@ optional parseInputValue(const Convertible& input, ParsingContext& pa parentContext.error("Numeric branch labels must be integer values.", index); } else { type = {type::Number}; - result = optional{static_cast(n)}; + result = std::optional{static_cast(n)}; } }, [&] (const std::string& s) { @@ -179,10 +179,10 @@ optional parseInputValue(const Convertible& input, ParsingContext& pa if (!inputType) { inputType = type; } else { - optional err = type::checkSubtype(*inputType, *type); + std::optional err = type::checkSubtype(*inputType, *type); if (err) { parentContext.error(*err, index); - return optional(); + return std::optional(); } } @@ -239,8 +239,8 @@ ParseResult parseMatch(const Convertible& value, ParsingContext& ctx) { return ParseResult(); } - optional inputType; - optional outputType; + std::optional inputType; + std::optional outputType; if (ctx.getExpected() && *ctx.getExpected() != type::Value) { outputType = ctx.getExpected(); } @@ -264,14 +264,14 @@ ParseResult parseMatch(const Convertible& value, ParsingContext& ctx) { labels.reserve(groupLength); for (size_t j = 0; j < groupLength; j++) { - const optional inputValue = parseInputValue(arrayMember(label, j), ctx, i, inputType); + const std::optional inputValue = parseInputValue(arrayMember(label, j), ctx, i, inputType); if (!inputValue) { return ParseResult(); } labels.push_back(*inputValue); } } else { - const optional inputValue = parseInputValue(label, ctx, i, inputType); + const std::optional inputValue = parseInputValue(label, ctx, i, inputType); if (!inputValue) { return ParseResult(); } @@ -302,7 +302,7 @@ ParseResult parseMatch(const Convertible& value, ParsingContext& ctx) { assert(inputType && outputType); - optional err; + std::optional err; if ((*input)->getType() != type::Value && (err = type::checkSubtype(*inputType, (*input)->getType()))) { ctx.error(*err, 1); return ParseResult(); diff --git a/src/mbgl/style/expression/number_format.cpp b/src/mbgl/style/expression/number_format.cpp index 37efa1d2c..13082fffc 100644 --- a/src/mbgl/style/expression/number_format.cpp +++ b/src/mbgl/style/expression/number_format.cpp @@ -110,8 +110,8 @@ bool NumberFormat::operator==(const Expression& e) const { return false; } -std::vector> NumberFormat::possibleOutputs() const { - return { nullopt }; +std::vector> NumberFormat::possibleOutputs() const { + return { std::nullopt }; } using namespace mbgl::style::conversion; @@ -141,7 +141,7 @@ ParseResult NumberFormat::parse(const Convertible& value, ParsingContext& ctx) { return ParseResult(); } - const optional localeOption = objectMember(options, localeKey); + const std::optional localeOption = objectMember(options, localeKey); ParseResult localeResult; if (localeOption) { localeResult = ctx.parse(*localeOption, 1, {type::String}); @@ -151,7 +151,7 @@ ParseResult NumberFormat::parse(const Convertible& value, ParsingContext& ctx) { } } - const optional currencyOption = objectMember(options, currencyKey); + const std::optional currencyOption = objectMember(options, currencyKey); ParseResult currencyResult; if (currencyOption) { currencyResult = ctx.parse(*currencyOption, 1, {type::String}); @@ -161,7 +161,7 @@ ParseResult NumberFormat::parse(const Convertible& value, ParsingContext& ctx) { } } - const optional minFractionDigitsOption = objectMember(options, minFractionDigitsKey); + const std::optional minFractionDigitsOption = objectMember(options, minFractionDigitsKey); ParseResult minFractionDigitsResult; if (minFractionDigitsOption) { minFractionDigitsResult = ctx.parse(*minFractionDigitsOption, 1, {type::Number}); @@ -171,7 +171,7 @@ ParseResult NumberFormat::parse(const Convertible& value, ParsingContext& ctx) { } } - const optional maxFractionDigitsOption = objectMember(options, maxFractionDigitsKey); + const std::optional maxFractionDigitsOption = objectMember(options, maxFractionDigitsKey); ParseResult maxFractionDigitsResult; if (maxFractionDigitsOption) { maxFractionDigitsResult = ctx.parse(*maxFractionDigitsOption, 1, {type::Number}); diff --git a/src/mbgl/style/expression/parsing_context.cpp b/src/mbgl/style/expression/parsing_context.cpp index f3842613d..47d98ade0 100644 --- a/src/mbgl/style/expression/parsing_context.cpp +++ b/src/mbgl/style/expression/parsing_context.cpp @@ -86,8 +86,8 @@ using namespace mbgl::style::conversion; ParseResult ParsingContext::parse(const Convertible& value, std::size_t index_, - optional expected_, - const optional& typeAnnotationOption) { + std::optional expected_, + const std::optional& typeAnnotationOption) { ParsingContext child(key + "[" + util::toString(index_) + "]", errors, std::move(expected_), @@ -95,7 +95,7 @@ ParseResult ParsingContext::parse(const Convertible& value, return child.parse(value, typeAnnotationOption); } -ParseResult ParsingContext::parse(const Convertible& value, std::size_t index_, optional expected_, +ParseResult ParsingContext::parse(const Convertible& value, std::size_t index_, std::optional expected_, const std::map>& bindings) { ParsingContext child(key + "[" + util::toString(index_) + "]", errors, @@ -148,7 +148,7 @@ bool isExpression(const std::string& name) { } ParseResult ParsingContext::parse(const Convertible& value, - const optional& typeAnnotationOption) { + const std::optional& typeAnnotationOption) { ParseResult parsed; if (isArray(value)) { @@ -158,7 +158,7 @@ ParseResult ParsingContext::parse(const Convertible& value, return ParseResult(); } - const optional op = toString(arrayMember(value, 0)); + const std::optional op = toString(arrayMember(value, 0)); if (!op) { error( "Expression name must be a string, but found " + getJSONType(arrayMember(value, 0)) + @@ -244,18 +244,18 @@ ParseResult ParsingContext::parse(const Convertible& value, } ParseResult ParsingContext::parseExpression(const Convertible& value, - const optional& typeAnnotationOption) { + const std::optional& typeAnnotationOption) { return parse(value, typeAnnotationOption); } ParseResult ParsingContext::parseLayerPropertyExpression(const Convertible& value) { - optional typeAnnotationOption; + std::optional typeAnnotationOption; if (expected && *expected == type::String) { typeAnnotationOption = TypeAnnotationOption::coerce; } ParseResult parsed = parse(value, typeAnnotationOption); if (parsed && !isZoomConstant(**parsed)) { - optional> zoomCurve = findZoomCurve(parsed->get()); + std::optional> zoomCurve = findZoomCurve(parsed->get()); if (!zoomCurve) { error(R"("zoom" expression may only be used as input to a top-level "step" or "interpolate" expression.)"); return ParseResult(); @@ -281,9 +281,9 @@ std::string ParsingContext::getCombinedErrors() const { return combinedError; } -optional ParsingContext::checkType(const type::Type& t) { +std::optional ParsingContext::checkType(const type::Type& t) { assert(expected); - optional err = type::checkSubtype(*expected, t); + std::optional err = type::checkSubtype(*expected, t); if (err) { error(*err); } diff --git a/src/mbgl/style/expression/step.cpp b/src/mbgl/style/expression/step.cpp index 170e84bfc..7f75135e1 100644 --- a/src/mbgl/style/expression/step.cpp +++ b/src/mbgl/style/expression/step.cpp @@ -65,8 +65,8 @@ bool Step::operator==(const Expression& e) const { return false; } -std::vector> Step::possibleOutputs() const { - std::vector> result; +std::vector> Step::possibleOutputs() const { + std::vector> result; for (const auto& stop : stops) { for (auto& output : stop.second->possibleOutputs()) { result.push_back(std::move(output)); @@ -102,7 +102,7 @@ ParseResult Step::parse(const mbgl::style::conversion::Convertible& value, Parsi } std::map> stops; - optional outputType; + std::optional outputType; if (ctx.getExpected() && *ctx.getExpected() != type::Value) { outputType = ctx.getExpected(); } @@ -122,29 +122,29 @@ ParseResult Step::parse(const mbgl::style::conversion::Convertible& value, Parsi for (std::size_t i = 3; i + 1 < length; i += 2) { - const optional labelValue = toValue(arrayMember(value, i)); - optional label; + const auto labelValue = toValue(arrayMember(value, i)); + std::optional label; if (labelValue) { labelValue->match( [&](uint64_t n) { if (n > std::numeric_limits::max()) { - label = optional{std::numeric_limits::infinity()}; + label = std::optional{std::numeric_limits::infinity()}; } else { - label = optional{static_cast(n)}; + label = std::optional{static_cast(n)}; } }, [&](int64_t n) { if (n > std::numeric_limits::max()) { - label = optional{std::numeric_limits::infinity()}; + label = std::optional{std::numeric_limits::infinity()}; } else { - label = optional{static_cast(n)}; + label = std::optional{static_cast(n)}; } }, [&](double n) { if (n > std::numeric_limits::max()) { - label = optional{std::numeric_limits::infinity()}; + label = std::optional{std::numeric_limits::infinity()}; } else { - label = optional{n}; + label = std::optional{n}; } }, [&](const auto&) {} diff --git a/src/mbgl/style/expression/value.cpp b/src/mbgl/style/expression/value.cpp index b79296d26..1955a626e 100644 --- a/src/mbgl/style/expression/value.cpp +++ b/src/mbgl/style/expression/value.cpp @@ -18,7 +18,7 @@ type::Type typeOf(const Value& value) { [&](const NullValue&) -> type::Type { return type::Null; }, [&](const std::unordered_map&) -> type::Type { return type::Object; }, [&](const std::vector& arr) -> type::Type { - optional itemType; + std::optional itemType; for (const auto& item : arr) { const type::Type t = typeOf(item); if (!itemType) { @@ -192,10 +192,10 @@ Value ValueConverter::toExpressionValue(const float value) { return static_cast(value); } -optional ValueConverter::fromExpressionValue(const Value& value) { +std::optional ValueConverter::fromExpressionValue(const Value& value) { return value.template is() ? static_cast(value.template get()) - : optional(); + : std::optional(); } @@ -215,23 +215,23 @@ Value ValueConverter>::toExpressionValue(const std::array } template -optional> ValueConverter>::fromExpressionValue(const Value& value) { +std::optional> ValueConverter>::fromExpressionValue(const Value& value) { return value.match( - [&] (const std::vector& v) -> optional> { - if (v.size() != N) return optional>(); + [&] (const std::vector& v) -> std::optional> { + if (v.size() != N) return std::optional>(); std::array result; auto it = result.begin(); for(const Value& item : v) { - optional convertedItem = ValueConverter::fromExpressionValue(item); + std::optional convertedItem = ValueConverter::fromExpressionValue(item); if (!convertedItem) { - return optional>(); + return std::optional>(); } *it = *convertedItem; it = std::next(it); } return result; }, - [&] (const auto&) { return optional>(); } + [&] (const auto&) { return std::optional>(); } ); } @@ -242,21 +242,21 @@ Value ValueConverter>::toExpressionValue(const std::vector& va } template -optional> ValueConverter>::fromExpressionValue(const Value& value) { +std::optional> ValueConverter>::fromExpressionValue(const Value& value) { return value.match( - [&] (const std::vector& v) -> optional> { + [&] (const std::vector& v) -> std::optional> { std::vector result; result.reserve(v.size()); for(const Value& item : v) { - optional convertedItem = ValueConverter::fromExpressionValue(item); + std::optional convertedItem = ValueConverter::fromExpressionValue(item); if (!convertedItem) { - return optional>(); + return std::optional>(); } result.push_back(*convertedItem); } return result; }, - [&] (const auto&) { return optional>(); } + [&] (const auto&) { return std::optional>(); } ); } @@ -264,18 +264,18 @@ Value ValueConverter::toExpressionValue(const mbgl::style::Position& v return ValueConverter>::toExpressionValue(value.getSpherical()); } -optional ValueConverter::fromExpressionValue(const Value& v) { +std::optional ValueConverter::fromExpressionValue(const Value& v) { auto pos = ValueConverter>::fromExpressionValue(v); - return pos ? optional(Position(*pos)) : optional(); + return pos ? std::optional(Position(*pos)) : std::optional(); } Value ValueConverter::toExpressionValue(const mbgl::style::Rotation& value) { return ValueConverter::toExpressionValue(static_cast(value.getAngle())); } -optional ValueConverter::fromExpressionValue(const Value& v) { +std::optional ValueConverter::fromExpressionValue(const Value& v) { auto angle = ValueConverter::fromExpressionValue(v); - return angle ? optional(Rotation(*angle)) : optional(); + return angle ? std::optional(Rotation(*angle)) : std::optional(); } template @@ -284,10 +284,10 @@ Value ValueConverter>>::toExpressionValue } template -optional ValueConverter>>::fromExpressionValue(const Value& value) { +std::optional ValueConverter>>::fromExpressionValue(const Value& value) { return value.match( [&] (const std::string& v) { return Enum::toEnum(v); }, - [&] (const auto&) { return optional(); } + [&] (const auto&) { return std::optional(); } ); } diff --git a/src/mbgl/style/expression/within.cpp b/src/mbgl/style/expression/within.cpp index 2346fdbaf..edc64c5dc 100644 --- a/src/mbgl/style/expression/within.cpp +++ b/src/mbgl/style/expression/within.cpp @@ -169,7 +169,7 @@ bool featureWithinPolygons(const GeometryTileFeature& feature, }; } -mbgl::optional parseValue(const mbgl::style::conversion::Convertible& value_, +std::optional parseValue(const mbgl::style::conversion::Convertible& value_, mbgl::style::expression::ParsingContext& ctx) { if (isObject(value_)) { mbgl::style::conversion::Error error; @@ -181,17 +181,17 @@ mbgl::optional parseValue(const mbgl::style::conversion::Converti } ctx.error("'within' expression requires valid geojson source that contains polygon geometry type."); - return nullopt; + return std::nullopt; } -mbgl::optional getPolygonInfo(const Feature& polyFeature, +std::optional getPolygonInfo(const Feature& polyFeature, mbgl::style::expression::ParsingContext& ctx) { const auto type = apply_visitor(ToFeatureType(), polyFeature.geometry); if (type == FeatureType::Polygon) { return polyFeature.geometry; } ctx.error("'within' expression requires valid geojson source that contains polygon geometry type."); - return nullopt; + return std::nullopt; } } // namespace @@ -318,7 +318,7 @@ bool Within::operator==(const Expression& e) const { return false; } -std::vector> Within::possibleOutputs() const { +std::vector> Within::possibleOutputs() const { return {{true}, {false}}; } diff --git a/src/mbgl/style/filter.cpp b/src/mbgl/style/filter.cpp index 18b8b0a7f..7b5ad8d9f 100644 --- a/src/mbgl/style/filter.cpp +++ b/src/mbgl/style/filter.cpp @@ -10,7 +10,7 @@ bool Filter::operator()(const expression::EvaluationContext &context) const { const expression::EvaluationResult result = (*this->expression)->evaluate(context); if (result) { - const optional typed = expression::fromExpressionValue(*result); + const std::optional typed = expression::fromExpressionValue(*result); return typed ? *typed : false; } else { return false; diff --git a/src/mbgl/style/image.cpp b/src/mbgl/style/image.cpp index eb0b5ab24..ea4c8ee8d 100644 --- a/src/mbgl/style/image.cpp +++ b/src/mbgl/style/image.cpp @@ -11,7 +11,7 @@ Image::Image(std::string id, bool sdf, ImageStretches stretchX, ImageStretches stretchY, - const optional& content) + const std::optional& content) : baseImpl(makeMutable( std::move(id), std::move(image), pixelRatio, sdf, std::move(stretchX), std::move(stretchY), content)) {} @@ -41,7 +41,7 @@ const ImageStretches& Image::getStretchY() const { return baseImpl->stretchY; } -const optional& Image::getContent() const { +const std::optional& Image::getContent() const { return baseImpl->content; } diff --git a/src/mbgl/style/image_impl.cpp b/src/mbgl/style/image_impl.cpp index b99a2e108..3f60ae09c 100644 --- a/src/mbgl/style/image_impl.cpp +++ b/src/mbgl/style/image_impl.cpp @@ -38,7 +38,7 @@ Image::Impl::Impl(std::string id_, bool sdf_, ImageStretches stretchX_, ImageStretches stretchY_, - optional content_) + std::optional content_) : id(std::move(id_)), image(std::move(image_)), pixelRatio(pixelRatio_), diff --git a/src/mbgl/style/image_impl.hpp b/src/mbgl/style/image_impl.hpp index 11ceab483..bd47397ca 100644 --- a/src/mbgl/style/image_impl.hpp +++ b/src/mbgl/style/image_impl.hpp @@ -5,6 +5,7 @@ #include #include #include +#include namespace mbgl { namespace style { @@ -17,7 +18,7 @@ public: bool sdf = false, ImageStretches stretchX = {}, ImageStretches stretchY = {}, - optional content = nullopt); + std::optional content = std::nullopt); const std::string id; @@ -34,7 +35,7 @@ public: const ImageStretches stretchY; // The space where text can be fit into this image. - const optional content; + const std::optional content; }; } // namespace style diff --git a/src/mbgl/style/layer.cpp b/src/mbgl/style/layer.cpp index 428bcc9a5..348edcff9 100644 --- a/src/mbgl/style/layer.cpp +++ b/src/mbgl/style/layer.cpp @@ -155,70 +155,68 @@ void Layer::setObserver(LayerObserver* observer_) { observer = observer_ ? observer_ : &nullObserver; } -optional Layer::setProperty(const std::string& name, const conversion::Convertible& value) { +std::optional Layer::setProperty(const std::string& name, const conversion::Convertible& value) { using namespace conversion; - optional error = setPropertyInternal(name, value); + std::optional error = setPropertyInternal(name, value); if (!error) return error; // Successfully set by the derived class implementation. if (name == "visibility") return setVisibility(value); if (name == "minzoom") { if (auto zoom = convert(value, *error)) { setMinZoom(*zoom); - return nullopt; + return std::nullopt; } } else if (name == "maxzoom") { if (auto zoom = convert(value, *error)) { setMaxZoom(*zoom); - return nullopt; + return std::nullopt; } } else if (name == "filter") { if (auto filter = convert(value, *error)) { setFilter(*filter); - return nullopt; + return std::nullopt; } } else if (name == "source-layer") { if (auto sourceLayer = convert(value, *error)) { if (getTypeInfo()->source != LayerTypeInfo::Source::Required) { Log::Warning(mbgl::Event::General, "'source-layer' property cannot be set to" - "the layer %s", - baseImpl->id.c_str()); - return nullopt; + "the layer " + baseImpl->id); + return std::nullopt; } setSourceLayer(*sourceLayer); - return nullopt; + return std::nullopt; } } else if (name == "source") { if (auto sourceID = convert(value, *error)) { if (getTypeInfo()->source != LayerTypeInfo::Source::Required) { Log::Warning(mbgl::Event::General, "'source' property cannot be set to" - "the layer %s", - baseImpl->id.c_str()); - return nullopt; + "the layer " + baseImpl->id); + return std::nullopt; } setSourceID(*sourceID); - return nullopt; + return std::nullopt; } } return error; } -optional Layer::setVisibility(const conversion::Convertible& value) { +std::optional Layer::setVisibility(const conversion::Convertible& value) { using namespace conversion; if (isUndefined(value)) { setVisibility(VisibilityType::Visible); - return nullopt; + return std::nullopt; } Error error; - optional visibility = convert(value, error); + std::optional visibility = convert(value, error); if (!visibility) { return error; } setVisibility(*visibility); - return nullopt; + return std::nullopt; } const LayerTypeInfo* Layer::getTypeInfo() const noexcept { diff --git a/src/mbgl/style/layers/background_layer.cpp b/src/mbgl/style/layers/background_layer.cpp index 49eb267bf..904f3cdf0 100644 --- a/src/mbgl/style/layers/background_layer.cpp +++ b/src/mbgl/style/layers/background_layer.cpp @@ -213,7 +213,7 @@ Value BackgroundLayer::serialize() const { return result; } -optional BackgroundLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional BackgroundLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -227,7 +227,7 @@ optional BackgroundLayer::setPropertyInternal(const std::string& name, co } setBackgroundColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::BackgroundOpacity) { Error error; @@ -237,7 +237,7 @@ optional BackgroundLayer::setPropertyInternal(const std::string& name, co } setBackgroundOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::BackgroundPattern) { Error error; @@ -247,28 +247,28 @@ optional BackgroundLayer::setPropertyInternal(const std::string& name, co } setBackgroundPattern(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::BackgroundColorTransition) { setBackgroundColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::BackgroundOpacityTransition) { setBackgroundOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::BackgroundPatternTransition) { setBackgroundPatternTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/circle_layer.cpp b/src/mbgl/style/layers/circle_layer.cpp index c66a768f0..a04ddf1df 100644 --- a/src/mbgl/style/layers/circle_layer.cpp +++ b/src/mbgl/style/layers/circle_layer.cpp @@ -513,7 +513,7 @@ Value CircleLayer::serialize() const { return result; } -optional CircleLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional CircleLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -530,32 +530,32 @@ optional CircleLayer::setPropertyInternal(const std::string& name, const if (property == Property::CircleBlur) { setCircleBlur(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleOpacity) { setCircleOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleRadius) { setCircleRadius(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleStrokeOpacity) { setCircleStrokeOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleStrokeWidth) { setCircleStrokeWidth(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleSortKey) { setCircleSortKey(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::CircleColor || property == Property::CircleStrokeColor) { @@ -567,12 +567,12 @@ optional CircleLayer::setPropertyInternal(const std::string& name, const if (property == Property::CircleColor) { setCircleColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleStrokeColor) { setCircleStrokeColor(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::CirclePitchAlignment) { @@ -583,7 +583,7 @@ optional CircleLayer::setPropertyInternal(const std::string& name, const } setCirclePitchAlignment(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CirclePitchScale) { Error error; @@ -593,7 +593,7 @@ optional CircleLayer::setPropertyInternal(const std::string& name, const } setCirclePitchScale(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleTranslate) { Error error; @@ -603,7 +603,7 @@ optional CircleLayer::setPropertyInternal(const std::string& name, const } setCircleTranslate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::CircleTranslateAnchor) { Error error; @@ -613,68 +613,68 @@ optional CircleLayer::setPropertyInternal(const std::string& name, const } setCircleTranslateAnchor(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::CircleBlurTransition) { setCircleBlurTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleColorTransition) { setCircleColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleOpacityTransition) { setCircleOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CirclePitchAlignmentTransition) { setCirclePitchAlignmentTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CirclePitchScaleTransition) { setCirclePitchScaleTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleRadiusTransition) { setCircleRadiusTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleStrokeColorTransition) { setCircleStrokeColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleStrokeOpacityTransition) { setCircleStrokeOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleStrokeWidthTransition) { setCircleStrokeWidthTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleTranslateTransition) { setCircleTranslateTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::CircleTranslateAnchorTransition) { setCircleTranslateAnchorTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/fill_extrusion_layer.cpp b/src/mbgl/style/layers/fill_extrusion_layer.cpp index 55f6c0a5a..0885349be 100644 --- a/src/mbgl/style/layers/fill_extrusion_layer.cpp +++ b/src/mbgl/style/layers/fill_extrusion_layer.cpp @@ -388,7 +388,7 @@ Value FillExtrusionLayer::serialize() const { return result; } -optional FillExtrusionLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional FillExtrusionLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -403,12 +403,12 @@ optional FillExtrusionLayer::setPropertyInternal(const std::string& name, if (property == Property::FillExtrusionBase) { setFillExtrusionBase(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionHeight) { setFillExtrusionHeight(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::FillExtrusionColor) { @@ -419,7 +419,7 @@ optional FillExtrusionLayer::setPropertyInternal(const std::string& name, } setFillExtrusionColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionOpacity) { Error error; @@ -429,7 +429,7 @@ optional FillExtrusionLayer::setPropertyInternal(const std::string& name, } setFillExtrusionOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionPattern) { Error error; @@ -439,7 +439,7 @@ optional FillExtrusionLayer::setPropertyInternal(const std::string& name, } setFillExtrusionPattern(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionTranslate) { Error error; @@ -449,7 +449,7 @@ optional FillExtrusionLayer::setPropertyInternal(const std::string& name, } setFillExtrusionTranslate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionTranslateAnchor) { Error error; @@ -459,7 +459,7 @@ optional FillExtrusionLayer::setPropertyInternal(const std::string& name, } setFillExtrusionTranslateAnchor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionVerticalGradient) { Error error; @@ -469,53 +469,53 @@ optional FillExtrusionLayer::setPropertyInternal(const std::string& name, } setFillExtrusionVerticalGradient(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::FillExtrusionBaseTransition) { setFillExtrusionBaseTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionColorTransition) { setFillExtrusionColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionHeightTransition) { setFillExtrusionHeightTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionOpacityTransition) { setFillExtrusionOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionPatternTransition) { setFillExtrusionPatternTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionTranslateTransition) { setFillExtrusionTranslateTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionTranslateAnchorTransition) { setFillExtrusionTranslateAnchorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillExtrusionVerticalGradientTransition) { setFillExtrusionVerticalGradientTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/fill_layer.cpp b/src/mbgl/style/layers/fill_layer.cpp index d25638f5e..dea9690fd 100644 --- a/src/mbgl/style/layers/fill_layer.cpp +++ b/src/mbgl/style/layers/fill_layer.cpp @@ -373,7 +373,7 @@ Value FillLayer::serialize() const { return result; } -optional FillLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional FillLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -387,7 +387,7 @@ optional FillLayer::setPropertyInternal(const std::string& name, const Co } setFillAntialias(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillColor || property == Property::FillOutlineColor) { Error error; @@ -398,12 +398,12 @@ optional FillLayer::setPropertyInternal(const std::string& name, const Co if (property == Property::FillColor) { setFillColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillOutlineColor) { setFillOutlineColor(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::FillOpacity || property == Property::FillSortKey) { @@ -415,12 +415,12 @@ optional FillLayer::setPropertyInternal(const std::string& name, const Co if (property == Property::FillOpacity) { setFillOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillSortKey) { setFillSortKey(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::FillPattern) { @@ -431,7 +431,7 @@ optional FillLayer::setPropertyInternal(const std::string& name, const Co } setFillPattern(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillTranslate) { Error error; @@ -441,7 +441,7 @@ optional FillLayer::setPropertyInternal(const std::string& name, const Co } setFillTranslate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::FillTranslateAnchor) { Error error; @@ -451,48 +451,48 @@ optional FillLayer::setPropertyInternal(const std::string& name, const Co } setFillTranslateAnchor(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::FillAntialiasTransition) { setFillAntialiasTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillColorTransition) { setFillColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillOpacityTransition) { setFillOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillOutlineColorTransition) { setFillOutlineColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillPatternTransition) { setFillPatternTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillTranslateTransition) { setFillTranslateTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::FillTranslateAnchorTransition) { setFillTranslateAnchorTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/heatmap_layer.cpp b/src/mbgl/style/layers/heatmap_layer.cpp index d7f3fc26d..ed8ca711f 100644 --- a/src/mbgl/style/layers/heatmap_layer.cpp +++ b/src/mbgl/style/layers/heatmap_layer.cpp @@ -285,7 +285,7 @@ Value HeatmapLayer::serialize() const { return result; } -optional HeatmapLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional HeatmapLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -299,7 +299,7 @@ optional HeatmapLayer::setPropertyInternal(const std::string& name, const } setHeatmapColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::HeatmapIntensity || property == Property::HeatmapOpacity) { Error error; @@ -310,12 +310,12 @@ optional HeatmapLayer::setPropertyInternal(const std::string& name, const if (property == Property::HeatmapIntensity) { setHeatmapIntensity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::HeatmapOpacity) { setHeatmapOpacity(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::HeatmapRadius || property == Property::HeatmapWeight) { @@ -327,44 +327,44 @@ optional HeatmapLayer::setPropertyInternal(const std::string& name, const if (property == Property::HeatmapRadius) { setHeatmapRadius(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::HeatmapWeight) { setHeatmapWeight(*typedValue); - return nullopt; + return std::nullopt; } } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::HeatmapColorTransition) { setHeatmapColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HeatmapIntensityTransition) { setHeatmapIntensityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HeatmapOpacityTransition) { setHeatmapOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HeatmapRadiusTransition) { setHeatmapRadiusTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HeatmapWeightTransition) { setHeatmapWeightTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/hillshade_layer.cpp b/src/mbgl/style/layers/hillshade_layer.cpp index 9f9607765..20df49a19 100644 --- a/src/mbgl/style/layers/hillshade_layer.cpp +++ b/src/mbgl/style/layers/hillshade_layer.cpp @@ -318,7 +318,7 @@ Value HillshadeLayer::serialize() const { return result; } -optional HillshadeLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional HillshadeLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -334,17 +334,17 @@ optional HillshadeLayer::setPropertyInternal(const std::string& name, con if (property == Property::HillshadeAccentColor) { setHillshadeAccentColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeHighlightColor) { setHillshadeHighlightColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeShadowColor) { setHillshadeShadowColor(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::HillshadeExaggeration || property == Property::HillshadeIlluminationDirection) { @@ -356,12 +356,12 @@ optional HillshadeLayer::setPropertyInternal(const std::string& name, con if (property == Property::HillshadeExaggeration) { setHillshadeExaggeration(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeIlluminationDirection) { setHillshadeIlluminationDirection(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::HillshadeIlluminationAnchor) { @@ -372,43 +372,43 @@ optional HillshadeLayer::setPropertyInternal(const std::string& name, con } setHillshadeIlluminationAnchor(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::HillshadeAccentColorTransition) { setHillshadeAccentColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeExaggerationTransition) { setHillshadeExaggerationTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeHighlightColorTransition) { setHillshadeHighlightColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeIlluminationAnchorTransition) { setHillshadeIlluminationAnchorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeIlluminationDirectionTransition) { setHillshadeIlluminationDirectionTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::HillshadeShadowColorTransition) { setHillshadeShadowColorTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/layer.cpp.ejs b/src/mbgl/style/layers/layer.cpp.ejs index 8fd4b1fef..7bc881c1b 100644 --- a/src/mbgl/style/layers/layer.cpp.ejs +++ b/src/mbgl/style/layers/layer.cpp.ejs @@ -277,7 +277,7 @@ Value <%- camelize(type) %>Layer::serialize() const { return result; } -optional <%- camelize(type) %>Layer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional <%- camelize(type) %>Layer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -312,24 +312,24 @@ optional <%- camelize(type) %>Layer::setPropertyInternal(const std::strin } <% if (properties.length == 1) { %> set<%- camelize(properties[0].name) %>(*typedValue); - return nullopt; + return std::nullopt; <% } else for (const property of properties) { %> if (property == Property::<%- camelize(property.name) %>) { set<%- camelize(property.name) %>(*typedValue); - return nullopt; + return std::nullopt; } <% } -%> } <% } %> Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } <% for (const property of paintProperties) { %> if (property == Property::<%- camelize(property.name) %>Transition) { set<%- camelize(property.name) %>Transition(*transition); - return nullopt; + return std::nullopt; } <% } %> return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/line_layer.cpp b/src/mbgl/style/layers/line_layer.cpp index cfec989b7..cb2e60fa0 100644 --- a/src/mbgl/style/layers/line_layer.cpp +++ b/src/mbgl/style/layers/line_layer.cpp @@ -590,7 +590,7 @@ Value LineLayer::serialize() const { return result; } -optional LineLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional LineLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -606,32 +606,32 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co if (property == Property::LineBlur) { setLineBlur(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineGapWidth) { setLineGapWidth(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineOffset) { setLineOffset(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineOpacity) { setLineOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineWidth) { setLineWidth(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineSortKey) { setLineSortKey(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::LineColor) { @@ -642,7 +642,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLineColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineDasharray) { Error error; @@ -652,7 +652,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLineDasharray(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineGradient) { Error error; @@ -662,7 +662,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLineGradient(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LinePattern) { Error error; @@ -672,7 +672,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLinePattern(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineTranslate) { Error error; @@ -682,7 +682,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLineTranslate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineTranslateAnchor) { Error error; @@ -692,7 +692,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLineTranslateAnchor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineCap) { Error error; @@ -702,7 +702,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLineCap(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineJoin) { Error error; @@ -712,7 +712,7 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co } setLineJoin(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineMiterLimit || property == Property::LineRoundLimit) { Error error; @@ -723,74 +723,74 @@ optional LineLayer::setPropertyInternal(const std::string& name, const Co if (property == Property::LineMiterLimit) { setLineMiterLimit(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::LineRoundLimit) { setLineRoundLimit(*typedValue); - return nullopt; + return std::nullopt; } } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::LineBlurTransition) { setLineBlurTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineColorTransition) { setLineColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineDasharrayTransition) { setLineDasharrayTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineGapWidthTransition) { setLineGapWidthTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineGradientTransition) { setLineGradientTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineOffsetTransition) { setLineOffsetTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineOpacityTransition) { setLineOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LinePatternTransition) { setLinePatternTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineTranslateTransition) { setLineTranslateTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineTranslateAnchorTransition) { setLineTranslateAnchorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LineWidthTransition) { setLineWidthTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/location_indicator_layer.cpp b/src/mbgl/style/layers/location_indicator_layer.cpp index 9cf262e7b..9c3f6163c 100644 --- a/src/mbgl/style/layers/location_indicator_layer.cpp +++ b/src/mbgl/style/layers/location_indicator_layer.cpp @@ -516,7 +516,7 @@ Value LocationIndicatorLayer::serialize() const { return result; } -optional LocationIndicatorLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional LocationIndicatorLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -533,32 +533,32 @@ optional LocationIndicatorLayer::setPropertyInternal(const std::string& n if (property == Property::AccuracyRadius) { setAccuracyRadius(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::BearingImageSize) { setBearingImageSize(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::ImageTiltDisplacement) { setImageTiltDisplacement(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::PerspectiveCompensation) { setPerspectiveCompensation(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::ShadowImageSize) { setShadowImageSize(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TopImageSize) { setTopImageSize(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::AccuracyRadiusBorderColor || property == Property::AccuracyRadiusColor) { @@ -570,12 +570,12 @@ optional LocationIndicatorLayer::setPropertyInternal(const std::string& n if (property == Property::AccuracyRadiusBorderColor) { setAccuracyRadiusBorderColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::AccuracyRadiusColor) { setAccuracyRadiusColor(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::Bearing) { @@ -586,7 +586,7 @@ optional LocationIndicatorLayer::setPropertyInternal(const std::string& n } setBearing(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::Location) { Error error; @@ -596,7 +596,7 @@ optional LocationIndicatorLayer::setPropertyInternal(const std::string& n } setLocation(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::BearingImage || property == Property::ShadowImage || property == Property::TopImage) { Error error; @@ -607,74 +607,74 @@ optional LocationIndicatorLayer::setPropertyInternal(const std::string& n if (property == Property::BearingImage) { setBearingImage(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::ShadowImage) { setShadowImage(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TopImage) { setTopImage(*typedValue); - return nullopt; + return std::nullopt; } } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::AccuracyRadiusTransition) { setAccuracyRadiusTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::AccuracyRadiusBorderColorTransition) { setAccuracyRadiusBorderColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::AccuracyRadiusColorTransition) { setAccuracyRadiusColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::BearingTransition) { setBearingTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::BearingImageSizeTransition) { setBearingImageSizeTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::ImageTiltDisplacementTransition) { setImageTiltDisplacementTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::LocationTransition) { setLocationTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::PerspectiveCompensationTransition) { setPerspectiveCompensationTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::ShadowImageSizeTransition) { setShadowImageSizeTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TopImageSizeTransition) { setTopImageSizeTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/raster_layer.cpp b/src/mbgl/style/layers/raster_layer.cpp index 95127fd95..94f068df3 100644 --- a/src/mbgl/style/layers/raster_layer.cpp +++ b/src/mbgl/style/layers/raster_layer.cpp @@ -388,7 +388,7 @@ Value RasterLayer::serialize() const { return result; } -optional RasterLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional RasterLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -406,37 +406,37 @@ optional RasterLayer::setPropertyInternal(const std::string& name, const if (property == Property::RasterBrightnessMax) { setRasterBrightnessMax(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::RasterBrightnessMin) { setRasterBrightnessMin(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::RasterContrast) { setRasterContrast(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::RasterFadeDuration) { setRasterFadeDuration(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::RasterHueRotate) { setRasterHueRotate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::RasterOpacity) { setRasterOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::RasterSaturation) { setRasterSaturation(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::RasterResampling) { @@ -447,53 +447,53 @@ optional RasterLayer::setPropertyInternal(const std::string& name, const } setRasterResampling(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::RasterBrightnessMaxTransition) { setRasterBrightnessMaxTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::RasterBrightnessMinTransition) { setRasterBrightnessMinTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::RasterContrastTransition) { setRasterContrastTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::RasterFadeDurationTransition) { setRasterFadeDurationTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::RasterHueRotateTransition) { setRasterHueRotateTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::RasterOpacityTransition) { setRasterOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::RasterResamplingTransition) { setRasterResamplingTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::RasterSaturationTransition) { setRasterSaturationTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/symbol_layer.cpp b/src/mbgl/style/layers/symbol_layer.cpp index ca08e7df0..a059f9144 100644 --- a/src/mbgl/style/layers/symbol_layer.cpp +++ b/src/mbgl/style/layers/symbol_layer.cpp @@ -1378,7 +1378,7 @@ Value SymbolLayer::serialize() const { return result; } -optional SymbolLayer::setPropertyInternal(const std::string& name, const Convertible& value) { +std::optional SymbolLayer::setPropertyInternal(const std::string& name, const Convertible& value) { const auto it = layerProperties.find(name.c_str()); if (it == layerProperties.end()) return Error{"layer doesn't support this property"}; @@ -1394,22 +1394,22 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconColor) { setIconColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconHaloColor) { setIconHaloColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextColor) { setTextColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextHaloColor) { setTextHaloColor(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconHaloBlur || property == Property::IconHaloWidth || @@ -1426,72 +1426,72 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconHaloBlur) { setIconHaloBlur(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconHaloWidth) { setIconHaloWidth(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconOpacity) { setIconOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextHaloBlur) { setTextHaloBlur(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextHaloWidth) { setTextHaloWidth(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextOpacity) { setTextOpacity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconRotate) { setIconRotate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconSize) { setIconSize(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::SymbolSortKey) { setSymbolSortKey(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextLetterSpacing) { setTextLetterSpacing(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextMaxWidth) { setTextMaxWidth(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextRadialOffset) { setTextRadialOffset(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextRotate) { setTextRotate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextSize) { setTextSize(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconTranslate || property == Property::TextTranslate) { @@ -1503,12 +1503,12 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconTranslate) { setIconTranslate(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextTranslate) { setTextTranslate(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconTranslateAnchor || property == Property::TextTranslateAnchor) { @@ -1520,12 +1520,12 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconTranslateAnchor) { setIconTranslateAnchor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextTranslateAnchor) { setTextTranslateAnchor(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconAllowOverlap || property == Property::IconIgnorePlacement || @@ -1541,47 +1541,47 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconAllowOverlap) { setIconAllowOverlap(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconIgnorePlacement) { setIconIgnorePlacement(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconKeepUpright) { setIconKeepUpright(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconOptional) { setIconOptional(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::SymbolAvoidEdges) { setSymbolAvoidEdges(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextAllowOverlap) { setTextAllowOverlap(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextIgnorePlacement) { setTextIgnorePlacement(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextKeepUpright) { setTextKeepUpright(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextOptional) { setTextOptional(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconAnchor || property == Property::TextAnchor) { @@ -1593,12 +1593,12 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconAnchor) { setIconAnchor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextAnchor) { setTextAnchor(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconImage) { @@ -1609,7 +1609,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setIconImage(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconOffset || property == Property::TextOffset) { Error error; @@ -1620,12 +1620,12 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconOffset) { setIconOffset(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextOffset) { setTextOffset(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconPadding || property == Property::SymbolSpacing || @@ -1639,27 +1639,27 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconPadding) { setIconPadding(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::SymbolSpacing) { setSymbolSpacing(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextLineHeight) { setTextLineHeight(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextMaxAngle) { setTextMaxAngle(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextPadding) { setTextPadding(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconPitchAlignment || property == Property::IconRotationAlignment || @@ -1672,22 +1672,22 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const if (property == Property::IconPitchAlignment) { setIconPitchAlignment(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconRotationAlignment) { setIconRotationAlignment(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextPitchAlignment) { setTextPitchAlignment(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextRotationAlignment) { setTextRotationAlignment(*typedValue); - return nullopt; + return std::nullopt; } } if (property == Property::IconTextFit) { @@ -1698,7 +1698,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setIconTextFit(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::IconTextFitPadding) { Error error; @@ -1708,7 +1708,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setIconTextFitPadding(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::SymbolPlacement) { Error error; @@ -1718,7 +1718,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setSymbolPlacement(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::SymbolZOrder) { Error error; @@ -1728,7 +1728,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setSymbolZOrder(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextField) { Error error; @@ -1738,7 +1738,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setTextField(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextFont) { Error error; @@ -1748,7 +1748,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setTextFont(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextJustify) { Error error; @@ -1758,7 +1758,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setTextJustify(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextTransform) { Error error; @@ -1768,7 +1768,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setTextTransform(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextVariableAnchor) { Error error; @@ -1779,7 +1779,7 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setTextVariableAnchor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::TextWritingMode) { Error error; @@ -1789,83 +1789,83 @@ optional SymbolLayer::setPropertyInternal(const std::string& name, const } setTextWritingMode(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::IconColorTransition) { setIconColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::IconHaloBlurTransition) { setIconHaloBlurTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::IconHaloColorTransition) { setIconHaloColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::IconHaloWidthTransition) { setIconHaloWidthTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::IconOpacityTransition) { setIconOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::IconTranslateTransition) { setIconTranslateTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::IconTranslateAnchorTransition) { setIconTranslateAnchorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TextColorTransition) { setTextColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TextHaloBlurTransition) { setTextHaloBlurTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TextHaloColorTransition) { setTextHaloColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TextHaloWidthTransition) { setTextHaloWidthTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TextOpacityTransition) { setTextOpacityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TextTranslateTransition) { setTextTranslateTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::TextTranslateAnchorTransition) { setTextTranslateAnchorTransition(*transition); - return nullopt; + return std::nullopt; } return Error{"layer doesn't support this property"}; diff --git a/src/mbgl/style/layers/symbol_layer_impl.cpp b/src/mbgl/style/layers/symbol_layer_impl.cpp index 60ebe57f9..18e5f1cd8 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.cpp +++ b/src/mbgl/style/layers/symbol_layer_impl.cpp @@ -36,7 +36,7 @@ void SymbolLayer::Impl::populateFontStack(std::set& fontStack) const if (value) { fontStack.insert(*value); } else { - Log::Warning(Event::ParseStyle, "Layer '%s' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression.", id.c_str()); + Log::Warning(Event::ParseStyle, "Layer '" + id + "' has an invalid value for text-font and will not render text. Output values must be contained as literals within the expression."); break; } } diff --git a/src/mbgl/style/layers/symbol_layer_impl.hpp b/src/mbgl/style/layers/symbol_layer_impl.hpp index ca9505a5f..826f444e1 100644 --- a/src/mbgl/style/layers/symbol_layer_impl.hpp +++ b/src/mbgl/style/layers/symbol_layer_impl.hpp @@ -143,7 +143,7 @@ public: private: bool hasFormatSectionOverrides() const; - mutable optional hasFormatSectionOverrides_; + mutable std::optional hasFormatSectionOverrides_; }; } // namespace style diff --git a/src/mbgl/style/light.cpp b/src/mbgl/style/light.cpp index e4ceed0ce..bd4647439 100644 --- a/src/mbgl/style/light.cpp +++ b/src/mbgl/style/light.cpp @@ -65,7 +65,7 @@ MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map Light::setProperty(const std::string& name, const Convertible& value) { +std::optional Light::setProperty(const std::string& name, const Convertible& value) { const auto it = properties.find(name.c_str()); if (it == properties.end()) { return Error { "light doesn't support this property" }; @@ -76,77 +76,77 @@ optional Light::setProperty(const std::string& name, const Convertible& v if (property == Property::Anchor) { Error error; - optional> typedValue = convert>(value, error, false, false); + std::optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } setAnchor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::Color) { Error error; - optional> typedValue = convert>(value, error, false, false); + std::optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } setColor(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::Intensity) { Error error; - optional> typedValue = convert>(value, error, false, false); + std::optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } setIntensity(*typedValue); - return nullopt; + return std::nullopt; } if (property == Property::Position) { Error error; - optional> typedValue = convert>(value, error, false, false); + std::optional> typedValue = convert>(value, error, false, false); if (!typedValue) { return error; } setPosition(*typedValue); - return nullopt; + return std::nullopt; } Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } if (property == Property::AnchorTransition) { setAnchorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::ColorTransition) { setColorTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::IntensityTransition) { setIntensityTransition(*transition); - return nullopt; + return std::nullopt; } if (property == Property::PositionTransition) { setPositionTransition(*transition); - return nullopt; + return std::nullopt; } diff --git a/src/mbgl/style/light.cpp.ejs b/src/mbgl/style/light.cpp.ejs index fb0c47dc6..346fc3c43 100644 --- a/src/mbgl/style/light.cpp.ejs +++ b/src/mbgl/style/light.cpp.ejs @@ -60,7 +60,7 @@ MAPBOX_ETERNAL_CONSTEXPR const auto properties = mapbox::eternal::hash_map Light::setProperty(const std::string& name, const Convertible& value) { +std::optional Light::setProperty(const std::string& name, const Convertible& value) { const auto it = properties.find(name.c_str()); if (it == properties.end()) { return Error { "light doesn't support this property" }; @@ -73,7 +73,7 @@ optional Light::setProperty(const std::string& name, const Convertible& v for (const property of properties) { const dataDriven = property['property-type'] === 'data-driven' || property['property-type'] === 'cross-faded-data-driven'; const convertTokens = property.name === 'icon-image' || property.name === 'text-field'; - const conversion = `optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; + const conversion = `std::optional<${propertyValueType(property)}> typedValue = convert<${propertyValueType(property)}>(value, error, ${dataDriven}, ${convertTokens})`; conversions[conversion] = conversions[conversion] || []; conversions[conversion].push(property); } @@ -89,25 +89,25 @@ optional Light::setProperty(const std::string& name, const Convertible& v } <% if (properties.length == 1) { %> set<%- camelize(properties[0].name) %>(*typedValue); - return nullopt; + return std::nullopt; <% } else for (const property of properties) { %> if (property == Property::<%- camelize(property.name) %>) { set<%- camelize(property.name) %>(*typedValue); - return nullopt; + return std::nullopt; } <% } %> } <% } %> Error error; - optional transition = convert(value, error); + std::optional transition = convert(value, error); if (!transition) { return error; } <% for (const property of properties) { %> if (property == Property::<%- camelize(property.name) %>Transition) { set<%- camelize(property.name) %>Transition(*transition); - return nullopt; + return std::nullopt; } <% } %> diff --git a/src/mbgl/style/parser.cpp b/src/mbgl/style/parser.cpp index 9d9b80276..4dbaaa152 100644 --- a/src/mbgl/style/parser.cpp +++ b/src/mbgl/style/parser.cpp @@ -121,7 +121,7 @@ StyleParseResult Parser::parse(const std::string& json) { void Parser::parseTransition(const JSValue& value) { conversion::Error error; - optional converted = conversion::convert(value, error); + std::optional converted = conversion::convert(value, error); if (!converted) { Log::Warning(Event::ParseStyle, error.message); return; @@ -132,7 +132,7 @@ void Parser::parseTransition(const JSValue& value) { void Parser::parseLight(const JSValue& value) { conversion::Error error; - optional converted = conversion::convert(value, error); + std::optional converted = conversion::convert(value, error); if (!converted) { Log::Warning(Event::ParseStyle, error.message); return; @@ -151,7 +151,7 @@ void Parser::parseSources(const JSValue& value) { std::string id { property.name.GetString(), property.name.GetStringLength() }; conversion::Error error; - optional> source = + std::optional> source = conversion::convert>(property.value, error, id); if (!source) { Log::Warning(Event::ParseStyle, error.message); @@ -189,7 +189,7 @@ void Parser::parseLayers(const JSValue& value) { const std::string layerID = { id.GetString(), id.GetStringLength() }; if (layersMap.find(layerID) != layersMap.end()) { - Log::Warning(Event::ParseStyle, "duplicate layer id %s", layerID.c_str()); + Log::Warning(Event::ParseStyle, "duplicate layer id " + layerID); continue; } @@ -222,7 +222,7 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique // Make sure we have not previously attempted to parse this layer. if (std::find(stack.begin(), stack.end(), id) != stack.end()) { - Log::Warning(Event::ParseStyle, "layer reference of '%s' is circular", id.c_str()); + Log::Warning(Event::ParseStyle, "layer reference of '" + id + "' is circular"); return; } @@ -230,14 +230,14 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique // This layer is referencing another layer. Recursively parse that layer. const JSValue& refVal = value["ref"]; if (!refVal.IsString()) { - Log::Warning(Event::ParseStyle, "layer ref of '%s' must be a string", id.c_str()); + Log::Warning(Event::ParseStyle, "layer ref of '" + id + "' must be a string"); return; } const std::string ref { refVal.GetString(), refVal.GetStringLength() }; auto it = layersMap.find(ref); if (it == layersMap.end()) { - Log::Warning(Event::ParseStyle, "layer '%s' references unknown layer %s", id.c_str(), ref.c_str()); + Log::Warning(Event::ParseStyle, "layer '" + id + "' references unknown layer " + ref); return; } @@ -257,7 +257,7 @@ void Parser::parseLayer(const std::string& id, const JSValue& value, std::unique conversion::setPaintProperties(*layer, conversion::Convertible(&value)); } else { conversion::Error error; - optional> converted = conversion::convert>(value, error); + std::optional> converted = conversion::convert>(value, error); if (!converted) { Log::Warning(Event::ParseStyle, error.message); return; diff --git a/src/mbgl/style/properties.hpp b/src/mbgl/style/properties.hpp index 4279490eb..b6d3ac53a 100644 --- a/src/mbgl/style/properties.hpp +++ b/src/mbgl/style/properties.hpp @@ -75,7 +75,7 @@ public: } private: - mutable optional>> prior; + mutable std::optional>> prior; TimePoint begin; TimePoint end; Value value; diff --git a/src/mbgl/style/rapidjson_conversion.hpp b/src/mbgl/style/rapidjson_conversion.hpp index ba2219577..2e34376a6 100644 --- a/src/mbgl/style/rapidjson_conversion.hpp +++ b/src/mbgl/style/rapidjson_conversion.hpp @@ -33,7 +33,7 @@ public: return value->IsObject(); } - static optional objectMember(const JSValue* value, const char * name) { + static std::optional objectMember(const JSValue* value, const char * name) { if (!value->HasMember(name)) { return {}; } @@ -42,10 +42,10 @@ public: } template - static optional eachMember(const JSValue* value, Fn&& fn) { + static std::optional eachMember(const JSValue* value, Fn&& fn) { assert(value->IsObject()); for (const auto& property : value->GetObject()) { - optional result = + std::optional result = fn({ property.name.GetString(), property.name.GetStringLength() }, &property.value); if (result) { return result; @@ -54,35 +54,35 @@ public: return {}; } - static optional toBool(const JSValue* value) { + static std::optional toBool(const JSValue* value) { if (!value->IsBool()) { return {}; } return value->GetBool(); } - static optional toNumber(const JSValue* value) { + static std::optional toNumber(const JSValue* value) { if (!value->IsNumber()) { return {}; } return static_cast(value->GetDouble()); } - static optional toDouble(const JSValue* value) { + static std::optional toDouble(const JSValue* value) { if (!value->IsNumber()) { return {}; } return value->GetDouble(); } - static optional toString(const JSValue* value) { + static std::optional toString(const JSValue* value) { if (!value->IsString()) { return {}; } return {{ value->GetString(), value->GetStringLength() }}; } - static optional toValue(const JSValue* value) { + static std::optional toValue(const JSValue* value) { switch (value->GetType()) { case rapidjson::kNullType: case rapidjson::kFalseType: @@ -104,7 +104,7 @@ public: } } - static optional toGeoJSON(const JSValue* value, Error& error) { + static std::optional toGeoJSON(const JSValue* value, Error& error) { try { return mapbox::geojson::convert(*value); } catch (const std::exception& ex) { @@ -115,7 +115,7 @@ public: }; template -optional convert(const JSValue& value, Error& error, Args&&...args) { +std::optional convert(const JSValue& value, Error& error, Args&&...args) { return convert(Convertible(&value), error, std::forward(args)...); } diff --git a/src/mbgl/style/source.cpp b/src/mbgl/style/source.cpp index b2a9473fe..1a8efc08b 100644 --- a/src/mbgl/style/source.cpp +++ b/src/mbgl/style/source.cpp @@ -23,7 +23,7 @@ std::string Source::getID() const { return baseImpl->id; } -optional Source::getAttribution() const { +std::optional Source::getAttribution() const { return baseImpl->getAttribution(); } @@ -43,7 +43,7 @@ void Source::setObserver(SourceObserver* observer_) { observer = observer_ ? observer_ : &nullObserver; } -void Source::setPrefetchZoomDelta(optional delta) noexcept { +void Source::setPrefetchZoomDelta(std::optional delta) noexcept { if (getPrefetchZoomDelta() == delta) return; auto newImpl = createMutable(); newImpl->setPrefetchZoomDelta(std::move(delta)); @@ -51,7 +51,7 @@ void Source::setPrefetchZoomDelta(optional delta) noexcept { observer->onSourceChanged(*this); } -optional Source::getPrefetchZoomDelta() const noexcept { +std::optional Source::getPrefetchZoomDelta() const noexcept { return baseImpl->getPrefetchZoomDelta(); } @@ -67,7 +67,7 @@ Duration Source::getMinimumTileUpdateInterval() const noexcept { return baseImpl->getMinimumTileUpdateInterval(); } -void Source::setMaxOverscaleFactorForParentTiles(optional overscaleFactor) noexcept { +void Source::setMaxOverscaleFactorForParentTiles(std::optional overscaleFactor) noexcept { if (getMaxOverscaleFactorForParentTiles() == overscaleFactor) return; auto newImpl = createMutable(); newImpl->setMaxOverscaleFactorForParentTiles(std::move(overscaleFactor)); @@ -75,13 +75,13 @@ void Source::setMaxOverscaleFactorForParentTiles(optional overscaleFact observer->onSourceChanged(*this); } -optional Source::getMaxOverscaleFactorForParentTiles() const noexcept { +std::optional Source::getMaxOverscaleFactorForParentTiles() const noexcept { return baseImpl->getMaxOverscaleFactorForParentTiles(); } void Source::dumpDebugLogs() const { - Log::Info(Event::General, "Source::id: %s", getID().c_str()); - Log::Info(Event::General, "Source::loaded: %d", loaded); + Log::Info(Event::General, "Source::id: " + getID()); + Log::Info(Event::General, "Source::loaded: " + std::to_string(loaded)); } } // namespace style diff --git a/src/mbgl/style/source_impl.cpp b/src/mbgl/style/source_impl.cpp index 98433a8c8..0407b730c 100644 --- a/src/mbgl/style/source_impl.cpp +++ b/src/mbgl/style/source_impl.cpp @@ -6,10 +6,10 @@ namespace mbgl { namespace style { namespace { -void WarnIfOverscaleFactorCapsPrefetchDelta(const optional& overscale, const optional& prefetch) { +void WarnIfOverscaleFactorCapsPrefetchDelta(const std::optional& overscale, const std::optional& prefetch) { const uint8_t prefetchDelta = std::max(util::DEFAULT_PREFETCH_ZOOM_DELTA, prefetch.value_or(0u)); if (overscale && *overscale < prefetchDelta) { - Log::Warning(Event::Style, "Parent tile overscale factor will cap prefetch delta to %d", int(*overscale)); + Log::Warning(Event::Style, "Parent tile overscale factor will cap prefetch delta to " + std::to_string(int(*overscale))); } } } // namespace @@ -19,21 +19,21 @@ Source::Impl::Impl(SourceType type_, std::string id_) id(std::move(id_)) { } -void Source::Impl::setPrefetchZoomDelta(optional delta) noexcept { +void Source::Impl::setPrefetchZoomDelta(std::optional delta) noexcept { prefetchZoomDelta = std::move(delta); WarnIfOverscaleFactorCapsPrefetchDelta(maxOverscaleFactor, prefetchZoomDelta); } -optional Source::Impl::getPrefetchZoomDelta() const noexcept { +std::optional Source::Impl::getPrefetchZoomDelta() const noexcept { return prefetchZoomDelta; } -void Source::Impl::setMaxOverscaleFactorForParentTiles(optional overscaleFactor) noexcept { +void Source::Impl::setMaxOverscaleFactorForParentTiles(std::optional overscaleFactor) noexcept { maxOverscaleFactor = std::move(overscaleFactor); WarnIfOverscaleFactorCapsPrefetchDelta(maxOverscaleFactor, prefetchZoomDelta); } -optional Source::Impl::getMaxOverscaleFactorForParentTiles() const noexcept { +std::optional Source::Impl::getMaxOverscaleFactorForParentTiles() const noexcept { return maxOverscaleFactor; } diff --git a/src/mbgl/style/source_impl.hpp b/src/mbgl/style/source_impl.hpp index 87a30dcf9..daedaa271 100644 --- a/src/mbgl/style/source_impl.hpp +++ b/src/mbgl/style/source_impl.hpp @@ -18,13 +18,13 @@ public: Impl& operator=(const Impl&) = delete; - virtual optional getAttribution() const = 0; - void setPrefetchZoomDelta(optional delta) noexcept; - optional getPrefetchZoomDelta() const noexcept; + virtual std::optional getAttribution() const = 0; + void setPrefetchZoomDelta(std::optional delta) noexcept; + std::optional getPrefetchZoomDelta() const noexcept; void setMinimumTileUpdateInterval(Duration interval) { minimumTileUpdateInterval = interval; } Duration getMinimumTileUpdateInterval() const { return minimumTileUpdateInterval; } - void setMaxOverscaleFactorForParentTiles(optional overscaleFactor) noexcept; - optional getMaxOverscaleFactorForParentTiles() const noexcept; + void setMaxOverscaleFactorForParentTiles(std::optional overscaleFactor) noexcept; + std::optional getMaxOverscaleFactorForParentTiles() const noexcept; bool isVolatile() const { return volatileFlag; } void setVolatile(bool set) { volatileFlag = set; } @@ -32,8 +32,8 @@ public: const std::string id; protected: - optional prefetchZoomDelta; - optional maxOverscaleFactor; + std::optional prefetchZoomDelta; + std::optional maxOverscaleFactor; Duration minimumTileUpdateInterval{Duration::zero()}; bool volatileFlag = false; diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.cpp b/src/mbgl/style/sources/custom_geometry_source_impl.cpp index 184718fd7..fbaa25217 100644 --- a/src/mbgl/style/sources/custom_geometry_source_impl.cpp +++ b/src/mbgl/style/sources/custom_geometry_source_impl.cpp @@ -17,7 +17,7 @@ bool CustomGeometrySource::Impl::operator!=(const Impl& other) const noexcept { return tileOptions != other.tileOptions || zoomRange != other.zoomRange || bool(loaderRef) != bool(other.loaderRef); } -optional CustomGeometrySource::Impl::getAttribution() const { +std::optional CustomGeometrySource::Impl::getAttribution() const { return {}; } @@ -29,7 +29,7 @@ Range CustomGeometrySource::Impl::getZoomRange() const { return zoomRange; } -optional> CustomGeometrySource::Impl::getTileLoader() const { +std::optional> CustomGeometrySource::Impl::getTileLoader() const { return loaderRef; } diff --git a/src/mbgl/style/sources/custom_geometry_source_impl.hpp b/src/mbgl/style/sources/custom_geometry_source_impl.hpp index a441b38f6..920280ef5 100644 --- a/src/mbgl/style/sources/custom_geometry_source_impl.hpp +++ b/src/mbgl/style/sources/custom_geometry_source_impl.hpp @@ -13,17 +13,17 @@ public: Impl(std::string id, const CustomGeometrySource::Options& options); Impl(const Impl&, const ActorRef&); - optional getAttribution() const final; + std::optional getAttribution() const final; Immutable getTileOptions() const; Range getZoomRange() const; - optional> getTileLoader() const; + std::optional> getTileLoader() const; bool operator!=(const Impl&) const noexcept; private: Immutable tileOptions; Range zoomRange; - optional> loaderRef; + std::optional> loaderRef; }; } // namespace style diff --git a/src/mbgl/style/sources/geojson_source.cpp b/src/mbgl/style/sources/geojson_source.cpp index d750d6b1d..86c504f94 100644 --- a/src/mbgl/style/sources/geojson_source.cpp +++ b/src/mbgl/style/sources/geojson_source.cpp @@ -61,7 +61,7 @@ void GeoJSONSource::setGeoJSONData(std::shared_ptr geoJSONData) { observer->onSourceChanged(*this); } -optional GeoJSONSource::getURL() const { +std::optional GeoJSONSource::getURL() const { return url; } @@ -94,11 +94,11 @@ void GeoJSONSource::loadDescription(FileSource& fileSource) { auto& current = static_cast(*currentImpl); conversion::Error error; std::shared_ptr geoJSONData; - if (optional geoJSON = conversion::convertJSON(*data, error)) { + if (std::optional geoJSON = conversion::convertJSON(*data, error)) { geoJSONData = createGeoJSONData(*geoJSON, current); } else { // Create an empty GeoJSON VT object to make sure we're not infinitely waiting for tiles to load. - Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: %s", error.message.c_str()); + Log::Error(Event::ParseStyle, "Failed to parse GeoJSON data: " + error.message); } return makeMutable(current, std::move(geoJSONData)); }; diff --git a/src/mbgl/style/sources/geojson_source_impl.cpp b/src/mbgl/style/sources/geojson_source_impl.cpp index 1ee8b2d39..42f273c02 100644 --- a/src/mbgl/style/sources/geojson_source_impl.cpp +++ b/src/mbgl/style/sources/geojson_source_impl.cpp @@ -76,10 +76,10 @@ class SuperclusterData final : public GeoJSONData { template T evaluateFeature(const mapbox::feature::feature& f, const std::shared_ptr& expression, - optional accumulated = nullopt) { + std::optional accumulated = std::nullopt) { const expression::EvaluationResult result = expression->evaluate(accumulated, f); if (result) { - optional typed = expression::fromExpressionValue(*result); + std::optional typed = expression::fromExpressionValue(*result); if (typed) { return std::move(*typed); } @@ -113,7 +113,7 @@ std::shared_ptr GeoJSONData::create(const GeoJSON& geoJSON, continue; } feature->properties = toFill; - optional accumulated(toReturn[p.first]); + std::optional accumulated(toReturn[p.first]); toReturn[p.first] = evaluateFeature(*feature, p.second.second, accumulated); } }; @@ -146,7 +146,7 @@ std::weak_ptr GeoJSONSource::Impl::getData() const { return data; } -optional GeoJSONSource::Impl::getAttribution() const { +std::optional GeoJSONSource::Impl::getAttribution() const { return {}; } diff --git a/src/mbgl/style/sources/geojson_source_impl.hpp b/src/mbgl/style/sources/geojson_source_impl.hpp index fd23ebdbe..ca4addcdd 100644 --- a/src/mbgl/style/sources/geojson_source_impl.hpp +++ b/src/mbgl/style/sources/geojson_source_impl.hpp @@ -21,7 +21,7 @@ public: std::weak_ptr getData() const; const Immutable& getOptions() const { return options; } - optional getAttribution() const final; + std::optional getAttribution() const final; private: Immutable options; diff --git a/src/mbgl/style/sources/image_source.cpp b/src/mbgl/style/sources/image_source.cpp index 144d007cc..dd64d155c 100644 --- a/src/mbgl/style/sources/image_source.cpp +++ b/src/mbgl/style/sources/image_source.cpp @@ -50,7 +50,7 @@ void ImageSource::setImage(PremultipliedImage&& image_) { observer->onSourceChanged(*this); } -optional ImageSource::getURL() const { +std::optional ImageSource::getURL() const { return url; } diff --git a/src/mbgl/style/sources/image_source_impl.cpp b/src/mbgl/style/sources/image_source_impl.cpp index 7a4f5ac01..4c21a01db 100644 --- a/src/mbgl/style/sources/image_source_impl.cpp +++ b/src/mbgl/style/sources/image_source_impl.cpp @@ -25,7 +25,7 @@ std::array ImageSource::Impl::getCoordinates() const { return coords; } -optional ImageSource::Impl::getAttribution() const { +std::optional ImageSource::Impl::getAttribution() const { return {}; } diff --git a/src/mbgl/style/sources/image_source_impl.hpp b/src/mbgl/style/sources/image_source_impl.hpp index 16ddcfda7..494e6deeb 100644 --- a/src/mbgl/style/sources/image_source_impl.hpp +++ b/src/mbgl/style/sources/image_source_impl.hpp @@ -20,7 +20,7 @@ public: std::shared_ptr getImage() const; std::array getCoordinates() const; - optional getAttribution() const final; + std::optional getAttribution() const final; private: std::array coords; std::shared_ptr image; diff --git a/src/mbgl/style/sources/raster_source.cpp b/src/mbgl/style/sources/raster_source.cpp index 6e6832c60..415e5152b 100644 --- a/src/mbgl/style/sources/raster_source.cpp +++ b/src/mbgl/style/sources/raster_source.cpp @@ -28,7 +28,7 @@ const variant& RasterSource::getURLOrTileset() const { return urlOrTileset; } -optional RasterSource::getURL() const { +std::optional RasterSource::getURL() const { if (urlOrTileset.is()) { return {}; } @@ -64,7 +64,7 @@ void RasterSource::loadDescription(FileSource& fileSource) { observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON"))); } else { conversion::Error error; - optional tileset = conversion::convertJSON(*res.data, error); + std::optional tileset = conversion::convertJSON(*res.data, error); if (!tileset) { observer->onSourceError(*this, std::make_exception_ptr(util::StyleParseException(error.message))); return; diff --git a/src/mbgl/style/sources/raster_source_impl.cpp b/src/mbgl/style/sources/raster_source_impl.cpp index 4201fd057..62fa71710 100644 --- a/src/mbgl/style/sources/raster_source_impl.cpp +++ b/src/mbgl/style/sources/raster_source_impl.cpp @@ -18,7 +18,7 @@ uint16_t RasterSource::Impl::getTileSize() const { return tileSize; } -optional RasterSource::Impl::getAttribution() const { +std::optional RasterSource::Impl::getAttribution() const { if (!tileset) { return {}; } diff --git a/src/mbgl/style/sources/raster_source_impl.hpp b/src/mbgl/style/sources/raster_source_impl.hpp index bb5845514..23443bf27 100644 --- a/src/mbgl/style/sources/raster_source_impl.hpp +++ b/src/mbgl/style/sources/raster_source_impl.hpp @@ -13,9 +13,9 @@ public: uint16_t getTileSize() const; - optional getAttribution() const final; + std::optional getAttribution() const final; - const optional tileset; + const std::optional tileset; private: uint16_t tileSize; diff --git a/src/mbgl/style/sources/vector_source.cpp b/src/mbgl/style/sources/vector_source.cpp index 5571b1f04..35b656c5b 100644 --- a/src/mbgl/style/sources/vector_source.cpp +++ b/src/mbgl/style/sources/vector_source.cpp @@ -14,8 +14,8 @@ namespace mbgl { namespace style { -VectorSource::VectorSource(std::string id, variant urlOrTileset_, optional maxZoom_, - optional minZoom_) +VectorSource::VectorSource(std::string id, variant urlOrTileset_, std::optional maxZoom_, + std::optional minZoom_) : Source(makeMutable(std::move(id))), urlOrTileset(std::move(urlOrTileset_)), maxZoom(std::move(maxZoom_)), @@ -31,7 +31,7 @@ const variant& VectorSource::getURLOrTileset() const { return urlOrTileset; } -optional VectorSource::getURL() const { +std::optional VectorSource::getURL() const { if (urlOrTileset.is()) { return {}; } @@ -63,7 +63,7 @@ void VectorSource::loadDescription(FileSource& fileSource) { observer->onSourceError(*this, std::make_exception_ptr(std::runtime_error("unexpectedly empty TileJSON"))); } else { conversion::Error error; - optional tileset = conversion::convertJSON(*res.data, error); + auto tileset = conversion::convertJSON(*res.data, error); if (!tileset) { observer->onSourceError(*this, std::make_exception_ptr(util::StyleParseException(error.message))); return; diff --git a/src/mbgl/style/sources/vector_source_impl.cpp b/src/mbgl/style/sources/vector_source_impl.cpp index 8f85a41dd..c46dab206 100644 --- a/src/mbgl/style/sources/vector_source_impl.cpp +++ b/src/mbgl/style/sources/vector_source_impl.cpp @@ -12,7 +12,7 @@ VectorSource::Impl::Impl(const Impl& other, Tileset tileset_) tileset(std::move(tileset_)) { } -optional VectorSource::Impl::getAttribution() const { +std::optional VectorSource::Impl::getAttribution() const { if (!tileset) { return {}; } diff --git a/src/mbgl/style/sources/vector_source_impl.hpp b/src/mbgl/style/sources/vector_source_impl.hpp index 4526fbe35..4d7b9d259 100644 --- a/src/mbgl/style/sources/vector_source_impl.hpp +++ b/src/mbgl/style/sources/vector_source_impl.hpp @@ -11,9 +11,9 @@ public: Impl(std::string id); Impl(const Impl&, Tileset); - optional getAttribution() const final; + std::optional getAttribution() const final; - const optional tileset; + const std::optional tileset; }; } // namespace style diff --git a/src/mbgl/style/style.cpp b/src/mbgl/style/style.cpp index 902cc1687..880a9b1ba 100644 --- a/src/mbgl/style/style.cpp +++ b/src/mbgl/style/style.cpp @@ -60,9 +60,9 @@ const Light* Style::getLight() const { return impl->getLight(); } -optional Style::getImage(const std::string& name) const { +std::optional Style::getImage(const std::string& name) const { auto image = impl->getImage(name); - if (!image) return nullopt; + if (!image) return std::nullopt; return style::Image(std::move(*image)); } @@ -122,7 +122,7 @@ const Layer* Style::getLayer(const std::string& layerID) const { return impl->getLayer(layerID); } -void Style::addLayer(std::unique_ptr layer, const optional& before) { +void Style::addLayer(std::unique_ptr layer, const std::optional& before) { impl->mutated = true; impl->addLayer(std::move(layer), before); } diff --git a/src/mbgl/style/style_impl.cpp b/src/mbgl/style/style_impl.cpp index 25cd122b8..8bba8220c 100644 --- a/src/mbgl/style/style_impl.cpp +++ b/src/mbgl/style/style_impl.cpp @@ -163,7 +163,7 @@ std::unique_ptr Style::Impl::removeSource(const std::string& id) { // Check if source is in use for (const auto& layer: layers) { if (layer->getSourceID() == id) { - Log::Warning(Event::General, "Source '%s' is in use, cannot remove", id.c_str()); + Log::Warning(Event::General, "Source '" + id + "' is in use, cannot remove"); return nullptr; } } @@ -190,7 +190,7 @@ Layer* Style::Impl::getLayer(const std::string& id) const { return layers.get(id); } -Layer* Style::Impl::addLayer(std::unique_ptr layer, const optional& before) { +Layer* Style::Impl::addLayer(std::unique_ptr layer, const std::optional& before) { // TODO: verify source if (Source* source = sources.get(layer->getSourceID())) { if (!source->supportsLayerType(layer->baseImpl->getTypeInfo())) { @@ -294,16 +294,16 @@ void Style::Impl::removeImage(const std::string& id) { auto found = std::find_if(newImages->begin(), newImages->end(), [&id](const auto& image) { return image->id == id; }); if (found == newImages->end()) { - Log::Warning(Event::General, "Image '%s' is not present in style, cannot remove", id.c_str()); + Log::Warning(Event::General, "Image '" + id + "' is not present in style, cannot remove"); return; } newImages->erase(found); images = std::move(newImages); } -optional> Style::Impl::getImage(const std::string& id) const { +std::optional> Style::Impl::getImage(const std::string& id) const { auto found = std::find_if(images->begin(), images->end(), [&id](const auto& image) { return image->id == id; }); - if (found == images->end()) return nullopt; + if (found == images->end()) return std::nullopt; return *found; } @@ -325,8 +325,7 @@ void Style::Impl::onSourceChanged(Source& source) { void Style::Impl::onSourceError(Source& source, std::exception_ptr error) { lastError = error; - Log::Error(Event::Style, "Failed to load source %s: %s", - source.getID().c_str(), util::toString(error).c_str()); + Log::Error(Event::Style, std::string("Failed to load source ") + source.getID() + ": " + util::toString(error)); observer->onSourceError(source, error); observer->onResourceError(error); } @@ -365,7 +364,7 @@ void Style::Impl::onSpriteLoaded(std::vector> imag void Style::Impl::onSpriteError(std::exception_ptr error) { lastError = error; - Log::Error(Event::Style, "Failed to load sprite: %s", util::toString(error).c_str()); + Log::Error(Event::Style, "Failed to load sprite: " + util::toString(error)); observer->onResourceError(error); // Unblock rendering tiles (even though sprite request has failed). spriteLoaded = true; @@ -382,7 +381,7 @@ void Style::Impl::onLightChanged(const Light&) { } void Style::Impl::dumpDebugLogs() const { - Log::Info(Event::General, "styleURL: %s", url.c_str()); + Log::Info(Event::General, "styleURL: " + url); for (const auto& source : sources) { source->dumpDebugLogs(); } diff --git a/src/mbgl/style/style_impl.hpp b/src/mbgl/style/style_impl.hpp index 4573a3966..69e82f530 100644 --- a/src/mbgl/style/style_impl.hpp +++ b/src/mbgl/style/style_impl.hpp @@ -15,7 +15,6 @@ #include #include -#include #include #include @@ -65,7 +64,7 @@ public: std::vector getLayers() const; Layer* getLayer(const std::string& id) const; - Layer* addLayer(std::unique_ptr, const optional& beforeLayerID = {}); + Layer* addLayer(std::unique_ptr, const std::optional& beforeLayerID = std::nullopt); std::unique_ptr removeLayer(const std::string& layerID); std::string getName() const; @@ -77,7 +76,7 @@ public: void setLight(std::unique_ptr); Light* getLight() const; - optional> getImage(const std::string&) const; + std::optional> getImage(const std::string&) const; void addImage(std::unique_ptr); void removeImage(const std::string&); diff --git a/src/mbgl/text/collision_feature.cpp b/src/mbgl/text/collision_feature.cpp index 88dd71be8..81a907749 100644 --- a/src/mbgl/text/collision_feature.cpp +++ b/src/mbgl/text/collision_feature.cpp @@ -10,7 +10,7 @@ CollisionFeature::CollisionFeature(const GeometryCoordinates& line, const float bottom, const float left, const float right, - const optional& collisionPadding, + const std::optional& collisionPadding, const float boxScale, const float padding, const style::SymbolPlacementType placement, diff --git a/src/mbgl/text/collision_feature.hpp b/src/mbgl/text/collision_feature.hpp index 248660083..9fe6fa977 100644 --- a/src/mbgl/text/collision_feature.hpp +++ b/src/mbgl/text/collision_feature.hpp @@ -86,7 +86,7 @@ public: shapedText.bottom, shapedText.left, shapedText.right, - nullopt, + std::nullopt, boxScale, padding, placement, @@ -102,7 +102,7 @@ public: // See: https://github.com/mapbox/mapbox-gl-js/issues/4861 CollisionFeature(const GeometryCoordinates& line, const Anchor& anchor, - optional shapedIcon, + std::optional shapedIcon, const float boxScale, const float padding, const IndexedSubfeature& indexedFeature_, @@ -113,7 +113,7 @@ public: (shapedIcon ? shapedIcon->bottom() : 0), (shapedIcon ? shapedIcon->left() : 0), (shapedIcon ? shapedIcon->right() : 0), - (shapedIcon ? shapedIcon->collisionPadding() : optional{nullopt}), + (shapedIcon ? shapedIcon->collisionPadding() : std::optional{std::nullopt}), boxScale, padding, style::SymbolPlacementType::Point, @@ -127,7 +127,7 @@ public: float bottom, float left, float right, - const optional& collisionPadding, + const std::optional& collisionPadding, float boxScale, float padding, style::SymbolPlacementType, diff --git a/src/mbgl/text/collision_index.cpp b/src/mbgl/text/collision_index.cpp index 364887de2..4d8295ab1 100644 --- a/src/mbgl/text/collision_index.cpp +++ b/src/mbgl/text/collision_index.cpp @@ -154,8 +154,8 @@ std::pair CollisionIndex::placeFeature( const bool allowOverlap, const bool pitchWithMap, const bool collisionDebug, - const optional& avoidEdges, - const optional>& collisionGroupPredicate, + const std::optional& avoidEdges, + const std::optional>& collisionGroupPredicate, std::vector& projectedBoxes) { assert(projectedBoxes.empty()); if (!feature.alongLine) { @@ -185,8 +185,8 @@ std::pair CollisionIndex::placeLineFeature( const bool allowOverlap, const bool pitchWithMap, const bool collisionDebug, - const optional& avoidEdges, - const optional>& collisionGroupPredicate, + const std::optional& avoidEdges, + const std::optional>& collisionGroupPredicate, std::vector& projectedBoxes) { assert(feature.alongLine); assert(projectedBoxes.empty()); diff --git a/src/mbgl/text/collision_index.hpp b/src/mbgl/text/collision_index.hpp index 1fccdf493..b90242bb4 100644 --- a/src/mbgl/text/collision_index.hpp +++ b/src/mbgl/text/collision_index.hpp @@ -1,9 +1,9 @@ #pragma once #include + #include #include -#include #include #include @@ -43,8 +43,8 @@ public: bool allowOverlap, bool pitchWithMap, bool collisionDebug, - const optional& avoidEdges, - const optional>& collisionGroupPredicate, + const std::optional& avoidEdges, + const std::optional>& collisionGroupPredicate, std::vector& /*out*/); void insertFeature(const CollisionFeature& feature, const std::vector&, bool ignorePlacement, uint32_t bucketInstanceId, uint16_t collisionGroupId); @@ -74,8 +74,8 @@ private: bool allowOverlap, bool pitchWithMap, bool collisionDebug, - const optional& avoidEdges, - const optional>& collisionGroupPredicate, + const std::optional& avoidEdges, + const std::optional>& collisionGroupPredicate, std::vector& /*out*/); float approximateTileDistance(const TileDistance& tileDistance, diff --git a/src/mbgl/text/cross_tile_symbol_index.hpp b/src/mbgl/text/cross_tile_symbol_index.hpp index 8dfdb8466..50d911239 100644 --- a/src/mbgl/text/cross_tile_symbol_index.hpp +++ b/src/mbgl/text/cross_tile_symbol_index.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include diff --git a/src/mbgl/text/get_anchors.cpp b/src/mbgl/text/get_anchors.cpp index 7436c5926..ab2abc1bd 100644 --- a/src/mbgl/text/get_anchors.cpp +++ b/src/mbgl/text/get_anchors.cpp @@ -130,7 +130,7 @@ Anchors getAnchors(const GeometryCoordinates& line, return resample(line, offset, spacing, angleWindowSize, maxAngle, labelLength, continuedLine, false); } -optional getCenterAnchor(const GeometryCoordinates& line, +std::optional getCenterAnchor(const GeometryCoordinates& line, const float maxAngle, const float textLeft, const float textRight, @@ -167,7 +167,7 @@ optional getCenterAnchor(const GeometryCoordinates& line, return anchor; } - return nullopt; + return std::nullopt; } prevDistance += segmentDistance; diff --git a/src/mbgl/text/get_anchors.hpp b/src/mbgl/text/get_anchors.hpp index 19938b666..357ece3df 100644 --- a/src/mbgl/text/get_anchors.hpp +++ b/src/mbgl/text/get_anchors.hpp @@ -17,7 +17,7 @@ Anchors getAnchors(const GeometryCoordinates& line, float boxScale, float overscaling); -optional getCenterAnchor(const GeometryCoordinates& line, +std::optional getCenterAnchor(const GeometryCoordinates& line, float maxAngle, float textLeft, float textRight, diff --git a/src/mbgl/text/glyph.hpp b/src/mbgl/text/glyph.hpp index 2d8853e92..d1d1bd4cb 100644 --- a/src/mbgl/text/glyph.hpp +++ b/src/mbgl/text/glyph.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -55,7 +54,7 @@ public: GlyphMetrics metrics; }; -using Glyphs = std::map>>; +using Glyphs = std::map>>; using GlyphMap = std::map; class PositionedGlyph { @@ -68,7 +67,7 @@ public: float scale_, Rect rect_, GlyphMetrics metrics_, - optional imageID_, + std::optional imageID_, std::size_t sectionIndex_ = 0) : glyph(glyph_), x(x_), @@ -89,7 +88,7 @@ public: float scale = 0.0; Rect rect; GlyphMetrics metrics; - optional imageID; + std::optional imageID; // Maps positioned glyph to TaggedString section std::size_t sectionIndex; }; diff --git a/src/mbgl/text/glyph_manager.cpp b/src/mbgl/text/glyph_manager.cpp index 8aa9063ea..924e93152 100644 --- a/src/mbgl/text/glyph_manager.cpp +++ b/src/mbgl/text/glyph_manager.cpp @@ -141,7 +141,7 @@ void GlyphManager::notify(GlyphRequestor& requestor, const GlyphDependencies& gl if (it != entry.glyphs.end()) { glyphs.emplace(*it); } else { - glyphs.emplace(glyphID, std::experimental::nullopt); + glyphs.emplace(glyphID, std::nullopt); } } } diff --git a/src/mbgl/text/glyph_manager.hpp b/src/mbgl/text/glyph_manager.hpp index 8603a320d..a53636d0a 100644 --- a/src/mbgl/text/glyph_manager.hpp +++ b/src/mbgl/text/glyph_manager.hpp @@ -28,7 +28,7 @@ class GlyphManager { public: GlyphManager(const GlyphManager&) = delete; GlyphManager& operator=(const GlyphManager&) = delete; - explicit GlyphManager(std::unique_ptr = std::make_unique(optional())); + explicit GlyphManager(std::unique_ptr = std::make_unique(std::optional())); ~GlyphManager(); // Workers send a `getGlyphs` message to the main thread once they have determined diff --git a/src/mbgl/text/language_tag.cpp b/src/mbgl/text/language_tag.cpp index f8eee22b0..02f01c3d6 100644 --- a/src/mbgl/text/language_tag.cpp +++ b/src/mbgl/text/language_tag.cpp @@ -209,7 +209,7 @@ LanguageTag LanguageTag::fromBCP47(const std::string& bcp47Tag) { } } -LanguageTag::LanguageTag(optional language_, optional script_, optional region_) +LanguageTag::LanguageTag(std::optional language_, std::optional script_, std::optional region_) : language(std::move(language_)) , script(std::move(script_)) , region(std::move(region_)) diff --git a/src/mbgl/text/language_tag.hpp b/src/mbgl/text/language_tag.hpp index 7a6a16531..a499cd321 100644 --- a/src/mbgl/text/language_tag.hpp +++ b/src/mbgl/text/language_tag.hpp @@ -1,8 +1,7 @@ #pragma once -#include - #include +#include /* Use LanguageTag to go back and forth between BCP 47 language tags @@ -31,14 +30,14 @@ namespace mbgl { struct LanguageTag { LanguageTag() = default; - LanguageTag(optional language_, optional script_, optional region_); + LanguageTag(std::optional language_, std::optional script_, std::optional region_); static LanguageTag fromBCP47(const std::string& bcp47Tag); std::string toBCP47() const; - optional language; // ISO 639 - optional script; // ISO 15924 - optional region; // ISO 3316-1 || UN M.49 + std::optional language; // ISO 639 + std::optional script; // ISO 15924 + std::optional region; // ISO 3316-1 || UN M.49 }; } // end namespace mbgl diff --git a/src/mbgl/text/local_glyph_rasterizer.hpp b/src/mbgl/text/local_glyph_rasterizer.hpp index 4582aab10..4cc0c6a18 100644 --- a/src/mbgl/text/local_glyph_rasterizer.hpp +++ b/src/mbgl/text/local_glyph_rasterizer.hpp @@ -33,7 +33,7 @@ namespace mbgl { class LocalGlyphRasterizer { public: virtual ~LocalGlyphRasterizer(); - LocalGlyphRasterizer(const optional& fontFamily = optional()); + LocalGlyphRasterizer(const std::optional& fontFamily = std::nullopt); // virtual so that test harness can override platform-specific behavior virtual bool canRasterizeGlyph(const FontStack&, GlyphID); diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp index 0439babcb..f97ee1581 100644 --- a/src/mbgl/text/placement.cpp +++ b/src/mbgl/text/placement.cpp @@ -47,14 +47,14 @@ const CollisionGroups::CollisionGroup& CollisionGroups::get(const std::string& s uint16_t nextGroupID = ++maxGroupID; collisionGroups.emplace(sourceID, CollisionGroup( nextGroupID, - optional([nextGroupID](const IndexedSubfeature& feature) -> bool { + std::optional([nextGroupID](const IndexedSubfeature& feature) -> bool { return feature.collisionGroupId == nextGroupID; }) )); } return collisionGroups[sourceID]; } else { - static CollisionGroup nullGroup{0, nullopt}; + static CollisionGroup nullGroup{0, std::nullopt}; return nullGroup; } } @@ -73,7 +73,7 @@ public: const TransformState& state_, float placementZoom, CollisionGroups::CollisionGroup collisionGroup_, - optional avoidEdges_ = nullopt) + std::optional avoidEdges_ = std::nullopt) : bucket(bucket_), renderTile(renderTile_), state(state_), @@ -143,7 +143,7 @@ public: bool hasIconTextFit = getLayout().get() != IconTextFitType::None; - optional avoidEdges; + std::optional avoidEdges; }; // PlacementController implemenation @@ -155,7 +155,7 @@ void PlacementController::setPlacement(Immutable placement_) { stale = false; } -bool PlacementController::placementIsRecent(TimePoint now, const float zoom, optional periodOverride) const { +bool PlacementController::placementIsRecent(TimePoint now, const float zoom, std::optional periodOverride) const { if (!placement->transitionsEnabled()) return false; auto updatePeriod = periodOverride ? *periodOverride : placement->getUpdatePeriod(zoom); @@ -174,7 +174,7 @@ bool PlacementController::hasTransitions(TimePoint now) const { // Placement implementation Placement::Placement(std::shared_ptr updateParameters_, - optional> prevPlacement_) + std::optional> prevPlacement_) : updateParameters(std::move(updateParameters_)), collisionIndex(updateParameters->transformState, updateParameters->mode), transitionOptions(updateParameters->transitionOptions), @@ -184,7 +184,7 @@ Placement::Placement(std::shared_ptr updateParameters_, prevPlacement(std::move(prevPlacement_)), showCollisionBoxes(updateParameters->debugOptions & MapDebugOptions::Collision) { if (prevPlacement) { - prevPlacement->get()->prevPlacement = nullopt; // Only hold on to one placement back + prevPlacement->get()->prevPlacement = std::nullopt; // Only hold on to one placement back } } @@ -282,7 +282,7 @@ JointPlacement Placement::placeSymbol(const SymbolInstance& symbolInstance, cons std::pair placedVerticalText{false, false}; std::pair placedVerticalIcon{false, false}; Point shift{0.0f, 0.0f}; - optional horizontalTextIndex = symbolInstance.getDefaultHorizontalPlacedTextIndex(); + std::optional horizontalTextIndex = symbolInstance.getDefaultHorizontalPlacedTextIndex(); if (horizontalTextIndex) { const PlacedSymbol& placedSymbol = bucket.text.placedSymbols.at(*horizontalTextIndex); const float fontSize = evaluateSizeForFeature(ctx.partiallyEvaluatedTextSize, placedSymbol); @@ -447,7 +447,7 @@ JointPlacement Placement::placeSymbol(const SymbolInstance& symbolInstance, cons if (placedFeature.first) { assert(symbolInstance.crossTileID != 0u); - optional prevAnchor; + std::optional prevAnchor; // If this label was placed in the previous placement, record the anchor position // to allow us to animate the transition @@ -618,7 +618,7 @@ JointPlacement Placement::placeSymbol(const SymbolInstance& symbolInstance, cons namespace { SymbolInstanceReferences getBucketSymbols(const SymbolBucket& bucket, - const optional& sortKeyRange, + const std::optional& sortKeyRange, double bearing) { if (bucket.layout->get() == style::SymbolZOrderType::ViewportY) { auto sortedSymbols = bucket.getSortedSymbols(static_cast(bearing)); @@ -778,7 +778,7 @@ bool Placement::updateBucketDynamicVertices(SymbolBucket& bucket, const Transfor for (std::size_t i = 0; i < bucket.text.placedSymbols.size(); ++i) { const PlacedSymbol& symbol = bucket.text.placedSymbols[i]; - optional variableOffset; + std::optional variableOffset; const bool skipOrientation = bucket.allowVerticalPlacement && !symbol.placedOrientation; if (!symbol.hidden && symbol.crossTileID != 0u && !skipOrientation) { auto it = variableOffsets.find(symbol.crossTileID); @@ -1082,7 +1082,7 @@ void Placement::updateBucketOpacities(SymbolBucket& bucket, } namespace { -optional justificationToIndex(style::TextJustifyType justify, const SymbolInstance& symbolInstance, style::TextWritingModeType orientation) { +std::optional justificationToIndex(style::TextJustifyType justify, const SymbolInstance& symbolInstance, style::TextWritingModeType orientation) { // Vertical symbol has just one justification, style::TextJustifyType::Left. if (orientation == style::TextWritingModeType::Vertical) { return symbolInstance.placedVerticalTextIndex; @@ -1095,7 +1095,7 @@ optional justificationToIndex(style::TextJustifyType justify, const Symb case style::TextJustifyType::Auto: break; } assert(false); - return nullopt; + return std::nullopt; } const style::TextJustifyType justifyTypes[] = { @@ -1109,10 +1109,10 @@ void Placement::markUsedJustification(SymbolBucket& bucket, style::TextWritingModeType orientation) const { style::TextJustifyType anchorJustify = getAnchorJustification(placedAnchor); assert(anchorJustify != style::TextJustifyType::Auto); - const optional& autoIndex = justificationToIndex(anchorJustify, symbolInstance, orientation); + const std::optional& autoIndex = justificationToIndex(anchorJustify, symbolInstance, orientation); for (auto& justify : justifyTypes) { - const optional index = justificationToIndex(justify, symbolInstance, orientation); + const std::optional index = justificationToIndex(justify, symbolInstance, orientation); if (index) { assert(bucket.text.placedSymbols.size() > *index); if (autoIndex && *index != *autoIndex) { @@ -1130,9 +1130,9 @@ void Placement::markUsedOrientation(SymbolBucket& bucket, style::TextWritingModeType orientation, const SymbolInstance& symbolInstance) const { auto horizontal = orientation == style::TextWritingModeType::Horizontal ? - optional(orientation) : nullopt; + std::optional(orientation) : std::nullopt; auto vertical = orientation == style::TextWritingModeType::Vertical ? - optional(orientation) : nullopt; + std::optional(orientation) : std::nullopt; if (symbolInstance.placedRightTextIndex) { bucket.text.placedSymbols.at(*symbolInstance.placedRightTextIndex).placedOrientation = horizontal; @@ -1225,7 +1225,7 @@ const RetainedQueryData& Placement::getQueryData(uint32_t bucketInstanceId) cons class StaticPlacement : public Placement { public: explicit StaticPlacement(std::shared_ptr updateParameters_) - : Placement(std::move(updateParameters_), nullopt) {} + : Placement(std::move(updateParameters_), std::nullopt) {} protected: void commit() override; @@ -1265,7 +1265,7 @@ private: void collectPlacedSymbolData(bool enable) override { collectData = enable; } const std::vector& getPlacedSymbolsData() const override { return placedSymbolsData; } - optional getAvoidEdges(const SymbolBucket&, const mat4&) override; + std::optional getAvoidEdges(const SymbolBucket&, const mat4&) override; bool canPlaceAtVariableAnchor(const CollisionBox& box, TextVariableAnchorType anchor, Point shift, @@ -1282,7 +1282,7 @@ private: bool shouldRetryPlacement(const JointPlacement&, const PlacementContext&); std::unordered_map locationCache; - optional tileBorders; + std::optional tileBorders; std::set seenCrossTileIDs; std::vector placedSymbolsData; std::vector intersections; @@ -1341,14 +1341,14 @@ void TilePlacement::placeLayers(const RenderLayerReferences& layers) { commit(); } -optional TilePlacement::getAvoidEdges(const SymbolBucket& bucket, const mat4& posMatrix) { +std::optional TilePlacement::getAvoidEdges(const SymbolBucket& bucket, const mat4& posMatrix) { tileBorders = collisionIndex.projectTileBoundaries(posMatrix); const auto& layout = *bucket.layout; if (layout.get() || layout.get() == style::SymbolPlacementType::Line) { return tileBorders; } - return nullopt; + return std::nullopt; } void TilePlacement::placeSymbolBucket(const BucketPlacementData& params, std::set& seen) { @@ -1376,7 +1376,7 @@ void TilePlacement::placeSymbolBucket(const BucketPlacementData& params, std::se // those symbols will remain even if each tile is handled independently. SymbolInstanceReferences symbolInstances = getBucketSymbols(bucket, params.sortKeyRange, collisionIndex.getTransformState().getBearing()); - optional variableAnchor; + std::optional variableAnchor; if (!variableTextAnchors.empty()) variableAnchor = variableTextAnchors.front(); // Keeps the data necessary to find a feature location according to a tile. @@ -1511,14 +1511,14 @@ void TilePlacement::newSymbolPlaced(const SymbolInstance& symbol, if (!collectData || placementType != style::SymbolPlacementType::Point || shouldRetryPlacement(placement, ctx)) return; - optional> textCollisionBox; + std::optional> textCollisionBox; if (!textCollisionBoxes.empty()) { assert(textCollisionBoxes.size() == 1u); auto& box = textCollisionBoxes.front(); assert(box.isBox()); textCollisionBox = box.box(); } - optional> iconCollisionBox; + std::optional> iconCollisionBox; if (!iconCollisionBoxes.empty()) { assert(iconCollisionBoxes.size() == 1u); auto& box = iconCollisionBoxes.front(); @@ -1543,7 +1543,7 @@ bool TilePlacement::shouldRetryPlacement(const JointPlacement& placement, const // static Mutable Placement::create(std::shared_ptr updateParameters_, - optional> prevPlacement) { + std::optional> prevPlacement) { assert(updateParameters_); switch (updateParameters_->mode) { case MapMode::Continuous: diff --git a/src/mbgl/text/placement.hpp b/src/mbgl/text/placement.hpp index 82a62718a..25ebbebf9 100644 --- a/src/mbgl/text/placement.hpp +++ b/src/mbgl/text/placement.hpp @@ -42,7 +42,7 @@ public: float height; style::TextVariableAnchorType anchor; float textBoxScale; - optional prevAnchor; + std::optional prevAnchor; }; class JointPlacement { @@ -75,7 +75,7 @@ struct RetainedQueryData { class CollisionGroups { public: using Predicate = std::function; - using CollisionGroup = std::pair>; + using CollisionGroup = std::pair>; CollisionGroups(const bool crossSourceCollisions_) : maxGroupID(0) @@ -98,7 +98,7 @@ public: void setPlacement(Immutable); const Immutable& getPlacement() const { return placement; } void setPlacementStale() { stale = true; } - bool placementIsRecent(TimePoint now, float zoom, optional periodOverride = nullopt) const; + bool placementIsRecent(TimePoint now, float zoom, std::optional periodOverride = std::nullopt) const; bool hasTransitions(TimePoint now) const; private: @@ -115,7 +115,7 @@ public: * In Continuous map mode, `prevPlacement` must be provided. */ static Mutable create(std::shared_ptr updateParameters, - optional> prevPlacement = nullopt); + std::optional> prevPlacement = std::nullopt); virtual ~Placement(); virtual void placeLayers(const RenderLayerReferences&); @@ -137,7 +137,7 @@ public: // Public constructors are required for makeMutable(), shall not be called directly. Placement(); - Placement(std::shared_ptr, optional> prevPlacement); + Placement(std::shared_ptr, std::optional> prevPlacement); protected: friend SymbolBucket; @@ -152,8 +152,8 @@ protected: const std::vector& /*textBoxes*/, const std::vector& /*iconBoxes*/) {} // Implentation specific hooks, which get called during a symbol bucket placement. - virtual optional getAvoidEdges(const SymbolBucket&, const mat4& /*posMatrix*/) { - return nullopt; + virtual std::optional getAvoidEdges(const SymbolBucket&, const mat4& /*posMatrix*/) { + return std::nullopt; } SymbolInstanceReferences getSortedSymbols(const BucketPlacementData&, float pixelRatio); virtual bool canPlaceAtVariableAnchor(const CollisionBox&, @@ -193,7 +193,7 @@ protected: std::unordered_map retainedQueryData; CollisionGroups collisionGroups; - mutable optional> prevPlacement; + mutable std::optional> prevPlacement; bool showCollisionBoxes = false; // Cache being used by placeSymbol() diff --git a/src/mbgl/text/quads.cpp b/src/mbgl/text/quads.cpp index db56b6398..2ee343cf5 100644 --- a/src/mbgl/text/quads.cpp +++ b/src/mbgl/text/quads.cpp @@ -7,7 +7,6 @@ #include #include #include -#include #include @@ -107,7 +106,7 @@ SymbolQuads getIconQuads(const PositionedIcon& shapedIcon, fixedContentHeight = content.bottom - content.top - stretchContentHeight; } - optional> matrix{nullopt}; + std::optional> matrix{std::nullopt}; if (iconRotate) { const float angle = iconRotate * util::DEG2RAD_F; const float angle_sin = std::sin(angle); diff --git a/src/mbgl/text/tagged_string.cpp b/src/mbgl/text/tagged_string.cpp index 1b420dcf3..4fc513977 100644 --- a/src/mbgl/text/tagged_string.cpp +++ b/src/mbgl/text/tagged_string.cpp @@ -13,11 +13,11 @@ namespace mbgl { void TaggedString::addTextSection(const std::u16string& sectionText, double scale, const FontStack& fontStack, - optional textColor) { + std::optional textColor) { styledText.first += sectionText; sections.emplace_back(scale, fontStack, std::move(textColor)); styledText.second.resize(styledText.first.size(), static_cast(sections.size() - 1)); - supportsVerticalWritingMode = nullopt; + supportsVerticalWritingMode = std::nullopt; } void TaggedString::addImageSection(const std::string& imageID) { @@ -32,14 +32,14 @@ void TaggedString::addImageSection(const std::string& imageID) { styledText.second.resize(styledText.first.size(), static_cast(sections.size() - 1)); } -optional TaggedString::getNextImageSectionCharCode() { +std::optional TaggedString::getNextImageSectionCharCode() { if (imageSectionID == 0u) { imageSectionID = PUAbegin; return imageSectionID; } if (++imageSectionID > PUAend) { - return nullopt; + return std::nullopt; } return imageSectionID; diff --git a/src/mbgl/text/tagged_string.hpp b/src/mbgl/text/tagged_string.hpp index 205bfbcc5..0ff92307e 100644 --- a/src/mbgl/text/tagged_string.hpp +++ b/src/mbgl/text/tagged_string.hpp @@ -4,10 +4,12 @@ #include #include +#include + namespace mbgl { struct SectionOptions { - SectionOptions(double scale_, FontStack fontStack_, optional textColor_ = nullopt) + SectionOptions(double scale_, FontStack fontStack_, std::optional textColor_ = std::nullopt) : scale(scale_), fontStackHash(FontStackHasher()(fontStack_)), fontStack(std::move(fontStack_)), @@ -19,8 +21,8 @@ struct SectionOptions { double scale; FontStackHash fontStackHash; FontStack fontStack; - optional textColor; - optional imageID; + std::optional textColor; + std::optional imageID; }; /** @@ -83,7 +85,7 @@ struct TaggedString { void addTextSection(const std::u16string& text, double scale, const FontStack& fontStack, - optional textColor_ = nullopt); + std::optional textColor_ = std::nullopt); void addImageSection(const std::string& imageID); @@ -106,12 +108,12 @@ struct TaggedString { bool allowsVerticalWritingMode(); private: - optional getNextImageSectionCharCode(); + std::optional getNextImageSectionCharCode(); private: StyledText styledText; std::vector sections; - optional supportsVerticalWritingMode; + std::optional supportsVerticalWritingMode; // Max number of images within a text is 6400 U+E000–U+F8FF // that covers Basic Multilingual Plane Unicode Private Use Area (PUA). char16_t imageSectionID = 0u; diff --git a/src/mbgl/tile/geojson_tile_data.hpp b/src/mbgl/tile/geojson_tile_data.hpp index db7c9fadb..6353b7151 100644 --- a/src/mbgl/tile/geojson_tile_data.hpp +++ b/src/mbgl/tile/geojson_tile_data.hpp @@ -39,15 +39,15 @@ public: return *geometry; } - optional getValue(const std::string& key) const override { + std::optional getValue(const std::string& key) const override { auto it = feature.properties.find(key); if (it != feature.properties.end()) { - return optional(it->second); + return std::optional(it->second); } - return optional(); + return std::optional(); } - mutable optional geometry; + mutable std::optional geometry; }; class GeoJSONTileLayer : public GeometryTileLayer { diff --git a/src/mbgl/tile/geometry_tile.cpp b/src/mbgl/tile/geometry_tile.cpp index e0fd15595..d3f72582e 100644 --- a/src/mbgl/tile/geometry_tile.cpp +++ b/src/mbgl/tile/geometry_tile.cpp @@ -50,7 +50,7 @@ public: private: // TileRenderData overrides. - optional getPattern(const std::string&) const override; + std::optional getPattern(const std::string&) const override; const LayerRenderData* getLayerRenderData(const style::Layer::Impl&) const override; Bucket* getBucket(const style::Layer::Impl&) const override; void upload(gfx::UploadPass&) override; @@ -62,7 +62,7 @@ private: using namespace style; -optional GeometryTileRenderData::getPattern(const std::string& pattern) const { +std::optional GeometryTileRenderData::getPattern(const std::string& pattern) const { if (layoutResult) { const auto& iconAtlas = layoutResult->iconAtlas; auto it = iconAtlas.patternPositions.find(pattern); @@ -70,7 +70,7 @@ optional GeometryTileRenderData::getPattern(const std::string& pa return it->second; } } - return nullopt; + return std::nullopt; } void GeometryTileRenderData::upload(gfx::UploadPass& uploadPass) { diff --git a/src/mbgl/tile/geometry_tile.hpp b/src/mbgl/tile/geometry_tile.hpp index ac55c1790..769bce3f5 100644 --- a/src/mbgl/tile/geometry_tile.hpp +++ b/src/mbgl/tile/geometry_tile.hpp @@ -8,12 +8,12 @@ #include #include #include -#include #include #include #include #include +#include namespace mbgl { @@ -69,14 +69,14 @@ public: public: std::unordered_map layerRenderData; std::shared_ptr featureIndex; - optional glyphAtlasImage; + std::optional glyphAtlasImage; ImageAtlas iconAtlas; LayerRenderData* getLayerRenderData(const style::Layer::Impl&); LayoutResult(std::unordered_map renderData_, std::unique_ptr featureIndex_, - optional glyphAtlasImage_, + std::optional glyphAtlasImage_, ImageAtlas iconAtlas_) : layerRenderData(std::move(renderData_)), featureIndex(std::move(featureIndex_)), diff --git a/src/mbgl/tile/geometry_tile_data.hpp b/src/mbgl/tile/geometry_tile_data.hpp index 7d172e494..1b8cc3fdc 100644 --- a/src/mbgl/tile/geometry_tile_data.hpp +++ b/src/mbgl/tile/geometry_tile_data.hpp @@ -2,12 +2,12 @@ #include #include -#include #include #include #include #include +#include namespace mbgl { @@ -48,7 +48,7 @@ class GeometryTileFeature { public: virtual ~GeometryTileFeature() = default; virtual FeatureType getType() const = 0; - virtual optional getValue(const std::string& key) const = 0; + virtual std::optional getValue(const std::string& key) const = 0; virtual const PropertyMap& getProperties() const; virtual FeatureIdentifier getID() const { return NullValue {}; } virtual const GeometryCollection& getGeometries() const; diff --git a/src/mbgl/tile/geometry_tile_worker.cpp b/src/mbgl/tile/geometry_tile_worker.cpp index 409dfdf42..7025392b1 100644 --- a/src/mbgl/tile/geometry_tile_worker.cpp +++ b/src/mbgl/tile/geometry_tile_worker.cpp @@ -169,8 +169,8 @@ void GeometryTileWorker::setLayers(std::vector> layer } void GeometryTileWorker::reset(uint64_t correlationID_) { - layers = nullopt; - data = nullopt; + layers = std::nullopt; + data = std::nullopt; correlationID = correlationID_; switch (state) { @@ -288,7 +288,7 @@ void GeometryTileWorker::onGlyphsAvailable(GlyphMap newGlyphMap) { GlyphIDs& pendingGlyphIDs = pendingGlyphDependency.second; for (auto& newGlyph : newGlyphs) { const GlyphID& glyphID = newGlyph.first; - optional>& glyph = newGlyph.second; + std::optional>& glyph = newGlyph.second; if (pendingGlyphIDs.erase(glyphID)) { glyphs.emplace(glyphID, std::move(glyph)); @@ -450,7 +450,7 @@ void GeometryTileWorker::finalizeLayout() { } MBGL_TIMING_START(watch) - optional glyphAtlasImage; + std::optional glyphAtlasImage; ImageAtlas iconAtlas = makeImageAtlas(imageMap, patternMap, versionMap); if (!layouts.empty()) { GlyphAtlas glyphAtlas = makeGlyphAtlas(glyphMap); diff --git a/src/mbgl/tile/geometry_tile_worker.hpp b/src/mbgl/tile/geometry_tile_worker.hpp index ac18f2d12..9dacf2ea9 100644 --- a/src/mbgl/tile/geometry_tile_worker.hpp +++ b/src/mbgl/tile/geometry_tile_worker.hpp @@ -5,7 +5,6 @@ #include #include #include -#include #include #include #include @@ -92,9 +91,9 @@ private: uint64_t correlationID = 0; uint64_t imageCorrelationID = 0; - // Outer optional indicates whether we've received it or not. - optional>> layers; - optional> data; + // Outer std::optional indicates whether we've received it or not. + std::optional>> layers; + std::optional> data; std::vector> layouts; diff --git a/src/mbgl/tile/raster_dem_tile.cpp b/src/mbgl/tile/raster_dem_tile.cpp index 62a54aeb4..19160c10e 100644 --- a/src/mbgl/tile/raster_dem_tile.cpp +++ b/src/mbgl/tile/raster_dem_tile.cpp @@ -46,7 +46,7 @@ void RasterDEMTile::setError(std::exception_ptr err) { observer->onTileError(*this, std::move(err)); } -void RasterDEMTile::setMetadata(optional modified_, optional expires_) { +void RasterDEMTile::setMetadata(std::optional modified_, std::optional expires_) { modified = std::move(modified_); expires = std::move(expires_); } diff --git a/src/mbgl/tile/raster_dem_tile.hpp b/src/mbgl/tile/raster_dem_tile.hpp index a6189d8d7..21f189556 100644 --- a/src/mbgl/tile/raster_dem_tile.hpp +++ b/src/mbgl/tile/raster_dem_tile.hpp @@ -71,7 +71,7 @@ public: void setUpdateParameters(const TileUpdateParameters&) override; void setError(std::exception_ptr); - void setMetadata(optional modified, optional expires); + void setMetadata(std::optional modified, std::optional expires); void setData(const std::shared_ptr& data); bool layerPropertiesUpdated(const Immutable& layerProperties) override; diff --git a/src/mbgl/tile/raster_tile.cpp b/src/mbgl/tile/raster_tile.cpp index 2ba1dfcc0..371eb3b48 100644 --- a/src/mbgl/tile/raster_tile.cpp +++ b/src/mbgl/tile/raster_tile.cpp @@ -35,7 +35,7 @@ void RasterTile::setError(std::exception_ptr err) { observer->onTileError(*this, std::move(err)); } -void RasterTile::setMetadata(optional modified_, optional expires_) { +void RasterTile::setMetadata(std::optional modified_, std::optional expires_) { modified = std::move(modified_); expires = std::move(expires_); } diff --git a/src/mbgl/tile/raster_tile.hpp b/src/mbgl/tile/raster_tile.hpp index 4712bfb81..bf5ea7152 100644 --- a/src/mbgl/tile/raster_tile.hpp +++ b/src/mbgl/tile/raster_tile.hpp @@ -27,7 +27,7 @@ public: void setUpdateParameters(const TileUpdateParameters&) override; void setError(std::exception_ptr); - void setMetadata(optional modified, optional expires); + void setMetadata(std::optional modified, std::optional expires); void setData(const std::shared_ptr& data); bool layerPropertiesUpdated(const Immutable& layerProperties) override; diff --git a/src/mbgl/tile/tile.cpp b/src/mbgl/tile/tile.cpp index ca1b94fa9..eda0367f0 100644 --- a/src/mbgl/tile/tile.cpp +++ b/src/mbgl/tile/tile.cpp @@ -32,11 +32,11 @@ void Tile::dumpDebugLogs() const { case Kind::RasterDEM: kindString = "RasterDEM"; break; default: kindString = "Unknown"; break; } - Log::Info(Event::General, "Tile::Kind: %s", kindString.c_str()); - Log::Info(Event::General, "Tile::id: %s", util::toString(id).c_str()); - Log::Info(Event::General, "Tile::renderable: %s", isRenderable() ? "yes" : "no"); - Log::Info(Event::General, "Tile::complete: %s", isComplete() ? "yes" : "no"); - Log::Info(Event::General, "Tile::loaded: %s", isLoaded() ? "yes" : "no"); + Log::Info(Event::General, "Tile::Kind: " + kindString); + Log::Info(Event::General, "Tile::id: " + util::toString(id)); + Log::Info(Event::General, "Tile::renderable: " + std::string(isRenderable() ? "yes" : "no")); + Log::Info(Event::General, "Tile::complete: " + std::string(isComplete() ? "yes" : "no")); + Log::Info(Event::General, "Tile::loaded: " + std::string(isLoaded() ? "yes" : "no")); } void Tile::queryRenderedFeatures(std::unordered_map>&, const GeometryCoordinates&, diff --git a/src/mbgl/tile/tile.hpp b/src/mbgl/tile/tile.hpp index 573b3a1c5..3ab008fc8 100644 --- a/src/mbgl/tile/tile.hpp +++ b/src/mbgl/tile/tile.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include #include @@ -17,6 +16,7 @@ #include #include #include +#include namespace mbgl { @@ -145,8 +145,8 @@ public: const Kind kind; OverscaledTileID id; - optional modified; - optional expires; + std::optional modified; + std::optional expires; // Indicates whether this tile is used for the currently visible layers on the map. // Re-initialized at every source update. bool usedByRenderedLayers = false; diff --git a/src/mbgl/tile/tile_loader_impl.hpp b/src/mbgl/tile/tile_loader_impl.hpp index a034ea740..3a8094e63 100644 --- a/src/mbgl/tile/tile_loader_impl.hpp +++ b/src/mbgl/tile/tile_loader_impl.hpp @@ -37,11 +37,11 @@ TileLoader::TileLoader(T& tile_, } if (fileSource->supportsCacheOnlyRequests()) { - // When supported, the first request is always optional, even if the TileLoader - // is marked as required. That way, we can let the first optional request continue - // to load when the TileLoader is later changed from required to optional. If we + // When supported, the first request is always std::optional, even if the TileLoader + // is marked as required. That way, we can let the first std::optional request continue + // to load when the TileLoader is later changed from required to std::optional. If we // started out with a required request, we'd have to cancel everything, including the - // initial optional part of the request. + // initial std::optional part of the request. loadFromCache(); } else if (necessity == TileNecessity::Required) { // When the file source doesn't support cache-only requests, and we definiitely need this diff --git a/src/mbgl/tile/vector_tile.cpp b/src/mbgl/tile/vector_tile.cpp index 7ae53ef20..cff6e4731 100644 --- a/src/mbgl/tile/vector_tile.cpp +++ b/src/mbgl/tile/vector_tile.cpp @@ -20,7 +20,7 @@ void VectorTile::setUpdateParameters(const TileUpdateParameters& params) { loader.setUpdateParameters(params); } -void VectorTile::setMetadata(optional modified_, optional expires_) { +void VectorTile::setMetadata(std::optional modified_, std::optional expires_) { modified = std::move(modified_); expires = std::move(expires_); } diff --git a/src/mbgl/tile/vector_tile.hpp b/src/mbgl/tile/vector_tile.hpp index 31ae52b7c..817c0c25d 100644 --- a/src/mbgl/tile/vector_tile.hpp +++ b/src/mbgl/tile/vector_tile.hpp @@ -17,7 +17,7 @@ public: void setNecessity(TileNecessity) final; void setUpdateParameters(const TileUpdateParameters&) final; - void setMetadata(optional modified, optional expires); + void setMetadata(std::optional modified, std::optional expires); void setData(const std::shared_ptr& data); private: diff --git a/src/mbgl/tile/vector_tile_data.cpp b/src/mbgl/tile/vector_tile_data.cpp index 232f2481d..a6139b412 100644 --- a/src/mbgl/tile/vector_tile_data.cpp +++ b/src/mbgl/tile/vector_tile_data.cpp @@ -22,9 +22,9 @@ FeatureType VectorTileFeature::getType() const { } } -optional VectorTileFeature::getValue(const std::string& key) const { - const optional value(feature.getValue(key)); - return value->is() ? nullopt : value; +std::optional VectorTileFeature::getValue(const std::string& key) const { + const std::optional value(feature.getValue(key)); + return value->is() ? std::nullopt : value; } const PropertyMap& VectorTileFeature::getProperties() const { @@ -46,7 +46,7 @@ const GeometryCollection& VectorTileFeature::getGeometries() const { lines = feature.getGeometries(scale); } catch(const std::runtime_error& ex) { - Log::Error(Event::ParseTile, "Could not get geometries: %s", ex.what()); + Log::Error(Event::ParseTile, "Could not get geometries: " + std::string(ex.what())); lines = GeometryCollection(); } diff --git a/src/mbgl/tile/vector_tile_data.hpp b/src/mbgl/tile/vector_tile_data.hpp index 76e23e9bc..d4656f6e2 100644 --- a/src/mbgl/tile/vector_tile_data.hpp +++ b/src/mbgl/tile/vector_tile_data.hpp @@ -25,15 +25,15 @@ public: VectorTileFeature(const mapbox::vector_tile::layer&, const protozero::data_view&); FeatureType getType() const override; - optional getValue(const std::string& key) const override; + std::optional getValue(const std::string& key) const override; const PropertyMap& getProperties() const override; FeatureIdentifier getID() const override; const GeometryCollection& getGeometries() const override; private: mapbox::vector_tile::feature feature; - mutable optional lines; - mutable optional properties; + mutable std::optional lines; + mutable std::optional properties; }; class VectorTileLayer : public GeometryTileLayer { diff --git a/src/mbgl/util/camera.cpp b/src/mbgl/util/camera.cpp index 5c170eca4..d9010fe8f 100644 --- a/src/mbgl/util/camera.cpp +++ b/src/mbgl/util/camera.cpp @@ -183,7 +183,7 @@ void Camera::setPosition(const vec3& position) { updateTransform(transform, position); } -optional Camera::orientationFromFrame(const vec3& forward, const vec3& up) { +std::optional Camera::orientationFromFrame(const vec3& forward, const vec3& up) { vec3 upVector = up; vec2 xyForward = {{forward[0], forward[1]}}; @@ -203,7 +203,7 @@ optional Camera::orientationFromFrame(const vec3& forward, const vec const vec3 right = vec3Cross(upVector, forward); if (vec3Length(right) < epsilon) { - return nullopt; + return std::nullopt; } const double bearing = std::atan2(-right[1], right[0]); @@ -217,14 +217,14 @@ void FreeCameraOptions::setLocation(const LatLngAltitude& location) { position = util::toMercator(location.location, location.altitude); } -optional FreeCameraOptions::getLocation() const { +std::optional FreeCameraOptions::getLocation() const { if (!position) { - return nullopt; + return std::nullopt; } const vec3 positionValue = position.value(); if (positionValue[1] < 0.0 || positionValue[1] > 1.0) { - return nullopt; + return std::nullopt; } const LatLng location = {util::latFromMercatorY(positionValue[1]), util::lngFromMercatorX(positionValue[0])}; @@ -236,8 +236,8 @@ optional FreeCameraOptions::getLocation() const { return LatLngAltitude{location, altitude}; } -void FreeCameraOptions::lookAtPoint(const LatLng& location, const optional& upVector) { - orientation = nullopt; +void FreeCameraOptions::lookAtPoint(const LatLng& location, const std::optional& upVector) { + orientation = std::nullopt; if (!position) { return; } diff --git a/src/mbgl/util/camera.hpp b/src/mbgl/util/camera.hpp index 030d7cfaa..231c1b6a9 100644 --- a/src/mbgl/util/camera.hpp +++ b/src/mbgl/util/camera.hpp @@ -1,9 +1,10 @@ #pragma once -#include #include #include "quaternion.hpp" +#include + namespace mbgl { class LatLng; @@ -31,7 +32,7 @@ public: // Computes orientation using forward and up vectors of the provided coordinate frame. // Only bearing and pitch components will be used. Does not return a value if input is invalid - static optional orientationFromFrame(const vec3& forward, const vec3& up); + static std::optional orientationFromFrame(const vec3& forward, const vec3& up); private: Quaternion orientation; @@ -39,4 +40,4 @@ private: }; } // namespace util -} // namespace mbgl \ No newline at end of file +} // namespace mbgl diff --git a/src/mbgl/util/color.cpp b/src/mbgl/util/color.cpp index b4c4d8fac..a94d4800b 100644 --- a/src/mbgl/util/color.cpp +++ b/src/mbgl/util/color.cpp @@ -5,7 +5,7 @@ namespace mbgl { -optional Color::parse(const std::string& s) { +std::optional Color::parse(const std::string& s) { auto css_color = CSSColorParser::parse(s); // Premultiply the color. diff --git a/src/mbgl/util/grid_index.cpp b/src/mbgl/util/grid_index.cpp index eeeda01a2..cb197ef32 100644 --- a/src/mbgl/util/grid_index.cpp +++ b/src/mbgl/util/grid_index.cpp @@ -88,7 +88,7 @@ std::vector::BBox>> GridIndex::queryWithBo } template -bool GridIndex::hitTest(const BBox& queryBBox, optional> predicate) const { +bool GridIndex::hitTest(const BBox& queryBBox, std::optional> predicate) const { bool hit = false; query(queryBBox, [&](const T& t, const BBox&) -> bool { if (!predicate || (*predicate)(t)) { @@ -102,7 +102,7 @@ bool GridIndex::hitTest(const BBox& queryBBox, optional -bool GridIndex::hitTest(const BCircle& queryBCircle, optional> predicate) const { +bool GridIndex::hitTest(const BCircle& queryBCircle, std::optional> predicate) const { bool hit = false; query(queryBCircle, [&](const T& t, const BBox&) -> bool { if (!predicate || (*predicate)(t)) { diff --git a/src/mbgl/util/grid_index.hpp b/src/mbgl/util/grid_index.hpp index 502b1d99a..daad43cb4 100644 --- a/src/mbgl/util/grid_index.hpp +++ b/src/mbgl/util/grid_index.hpp @@ -2,12 +2,12 @@ #include #include -#include #include #include #include #include +#include namespace mbgl { @@ -67,8 +67,8 @@ public: std::vector query(const BBox&) const; std::vector> queryWithBoxes(const BBox&) const; - bool hitTest(const BBox&, optional> predicate = nullopt) const; - bool hitTest(const BCircle&, optional> predicate = nullopt) const; + bool hitTest(const BBox&, std::optional> predicate = std::nullopt) const; + bool hitTest(const BCircle&, std::optional> predicate = std::nullopt) const; bool empty() const; diff --git a/src/mbgl/util/http_header.cpp b/src/mbgl/util/http_header.cpp index 56b1e12fa..89a3c0160 100644 --- a/src/mbgl/util/http_header.cpp +++ b/src/mbgl/util/http_header.cpp @@ -32,12 +32,12 @@ CacheControl CacheControl::parse(const std::string& value) { return result; } -optional CacheControl::toTimePoint() const { - return maxAge ? util::now() + Seconds(*maxAge) : optional{}; +std::optional CacheControl::toTimePoint() const { + return maxAge ? util::now() + Seconds(*maxAge) : std::optional{}; } -optional parseRetryHeaders(const optional& retryAfter, - const optional& xRateLimitReset) { +std::optional parseRetryHeaders(const std::optional& retryAfter, + const std::optional& xRateLimitReset) { if (retryAfter) { try { auto secs = std::chrono::seconds(std::stoi(*retryAfter)); diff --git a/src/mbgl/util/http_header.hpp b/src/mbgl/util/http_header.hpp index 23da2c9ea..614ddc101 100644 --- a/src/mbgl/util/http_header.hpp +++ b/src/mbgl/util/http_header.hpp @@ -1,9 +1,9 @@ #pragma once -#include #include #include +#include namespace mbgl { namespace http { @@ -12,14 +12,14 @@ class CacheControl { public: static CacheControl parse(const std::string&); - optional maxAge; + std::optional maxAge; bool mustRevalidate = false; - optional toTimePoint() const; + std::optional toTimePoint() const; }; -optional parseRetryHeaders(const optional& retryAfter, - const optional& xRateLimitReset); +std::optional parseRetryHeaders(const std::optional& retryAfter, + const std::optional& xRateLimitReset); } // namespace http } // namespace mbgl diff --git a/src/mbgl/util/http_timeout.cpp b/src/mbgl/util/http_timeout.cpp index cf4085d5d..07d9b79f3 100644 --- a/src/mbgl/util/http_timeout.cpp +++ b/src/mbgl/util/http_timeout.cpp @@ -7,7 +7,7 @@ namespace mbgl { namespace http { -Duration errorRetryTimeout(Response::Error::Reason failedRequestReason, uint32_t failedRequests, optional retryAfter) { +Duration errorRetryTimeout(Response::Error::Reason failedRequestReason, uint32_t failedRequests, std::optional retryAfter) { if (failedRequestReason == Response::Error::Reason::Server) { // Retry after one second three times, then start exponential backoff. @@ -29,7 +29,7 @@ Duration errorRetryTimeout(Response::Error::Reason failedRequestReason, uint32_t } } -Duration expirationTimeout(optional expires, uint32_t expiredRequests) { +Duration expirationTimeout(std::optional expires, uint32_t expiredRequests) { if (expiredRequests) { return Seconds(1u << std::min(expiredRequests - 1, 31u)); } diff --git a/src/mbgl/util/http_timeout.hpp b/src/mbgl/util/http_timeout.hpp index b69479499..23db9300f 100644 --- a/src/mbgl/util/http_timeout.hpp +++ b/src/mbgl/util/http_timeout.hpp @@ -1,15 +1,16 @@ #pragma once #include -#include #include +#include + namespace mbgl { namespace http { -Duration errorRetryTimeout(Response::Error::Reason failedRequestReason, uint32_t failedRequests, optional retryAfter = {}); +Duration errorRetryTimeout(Response::Error::Reason failedRequestReason, uint32_t failedRequests, std::optional retryAfter = std::nullopt); -Duration expirationTimeout(optional expires, uint32_t expiredRequests); +Duration expirationTimeout(std::optional expires, uint32_t expiredRequests); } // namespace http } // namespace mbgl diff --git a/src/mbgl/util/io.cpp b/src/mbgl/util/io.cpp index 5225e2952..7c6fefe76 100644 --- a/src/mbgl/util/io.cpp +++ b/src/mbgl/util/io.cpp @@ -41,7 +41,7 @@ std::string read_file(const std::string &filename) { } } -optional readFile(const std::string &filename) { +std::optional readFile(const std::string &filename) { std::ifstream file(filename, std::ios::binary); if (file.good()) { std::stringstream data; diff --git a/src/mbgl/util/io.hpp b/src/mbgl/util/io.hpp index e628e8212..f4f7ddeb6 100644 --- a/src/mbgl/util/io.hpp +++ b/src/mbgl/util/io.hpp @@ -1,9 +1,8 @@ #pragma once -#include - #include #include +#include namespace mbgl { namespace util { @@ -16,7 +15,7 @@ struct IOException : std::runtime_error { void write_file(const std::string &filename, const std::string &data); std::string read_file(const std::string &filename); -optional readFile(const std::string &filename); +std::optional readFile(const std::string &filename); void deleteFile(const std::string& filename); void copyFile(const std::string& destination, const std::string& source); diff --git a/src/mbgl/util/logging.cpp b/src/mbgl/util/logging.cpp index 00409b974..92884bc7f 100644 --- a/src/mbgl/util/logging.cpp +++ b/src/mbgl/util/logging.cpp @@ -64,31 +64,15 @@ void Log::record(EventSeverity severity, Event event, const std::string &msg) { get()->impl->record(severity, event, -1, msg); } -void Log::record(EventSeverity severity, Event event, const char* format, ...) { - va_list args; - va_start(args, format); - char msg[4096]; - vsnprintf(msg, sizeof(msg), format, args); - va_end(args); - - get()->impl->record(severity, event, -1, std::string{msg}); -} - -void Log::record(EventSeverity severity, Event event, int64_t code, const char* format, ...) { - va_list args; - va_start(args, format); - char msg[4096]; - vsnprintf(msg, sizeof(msg), format, args); - va_end(args); - - get()->impl->record(severity, event, code, std::string{msg}); +void Log::record(EventSeverity severity, Event event, int64_t code, const std::string &msg) { + get()->impl->record(severity, event, code, msg); } void Log::record(EventSeverity severity, Event event, int64_t code, const std::string& msg, - const optional& threadName) { + const std::optional& threadName) { std::lock_guard lock(mutex); if (currentObserver && severity != EventSeverity::Debug && currentObserver->onRecord(severity, event, code, msg)) { diff --git a/src/mbgl/util/stopwatch.cpp b/src/mbgl/util/stopwatch.cpp index 6db9da07e..685340399 100644 --- a/src/mbgl/util/stopwatch.cpp +++ b/src/mbgl/util/stopwatch.cpp @@ -24,7 +24,9 @@ stopwatch::stopwatch(std::string name_, EventSeverity severity_, Event event_) void stopwatch::report(const std::string &name_) { Duration duration = Clock::now() - start; - Log::Record(severity, event, "%s: %fms", name_.c_str(), std::chrono::duration(duration).count()); + const auto logMsg = name_ + ": " + std::to_string(std::chrono::duration(duration).count()); + + Log::Record(severity, event, logMsg); start += duration; } diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp index cbb5f8279..afd597454 100644 --- a/src/mbgl/util/tile_cover.cpp +++ b/src/mbgl/util/tile_cover.cpp @@ -147,7 +147,7 @@ int32_t coveringZoomLevel(double zoom, style::SourceType type, uint16_t size) { } } -std::vector tileCover(const TransformState& state, uint8_t z, const optional& overscaledZ) { +std::vector tileCover(const TransformState& state, uint8_t z, const std::optional& overscaledZ) { struct Node { AABB aabb; uint8_t zoom; @@ -355,7 +355,7 @@ TileCover::TileCover(const Geometry& geom, uint8_t z, bool project/* = t TileCover::~TileCover() = default; -optional TileCover::next() { +std::optional TileCover::next() { return impl->next(); } diff --git a/src/mbgl/util/tile_cover.hpp b/src/mbgl/util/tile_cover.hpp index 5e09d8a67..d3f8cbf04 100644 --- a/src/mbgl/util/tile_cover.hpp +++ b/src/mbgl/util/tile_cover.hpp @@ -3,10 +3,10 @@ #include #include #include -#include #include #include +#include namespace mbgl { @@ -23,7 +23,7 @@ public: TileCover(const Geometry&, uint8_t z, bool project = true); ~TileCover(); - optional next(); + std::optional next(); bool hasNext(); private: @@ -35,7 +35,7 @@ int32_t coveringZoomLevel(double z, style::SourceType type, uint16_t tileSize); std::vector tileCover(const TransformState&, uint8_t z, - const optional& overscaledZ = nullopt); + const std::optional& overscaledZ = std::nullopt); std::vector tileCover(const LatLngBounds&, uint8_t z); std::vector tileCover(const Geometry&, uint8_t z); diff --git a/src/mbgl/util/tile_cover_impl.cpp b/src/mbgl/util/tile_cover_impl.cpp index e6f0516d5..9cf2d109c 100644 --- a/src/mbgl/util/tile_cover_impl.cpp +++ b/src/mbgl/util/tile_cover_impl.cpp @@ -340,7 +340,7 @@ bool TileCover::Impl::hasNext() const { && tileY < (1u << zoom)); } -optional TileCover::Impl::next() { +std::optional TileCover::Impl::next() { if (!hasNext()) return {}; const auto x = tileX; diff --git a/src/mbgl/util/tile_cover_impl.hpp b/src/mbgl/util/tile_cover_impl.hpp index 9ef263d12..fdb7ce16b 100644 --- a/src/mbgl/util/tile_cover_impl.hpp +++ b/src/mbgl/util/tile_cover_impl.hpp @@ -2,7 +2,6 @@ #include #include -#include #include #include @@ -81,7 +80,7 @@ public: Impl(int32_t z, const Geometry& geom, bool project = true); ~Impl() = default; - optional next(); + std::optional next(); bool hasNext() const; private: diff --git a/src/mbgl/util/tile_server_options.cpp b/src/mbgl/util/tile_server_options.cpp index 3f79566dc..5e5918a24 100644 --- a/src/mbgl/util/tile_server_options.cpp +++ b/src/mbgl/util/tile_server_options.cpp @@ -1,34 +1,32 @@ - #include -#include namespace mbgl { class TileServerOptions::Impl { public: std::string baseURL; - optional versionPrefix; + std::optional versionPrefix; std::string uriSchemeAlias; std::string sourceTemplate; std::string sourceDomainName; - optional sourceVersionPrefix; + std::optional sourceVersionPrefix; std::string styleTemplate; std::string styleDomainName; - optional styleVersionPrefix; + std::optional styleVersionPrefix; std::string spritesTemplate; std::string spritesDomainName; - optional spritesVersionPrefix; + std::optional spritesVersionPrefix; std::string glyphsTemplate; std::string glyphsDomainName; - optional glyphsVersionPrefix; + std::optional glyphsVersionPrefix; std::string tileTemplate; std::string tileDomainName; - optional tileVersionPrefix; + std::optional tileVersionPrefix; std::string apiKeyParameterName; bool apiKeyRequired; @@ -71,7 +69,7 @@ namespace mbgl { return impl_->uriSchemeAlias; } - TileServerOptions& TileServerOptions::withSourceTemplate(std::string sourceTemplate, std::string domainName, optional versionPrefix) { + TileServerOptions& TileServerOptions::withSourceTemplate(std::string sourceTemplate, std::string domainName, std::optional versionPrefix) { impl_->sourceTemplate = std::move(sourceTemplate); impl_->sourceVersionPrefix = std::move(versionPrefix); impl_->sourceDomainName = std::move(domainName); @@ -86,11 +84,11 @@ namespace mbgl { return impl_->sourceDomainName; } - const optional& TileServerOptions::sourceVersionPrefix() const { + const std::optional& TileServerOptions::sourceVersionPrefix() const { return impl_->sourceVersionPrefix; } - TileServerOptions& TileServerOptions::withStyleTemplate(std::string styleTemplate, std::string domainName, optional versionPrefix) { + TileServerOptions& TileServerOptions::withStyleTemplate(std::string styleTemplate, std::string domainName, std::optional versionPrefix) { impl_->styleTemplate = std::move(styleTemplate); impl_->styleDomainName = std::move(domainName); impl_->styleVersionPrefix = std::move(versionPrefix); @@ -105,11 +103,11 @@ namespace mbgl { return impl_->styleDomainName; } - const optional& TileServerOptions::styleVersionPrefix() const { + const std::optional& TileServerOptions::styleVersionPrefix() const { return impl_->styleVersionPrefix; } - TileServerOptions& TileServerOptions::withSpritesTemplate(std::string spritesTemplate, std::string domainName, optional versionPrefix) { + TileServerOptions& TileServerOptions::withSpritesTemplate(std::string spritesTemplate, std::string domainName, std::optional versionPrefix) { impl_->spritesTemplate = std::move(spritesTemplate); impl_->spritesDomainName = std::move(domainName); impl_->spritesVersionPrefix = std::move(versionPrefix); @@ -124,11 +122,11 @@ namespace mbgl { return impl_->spritesDomainName; } - const optional& TileServerOptions::spritesVersionPrefix() const { + const std::optional& TileServerOptions::spritesVersionPrefix() const { return impl_->spritesVersionPrefix; } - TileServerOptions& TileServerOptions::withGlyphsTemplate(std::string glyphsTemplate, std::string domainName, optional versionPrefix) { + TileServerOptions& TileServerOptions::withGlyphsTemplate(std::string glyphsTemplate, std::string domainName, std::optional versionPrefix) { impl_->glyphsTemplate = std::move(glyphsTemplate); impl_->glyphsDomainName = std::move(domainName); impl_->glyphsVersionPrefix = std::move(versionPrefix); @@ -143,11 +141,11 @@ namespace mbgl { return impl_->glyphsDomainName; } - const optional& TileServerOptions::glyphsVersionPrefix() const { + const std::optional& TileServerOptions::glyphsVersionPrefix() const { return impl_->glyphsVersionPrefix; } - TileServerOptions& TileServerOptions::withTileTemplate(std::string tileTemplate, std::string domainName, optional versionPrefix) { + TileServerOptions& TileServerOptions::withTileTemplate(std::string tileTemplate, std::string domainName, std::optional versionPrefix) { impl_->tileTemplate = std::move(tileTemplate); impl_->tileDomainName = std::move(domainName); impl_->tileVersionPrefix = std::move(versionPrefix); @@ -162,7 +160,7 @@ namespace mbgl { return impl_->tileDomainName; } - const optional& TileServerOptions::tileVersionPrefix() const { + const std::optional& TileServerOptions::tileVersionPrefix() const { return impl_->tileVersionPrefix; } diff --git a/src/mbgl/util/token.hpp b/src/mbgl/util/token.hpp index dea12f941..f2fc334cc 100644 --- a/src/mbgl/util/token.hpp +++ b/src/mbgl/util/token.hpp @@ -1,10 +1,9 @@ #pragma once -#include - #include #include #include +#include namespace mbgl { namespace util { @@ -28,7 +27,7 @@ std::string replaceTokens(const std::string &source, const Lookup &lookup) { for (brace++; brace != end && tokenReservedChars.find(*brace) == std::string::npos; brace++); if (brace != end && *brace == '}') { std::string key { pos + 1, brace }; - if (optional replacement = lookup(key)) { + if (std::optional replacement = lookup(key)) { result.append(*replacement); } else { result.append("{"); diff --git a/src/mbgl/util/url.cpp b/src/mbgl/util/url.cpp index c247931c2..9dbefaebc 100644 --- a/src/mbgl/util/url.cpp +++ b/src/mbgl/util/url.cpp @@ -132,7 +132,7 @@ Path::Path(const std::string& str, const size_t pos, const size_t count) } std::string transformURL(const std::string& tpl, const std::string& str, const URL& url) { - auto result = util::replaceTokens(tpl, [&](const std::string& token) -> optional { + auto result = util::replaceTokens(tpl, [&](const std::string& token) -> std::optional { if (token == "path") { return str.substr(url.path.first, url.path.second); } else if (token == "domain") { diff --git a/test/map/map.test.cpp b/test/map/map.test.cpp index 91f7e9060..9ae9d88ac 100644 --- a/test/map/map.test.cpp +++ b/test/map/map.test.cpp @@ -758,7 +758,7 @@ TEST(Map, DisabledSources) { MapTest<> test; // Always load the same image tile for raster layers. - test.fileSource->response = [] (const Resource& res) -> optional { + test.fileSource->response = [] (const Resource& res) -> std::optional { if (res.url == "asset://tile.png") { Response response; response.data = std::make_shared( @@ -1245,8 +1245,8 @@ TEST(Map, PrefetchDeltaOverride) { } }; - test.map.getStyle().getSource("vector")->setPrefetchZoomDelta(nullopt); - test.map.getStyle().getSource("custom")->setPrefetchZoomDelta(nullopt); + test.map.getStyle().getSource("vector")->setPrefetchZoomDelta(std::nullopt); + test.map.getStyle().getSource("custom")->setPrefetchZoomDelta(std::nullopt); test.runLoop.run(); // Each source requests 4 additional parent tiles. diff --git a/test/map/prefetch.test.cpp b/test/map/prefetch.test.cpp index e1fe1f12f..1d5b387f5 100644 --- a/test/map/prefetch.test.cpp +++ b/test/map/prefetch.test.cpp @@ -40,7 +40,7 @@ TEST(Map, PrefetchTiles) { std::vector tiles; - fileSource->response = [&] (const Resource& res) -> optional { + fileSource->response = [&] (const Resource& res) -> std::optional { static std::string tile = util::read_file("test/fixtures/map/prefetch/tile.png"); auto zoom = std::stoi(res.url); diff --git a/test/sprite/sprite_loader.test.cpp b/test/sprite/sprite_loader.test.cpp index 89b79f5b4..2c37e687e 100644 --- a/test/sprite/sprite_loader.test.cpp +++ b/test/sprite/sprite_loader.test.cpp @@ -166,7 +166,7 @@ TEST(SpriteLoader, LoadingCancel) { test.fileSource.spriteImageResponse = test.fileSource.spriteJSONResponse = [&] (const Resource&) { test.end(); - return optional(); + return std::optional(); }; test.observer.spriteLoaded = [&](std::vector>) { diff --git a/test/src/mbgl/test/stub_file_source.cpp b/test/src/mbgl/test/stub_file_source.cpp index 0c6557ef3..8b89e9581 100644 --- a/test/src/mbgl/test/stub_file_source.cpp +++ b/test/src/mbgl/test/stub_file_source.cpp @@ -33,7 +33,7 @@ StubFileSource::StubFileSource(const ResourceOptions& resourceOptions_, const Cl // Explicit copy to avoid iterator invalidation if ~StubFileRequest gets called within the loop. auto pending_ = pending; for (auto& pair : pending_) { - optional res = std::get<1>(pair.second)(std::get<0>(pair.second)); + std::optional res = std::get<1>(pair.second)(std::get<0>(pair.second)); if (res) { // This must be before calling the callback, because it's possible that the callback // could: @@ -58,7 +58,7 @@ StubFileSource::~StubFileSource() = default; std::unique_ptr StubFileSource::request(const Resource& resource, Callback callback) { auto req = std::make_unique(*this); if (type == ResponseType::Synchronous) { - optional res = response(resource); + std::optional res = response(resource); if (res) { callback(*res); } @@ -84,7 +84,7 @@ mapbox::base::Value StubFileSource::getProperty(const std::string& key) const { return (it != properties.end()) ? it->second : mapbox::base::Value(); } -optional StubFileSource::defaultResponse(const Resource& resource) { +std::optional StubFileSource::defaultResponse(const Resource& resource) { switch (resource.kind) { case Resource::Kind::Style: if (!styleResponse) throw std::runtime_error("unexpected style request"); diff --git a/test/src/mbgl/test/stub_file_source.hpp b/test/src/mbgl/test/stub_file_source.hpp index 5851f8984..63c5ee08c 100644 --- a/test/src/mbgl/test/stub_file_source.hpp +++ b/test/src/mbgl/test/stub_file_source.hpp @@ -29,7 +29,7 @@ public: void setProperty(const std::string&, const mapbox::base::Value&) override; mapbox::base::Value getProperty(const std::string&) const override; - using ResponseFunction = std::function (const Resource&)>; + using ResponseFunction = std::function (const Resource&)>; // You can set the response callback on a global level by assigning this callback: ResponseFunction response = [this] (const Resource& resource) { @@ -55,7 +55,7 @@ private: friend class StubOnlineFileSource; // The default behavior is to throw if no per-kind callback has been set. - optional defaultResponse(const Resource&); + std::optional defaultResponse(const Resource&); std::unordered_map> pending; ResponseType type; diff --git a/test/src/mbgl/test/stub_geometry_tile_feature.hpp b/test/src/mbgl/test/stub_geometry_tile_feature.hpp index 024e3c6c4..e77692fc7 100644 --- a/test/src/mbgl/test/stub_geometry_tile_feature.hpp +++ b/test/src/mbgl/test/stub_geometry_tile_feature.hpp @@ -32,8 +32,8 @@ public: return id; } - optional getValue(const std::string& key) const override { - return properties.count(key) ? properties.at(key) : optional(); + std::optional getValue(const std::string& key) const override { + return properties.count(key) ? properties.at(key) : std::optional(); } const GeometryCollection& getGeometries() const override { diff --git a/test/src/mbgl/test/util.cpp b/test/src/mbgl/test/util.cpp index 6484902d5..742989265 100644 --- a/test/src/mbgl/test/util.cpp +++ b/test/src/mbgl/test/util.cpp @@ -34,8 +34,7 @@ void checkImage(const std::string& base, try { expected_image = util::read_file(base + "/expected.png"); } catch (std::exception& ex) { - Log::Error(Event::Setup, "Failed to load expected image %s: %s", - (base + "/expected.png").c_str(), ex.what()); + Log::Error(Event::Setup, "Failed to load expected image " + base + "/expected.png" + ": " + ex.what()); throw; } diff --git a/test/storage/offline_database.test.cpp b/test/storage/offline_database.test.cpp index 943c36122..297211610 100644 --- a/test/storage/offline_database.test.cpp +++ b/test/storage/offline_database.test.cpp @@ -1582,7 +1582,7 @@ TEST(OfflineDatabase, CorruptDatabaseOnQuery) { EXPECT_EQ(0u, log.uncheckedCount()); // The first request fails because the database is corrupt and has to be recreated. - EXPECT_EQ(nullopt, db.get(fixture::tile)); + EXPECT_EQ(std::nullopt, db.get(fixture::tile)); EXPECT_EQ(1u, log.count(error(ResultCode::Corrupt, "Can't read resource: database disk image is malformed"), true)); EXPECT_EQ(1u, log.count({ EventSeverity::Warning, Event::Database, -1, "Removing existing incompatible offline database" })); EXPECT_EQ(0u, log.uncheckedCount()); @@ -1616,7 +1616,7 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DisallowedIO)) { // Now forbid any type of IO on the database and test that none of the calls crashes. fs.allowIO(false); - EXPECT_EQ(nullopt, db.get(fixture::resource)); + EXPECT_EQ(std::nullopt, db.get(fixture::resource)); EXPECT_EQ(1u, log.count(warning(ResultCode::Auth, "Can't update timestamp: authorization denied"))); EXPECT_EQ(1u, log.count(warning(ResultCode::Auth, "Can't read resource: authorization denied"))); EXPECT_EQ(0u, log.uncheckedCount()); @@ -1637,12 +1637,12 @@ TEST(OfflineDatabase, TEST_REQUIRES_WRITE(DisallowedIO)) { EXPECT_EQ(1u, log.count(warning(ResultCode::Auth, "Can't update region metadata: authorization denied"))); EXPECT_EQ(0u, log.uncheckedCount()); - EXPECT_EQ(nullopt, db.getRegionResource(fixture::resource)); + EXPECT_EQ(std::nullopt, db.getRegionResource(fixture::resource)); EXPECT_EQ(1u, log.count(warning(ResultCode::Auth, "Can't update timestamp: authorization denied"))); EXPECT_EQ(1u, log.count(warning(ResultCode::Auth, "Can't read region resource: authorization denied"))); EXPECT_EQ(0u, log.uncheckedCount()); - EXPECT_EQ(nullopt, db.hasRegionResource(fixture::resource)); + EXPECT_EQ(std::nullopt, db.hasRegionResource(fixture::resource)); EXPECT_EQ(1u, log.count(warning(ResultCode::Auth, "Can't query region resource: authorization denied"))); EXPECT_EQ(0u, log.uncheckedCount()); diff --git a/test/style/conversion/conversion_impl.test.cpp b/test/style/conversion/conversion_impl.test.cpp index 633d77886..1a6c1a030 100644 --- a/test/style/conversion/conversion_impl.test.cpp +++ b/test/style/conversion/conversion_impl.test.cpp @@ -42,37 +42,37 @@ public: return {}; } - static optional objectMember(const MockConvertible&, const char *) { - return nullopt; + static std::optional objectMember(const MockConvertible&, const char *) { + return std::nullopt; } template - static optional eachMember(const MockConvertible&, Fn&&) { - return nullopt; + static std::optional eachMember(const MockConvertible&, Fn&&) { + return std::nullopt; } - static optional toBool(const MockConvertible&) { - return nullopt; + static std::optional toBool(const MockConvertible&) { + return std::nullopt; } - static optional toNumber(const MockConvertible&) { - return nullopt; + static std::optional toNumber(const MockConvertible&) { + return std::nullopt; } - static optional toDouble(const MockConvertible&) { - return nullopt; + static std::optional toDouble(const MockConvertible&) { + return std::nullopt; } - static optional toString(const MockConvertible&) { - return nullopt; + static std::optional toString(const MockConvertible&) { + return std::nullopt; } - static optional toValue(const MockConvertible&) { - return nullopt; + static std::optional toValue(const MockConvertible&) { + return std::nullopt; } - static optional toGeoJSON(const MockConvertible&, Error&) { - return nullopt; + static std::optional toGeoJSON(const MockConvertible&, Error&) { + return std::nullopt; } }; diff --git a/test/style/conversion/geojson_options.test.cpp b/test/style/conversion/geojson_options.test.cpp index aa84686dc..cc5341e6e 100644 --- a/test/style/conversion/geojson_options.test.cpp +++ b/test/style/conversion/geojson_options.test.cpp @@ -10,13 +10,13 @@ using namespace mbgl::style::conversion; TEST(GeoJSONOptions, Basic) { Error error; - mbgl::optional converted = convertJSON("{}", error); + std::optional converted = convertJSON("{}", error); ASSERT_TRUE((bool) converted); } TEST(GeoJSONOptions, ErrorHandling) { Error error; - mbgl::optional converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(R"JSON({ "maxzoom": "should not be a string" })JSON", error); ASSERT_FALSE((bool) converted); diff --git a/test/style/conversion/tileset.test.cpp b/test/style/conversion/tileset.test.cpp index f92ed4678..8812c4752 100644 --- a/test/style/conversion/tileset.test.cpp +++ b/test/style/conversion/tileset.test.cpp @@ -10,13 +10,13 @@ using namespace mbgl::style::conversion; TEST(Tileset, Empty) { Error error; - mbgl::optional converted = convertJSON("{}", error); + std::optional converted = convertJSON("{}", error); EXPECT_FALSE((bool) converted); } TEST(Tileset, ErrorHandling) { Error error; - mbgl::optional converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(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 converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(R"JSON({ "tiles": ["http://mytiles"], "bounds": [73, -180, -73, -120] })JSON", error); @@ -34,7 +34,7 @@ TEST(Tileset, InvalidBounds) { } { Error error; - mbgl::optional converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(R"JSON({ "tiles": ["http://mytiles"], "bounds": [-120] })JSON", error); @@ -43,7 +43,7 @@ TEST(Tileset, InvalidBounds) { } { Error error; - mbgl::optional converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(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 converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(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 converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(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 converted = convertJSON(R"JSON({ + std::optional converted = convertJSON(R"JSON({ "tiles": ["http://mytiles"], "bounds": [-181.0000005,-90.000000006,180.00000000000006,91] })JSON", error); diff --git a/test/style/filter.test.cpp b/test/style/filter.test.cpp index 7bb59d4b4..ad397bfec 100644 --- a/test/style/filter.test.cpp +++ b/test/style/filter.test.cpp @@ -26,7 +26,7 @@ bool filter(const char * json, GeometryCollection featureGeometry = {}, float zoom = 0.0f) { conversion::Error error; - optional filter = conversion::convertJSON(json, error); + std::optional filter = conversion::convertJSON(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 = conversion::convertJSON(json, error); + std::optional filter = conversion::convertJSON(json, error); EXPECT_FALSE(bool(filter)); EXPECT_NE(error.message, ""); } @@ -67,7 +67,7 @@ void writeJSON(rapidjson::Writer& writer, const Value& std::string stringifyFilter(const char * json) { conversion::Error error; - optional filter = conversion::convertJSON(json, error); + std::optional filter = conversion::convertJSON(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 = conversion::convertJSON(R"(["any", ["all", ["==", ["geometry-type"], "LineString"]], ["==", "x", 1]])", error); + std::optional filter = conversion::convertJSON(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 result = conversion::convert(conversion::Convertible(&value), error); + std::optional result = conversion::convert(conversion::Convertible(&value), error); EXPECT_FALSE(result); } diff --git a/test/style/property_expression.test.cpp b/test/style/property_expression.test.cpp index 5932ade91..8556a22dd 100644 --- a/test/style/property_expression.test.cpp +++ b/test/style/property_expression.test.cpp @@ -63,11 +63,11 @@ TEST(PropertyExpression, Expression) { } TEST(PropertyExpression, Defaults) { - EXPECT_EQ(1.0f, PropertyExpression(number(get("property")), 0.0) + EXPECT_EQ(1.0f, PropertyExpression(number(get("property")), 0.0f) .evaluate(oneInteger, 2.0f)); - EXPECT_EQ(1.0f, PropertyExpression(number(get("property")), 0.0) + EXPECT_EQ(1.0f, PropertyExpression(number(get("property")), 0.0f) .evaluate(oneDouble, 2.0f)); - EXPECT_EQ(0.0f, PropertyExpression(number(get("property")), 0.0) + EXPECT_EQ(0.0f, PropertyExpression(number(get("property")), 0.0f) .evaluate(oneString, 2.0f)); EXPECT_EQ(2.0f, PropertyExpression(number(get("property"))) .evaluate(oneString, 2.0f)); diff --git a/test/style/source.test.cpp b/test/style/source.test.cpp index 6a16540a2..baee9e814 100644 --- a/test/style/source.test.cpp +++ b/test/style/source.test.cpp @@ -34,7 +34,6 @@ #include #include -#include #include #include #include @@ -47,6 +46,7 @@ #include #include +#include #include using namespace mbgl; @@ -466,7 +466,7 @@ TEST(Source, RasterTileCancel) { test.fileSource->tileResponse = [&] (const Resource&) { test.end(); - return optional(); + return std::optional(); }; RasterLayer layer("id", "source"); @@ -499,7 +499,7 @@ TEST(Source, RasterDEMTileCancel) { test.fileSource->tileResponse = [&] (const Resource&) { test.end(); - return optional(); + return std::optional(); }; HillshadeLayer layer("id", "source"); @@ -532,7 +532,7 @@ TEST(Source, VectorTileCancel) { test.fileSource->tileResponse = [&] (const Resource&) { test.end(); - return optional(); + return std::optional(); }; LineLayer layer("id", "source"); @@ -780,7 +780,7 @@ public: [&](const OverscaledTileID& tileID) { return std::make_unique(*this, tileID); }); } - const optional& getTileset() const override { + const std::optional& getTileset() const override { return static_cast(*baseImpl).tileset; } }; @@ -877,7 +877,7 @@ TEST(Source, RenderTileSetSourceUpdate) { mockedUpdateInternal(); } - const optional& getTileset() const override { + const std::optional& getTileset() const override { return static_cast(*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); diff --git a/test/style/style.test.cpp b/test/style/style.test.cpp index 3106882cb..c02c274d8 100644 --- a/test/style/style.test.cpp +++ b/test/style/style.test.cpp @@ -47,7 +47,7 @@ TEST(Style, Properties) { style.loadJSON(R"STYLE({})STYLE"); ASSERT_EQ(Milliseconds(300), *style.getTransitionOptions().duration); - ASSERT_EQ(optional {}, style.getTransitionOptions().delay); + ASSERT_EQ(std::optional{}, style.getTransitionOptions().delay); style.loadJSON(R"STYLE({"transition": { "duration": 500, "delay": 50 }})STYLE"); ASSERT_EQ(Milliseconds(500), *style.getTransitionOptions().duration); diff --git a/test/style/style_layer.test.cpp b/test/style/style_layer.test.cpp index 84bad2830..1417fd1d6 100644 --- a/test/style/style_layer.test.cpp +++ b/test/style/style_layer.test.cpp @@ -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() = PropertyValueType(std::move(formatted)); EXPECT_TRUE(MockOverrides::hasOverrides(layout.template get())); @@ -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(std::vector{section}); PropertyExpression propExprOverride(std::move(formatExprOverride)); layout.template get() = PropertyValueType(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 sections{{std::move(secondParagraph)}}; auto formattedExpr2 = std::make_unique(std::move(sections)); std::unordered_map> 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() = PossiblyEvaluatedPropertyValue(std::move(formatted)); paint.get() = PossiblyEvaluatedPropertyValue{Color::red()}; EXPECT_TRUE(paint.get().isConstant()); diff --git a/test/style/style_parser.test.cpp b/test/style/style_parser.test.cpp index 9f462af54..03286d59d 100644 --- a/test/style/style_parser.test.cpp +++ b/test/style/style_parser.test.cpp @@ -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()); diff --git a/test/text/cross_tile_symbol_index.test.cpp b/test/text/cross_tile_symbol_index.test.cpp index 938c4ae4c..86fda3bea 100644 --- a/test/text/cross_tile_symbol_index.test.cpp +++ b/test/text/cross_tile_symbol_index.test.cpp @@ -19,8 +19,8 @@ SymbolInstance makeSymbolInstance(float x, float y, std::u16string key) { auto sharedData = std::make_shared(std::move(line), shaping, - nullopt, - nullopt, + std::nullopt, + std::nullopt, layout_, placementType, textOffset, @@ -29,7 +29,7 @@ SymbolInstance makeSymbolInstance(float x, float y, std::u16string key) { SymbolContent::IconSDF, false, false); - return SymbolInstance(anchor, std::move(sharedData), shaping, nullopt, nullopt, 0, 0, placementType, textOffset, 0, 0, iconOffset, subfeature, 0, 0, key, 0.0f, 0.0f, 0.0f, variableTextOffset, false); + return SymbolInstance(anchor, std::move(sharedData), shaping, std::nullopt, std::nullopt, 0, 0, placementType, textOffset, 0, 0, iconOffset, subfeature, 0, 0, key, 0.0f, 0.0f, 0.0f, variableTextOffset, false); } diff --git a/test/text/formatted.test.cpp b/test/text/formatted.test.cpp index 70e743f5c..cb7811b35 100644 --- a/test/text/formatted.test.cpp +++ b/test/text/formatted.test.cpp @@ -1,7 +1,6 @@ #include #include -#include using namespace mbgl; using namespace mbgl::style::expression; @@ -19,7 +18,7 @@ TEST(Formatted, Empty) { Formatted emptyFormatted{""}; EXPECT_TRUE(emptyFormatted.empty()); - auto emptyText = FormattedSection{"", nullopt, nullopt, nullopt}; + auto emptyText = FormattedSection{"", std::nullopt, std::nullopt, std::nullopt}; auto emptyImage = FormattedSection{style::expression::Image()}; Formatted multipleEmptySections{std::vector{emptyText, emptyText, emptyText}}; EXPECT_TRUE(multipleEmptySections.empty()); @@ -27,7 +26,7 @@ TEST(Formatted, Empty) { Formatted multipleEmptySectionsWithImage{std::vector{emptyText, emptyImage, emptyText}}; EXPECT_TRUE(multipleEmptySectionsWithImage.empty()); - auto text = FormattedSection{"Formatted", nullopt, nullopt, nullopt}; + auto text = FormattedSection{"Formatted", std::nullopt, std::nullopt, std::nullopt}; auto image = FormattedSection{style::expression::Image("Image")}; Formatted multipleSections{std::vector{emptyText, text, emptyText}}; @@ -41,7 +40,7 @@ TEST(Formatted, ToString) { Formatted emptyFormatted{""}; EXPECT_EQ(emptyFormatted.toString(), ""); - auto text = FormattedSection{"Formatted", nullopt, nullopt, nullopt}; + auto text = FormattedSection{"Formatted", std::nullopt, std::nullopt, std::nullopt}; Formatted multipleSections{std::vector{text, text}}; EXPECT_EQ(multipleSections.toString(), "FormattedFormatted"); diff --git a/test/text/glyph_manager.test.cpp b/test/text/glyph_manager.test.cpp index 56af4ae6a..68c39822d 100644 --- a/test/text/glyph_manager.test.cpp +++ b/test/text/glyph_manager.test.cpp @@ -194,7 +194,7 @@ TEST(GlyphManager, LoadingCancel) { test.fileSource.glyphsResponse = [&] (const Resource&) { test.end(); - return optional(); + return std::optional(); }; test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) { @@ -214,7 +214,7 @@ TEST(GlyphManager, LoadLocalCJKGlyph) { test.fileSource.glyphsResponse = [&] (const Resource&) { glyphResponses++; - return optional(); + return std::optional(); }; test.observer.glyphsLoaded = [&] (const FontStack&, const GlyphRange&) { diff --git a/test/text/local_glyph_rasterizer.test.cpp b/test/text/local_glyph_rasterizer.test.cpp index e1eef4684..24a34d420 100644 --- a/test/text/local_glyph_rasterizer.test.cpp +++ b/test/text/local_glyph_rasterizer.test.cpp @@ -32,7 +32,7 @@ namespace { class LocalGlyphRasterizerTest { public: - LocalGlyphRasterizerTest(const optional fontFamily) + LocalGlyphRasterizerTest(const std::optional fontFamily) : frontend(1, gfx::HeadlessBackend::SwapBehaviour::NoFlush, gfx::ContextMode::Unique, fontFamily) {} util::RunLoop loop; diff --git a/test/text/quads.test.cpp b/test/text/quads.test.cpp index e159d28bb..7b11c3371 100644 --- a/test/text/quads.test.cpp +++ b/test/text/quads.test.cpp @@ -50,7 +50,7 @@ TEST(getIconQuads, style) { // shapedText.positionedGlyphs.emplace_back(PositionedGlyph(32, 0.0f, 0.0f, false, 0, 1.0)); shapedText.positionedLines.emplace_back(); shapedText.positionedLines.back().positionedGlyphs.emplace_back( - PositionedGlyph(32, 0.0f, 0.0f, false, 0, 1.0, /*texRect*/ {}, /*metrics*/ {}, /*imageID*/ nullopt)); + PositionedGlyph(32, 0.0f, 0.0f, false, 0, 1.0, /*texRect*/ {}, /*metrics*/ {}, /*imageID*/ std::nullopt)); // none { diff --git a/test/tile/vector_tile.test.cpp b/test/tile/vector_tile.test.cpp index cb12c5853..0661b54f3 100644 --- a/test/tile/vector_tile.test.cpp +++ b/test/tile/vector_tile.test.cpp @@ -103,5 +103,5 @@ TEST(VectorTileData, ParseResults) { ASSERT_EQ(properties.size(), 3u); ASSERT_EQ(properties.at("disputed"), *feature->getValue("disputed")); - ASSERT_EQ(feature->getValue("invalid"), nullopt); + ASSERT_EQ(feature->getValue("invalid"), std::nullopt); } diff --git a/test/util/merge_lines.test.cpp b/test/util/merge_lines.test.cpp index 5137a245e..3239f0798 100644 --- a/test/util/merge_lines.test.cpp +++ b/test/util/merge_lines.test.cpp @@ -23,8 +23,8 @@ public: FeatureType type_, GeometryCollection geometry_, PropertyMap properties_, - optional text_, - optional icon_, + std::optional text_, + std::optional icon_, std::size_t index_) : SymbolFeature(std::make_unique( std::move(id_), type_, std::move(geometry_), std::move(properties_))) { diff --git a/test/util/token.test.cpp b/test/util/token.test.cpp index d0cf1e31c..27386d8fb 100644 --- a/test/util/token.test.cpp +++ b/test/util/token.test.cpp @@ -47,7 +47,7 @@ TEST(Token, replaceTokens) { if (token == "HØYDE") return "150"; return ""; })); - EXPECT_EQ("{unknown}", mbgl::util::replaceTokens("{unknown}", [](const std::string&) -> optional { + EXPECT_EQ("{unknown}", mbgl::util::replaceTokens("{unknown}", [](const std::string&) -> std::optional { return {}; })); }