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

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

View File

@@ -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

View File

@@ -16,6 +16,7 @@
#include <mbgl/util/run_loop.hpp>
#include <sstream>
#include <optional>
using namespace mbgl;
@@ -34,7 +35,7 @@ public:
util::RunLoop loop;
};
void prepare(Map& map, optional<std::string> json = nullopt) {
void prepare(Map& map, std::optional<std::string> 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<std::string> json = nullopt) {
map.getStyle().addImage(std::make_unique<style::Image>("test-icon", std::move(image), 1.0f));
}
void prepare_map2(Map& map, optional<std::string> json = nullopt) {
void prepare_map2(Map& map, std::optional<std::string> 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

View File

@@ -27,7 +27,7 @@ static void Parse_CameraFunction(benchmark::State& state) {
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(doc, error, false, false);
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(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<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, false, false);
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, false, false);
if (!function) {
state.SkipWithError(error.message.c_str());
}

View File

@@ -33,7 +33,7 @@ static void Parse_CompositeFunction(benchmark::State& state) {
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(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<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
if (!function) {
state.SkipWithError(error.message.c_str());
}

View File

@@ -28,7 +28,7 @@ static void Parse_SourceFunction(benchmark::State& state) {
state.PauseTiming();
auto doc = createFunctionJSON(stopCount);
state.ResumeTiming();
optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> result = conversion::convertJSON<PropertyValue<float>>(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<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
std::optional<PropertyValue<float>> function = conversion::convertJSON<PropertyValue<float>>(doc, error, true, false);
if (!function) {
state.SkipWithError(error.message.c_str());
}

View File

@@ -31,8 +31,8 @@ public:
return id;
}
optional<Value> getValue(const std::string& key) const override {
return properties.count(key) ? properties.at(key) : optional<Value>();
std::optional<Value> getValue(const std::string& key) const override {
return properties.count(key) ? properties.at(key) : std::optional<Value>();
}
const GeometryCollection& getGeometries() const override {

View File

@@ -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);
}
}

View File

@@ -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<std::string> mergePath = {};
std::optional<std::string> mergePath = std::nullopt;
if (mergePathValue) mergePath = args::get(mergePathValue);
mbgl::optional<std::string> inputDb = {};
std::optional<std::string> 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<DatabaseFileSource> fileSource_,
util::RunLoop& loop_,
mbgl::optional<std::string> mergePath_)
std::optional<std::string> mergePath_)
: region(region_),
fileSource(std::move(fileSource_)),
loop(loop_),
@@ -249,7 +249,7 @@ int main(int argc, char *argv[]) {
OfflineRegion& region;
std::shared_ptr<DatabaseFileSource> fileSource;
util::RunLoop& loop;
mbgl::optional<std::string> mergePath;
std::optional<std::string> mergePath;
Timestamp start;
};

View File

@@ -75,7 +75,7 @@ std::string toString(const JSValue& value) {
return { value.GetString(), value.GetStringLength() };
}
optional<Value> toValue(const JSValue& jsvalue) {
std::optional<Value> toValue(const JSValue& jsvalue) {
if (jsvalue.IsNull()) {
return Value{};
}
@@ -105,7 +105,7 @@ optional<Value> 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<style::expression::type::Type> toExpressionType(const PropertySpec& spec) {
std::optional<style::expression::type::Type> 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<style::expression::type::Type> toExpressionType(const PropertySpec& spe
return {type::String};
}
return spec.type.empty() ? nullopt : optional<type::Type>{stringToType(spec.type)};
return spec.type.empty() ? std::nullopt : std::optional<type::Type>{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<float> zoom;
std::optional<float> 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<double> heatmapDensity;
std::optional<double> heatmapDensity;
if (evaluationContext.HasMember("heatmapDensity")) {
assert(evaluationContext["heatmapDensity"].IsNumber());
heatmapDensity = evaluationContext["heatmapDensity"].GetDouble();
}
// Parse canonicalID
optional<CanonicalTileID> canonical;
std::optional<CanonicalTileID> canonical;
if (evaluationContext.HasMember("canonicalID")) {
const auto& canonicalIDObject = evaluationContext["canonicalID"];
assert(canonicalIDObject.IsObject());
@@ -344,7 +344,7 @@ std::tuple<filesystem::path, std::vector<filesystem::path>, 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<filesystem::path, std::vector<filesystem::path>, 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<TestData> parseTestData(const filesystem::path& path) {
std::optional<TestData> parseTestData(const filesystem::path& path) {
TestData data;
auto maybeJson = readJson(path.string());
if (!maybeJson.is<JSDocument>()) { // 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<JSDocument>());
// 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<TestData> 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<Value> toValue(const expression::Value& exprValue) {
std::optional<Value> toValue(const expression::Value& exprValue) {
return exprValue.match(
[](const Color& c) -> optional<Value> {
[](const Color& c) -> std::optional<Value> {
std::vector<Value> color { static_cast<double>(c.r), static_cast<double>(c.g), static_cast<double>(c.b), static_cast<double>(c.a) };
return {Value{std::move(color)}};
},
[](const expression::Formatted& formatted) -> optional<Value> { return {formatted.toObject()}; },
[](const std::vector<expression::Value>& values) -> optional<Value> {
[](const expression::Formatted& formatted) -> std::optional<Value> { return {formatted.toObject()}; },
[](const std::vector<expression::Value>& values) -> std::optional<Value> {
std::vector<Value> mbglValues;
for (const auto& value : values) {
if (auto converted = expression::fromExpressionValue<Value>(value)) {
@@ -487,7 +487,7 @@ optional<Value> toValue(const expression::Value& exprValue) {
}
return {Value{std::move(mbglValues)}};
},
[](const std::unordered_map<std::string, expression::Value>& valueMap) -> optional<Value> {
[](const std::unordered_map<std::string, expression::Value>& valueMap) -> std::optional<Value> {
std::unordered_map<std::string, Value> mbglValueMap;
for (const auto& pair : valueMap) {
if (auto converted = expression::fromExpressionValue<Value>(pair.second)) {
@@ -500,9 +500,9 @@ optional<Value> toValue(const expression::Value& exprValue) {
}
std::unique_ptr<style::expression::Expression> parseExpression(const JSValue& value,
optional<PropertySpec>& spec,
std::optional<PropertySpec>& spec,
TestResult& result) {
optional<style::expression::type::Type> expected = spec ? toExpressionType(*spec) : nullopt;
std::optional<style::expression::type::Type> 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<style::expression::Expression> parseExpression(const JSValue& va
return nullptr;
}
std::unique_ptr<style::expression::Expression> parseExpression(const optional<Value>& value,
optional<PropertySpec>& spec,
std::unique_ptr<style::expression::Expression> parseExpression(const std::optional<Value>& value,
std::optional<PropertySpec>& spec,
TestResult& result) {
assert(value);
auto document = toDocument(*value);

View File

@@ -4,7 +4,6 @@
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/rapidjson.hpp>
#include <set>
@@ -14,9 +13,9 @@
using namespace mbgl;
struct Input {
Input(optional<float> zoom_,
optional<double> heatmapDensity_,
optional<CanonicalTileID> canonical_,
Input(std::optional<float> zoom_,
std::optional<double> heatmapDensity_,
std::optional<CanonicalTileID> canonical_,
std::set<std::string> 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<float> zoom;
optional<double> heatmapDensity;
optional<CanonicalTileID> canonical;
std::optional<float> zoom;
std::optional<double> heatmapDensity;
std::optional<CanonicalTileID> canonical;
std::set<std::string> availableImages;
Feature feature;
};
@@ -50,9 +49,9 @@ struct Compiled {
struct TestResult {
Compiled compiled;
optional<Value> expression;
optional<Value> outputs;
optional<Value> serialized;
std::optional<Value> expression;
std::optional<Value> outputs;
std::optional<Value> serialized;
};
struct PropertySpec {
@@ -60,7 +59,7 @@ struct PropertySpec {
std::string value;
std::size_t length = 0;
bool isDataDriven = false;
optional<Value> expression;
std::optional<Value> expression;
};
class TestData {
@@ -69,7 +68,7 @@ public:
TestResult expected;
TestResult result;
TestResult recompiled;
optional<PropertySpec> spec;
std::optional<PropertySpec> spec;
JSDocument document;
};
@@ -87,17 +86,17 @@ Arguments parseArguments(int argc, char** argv);
using Ignores = std::vector<Ignore>;
Ignores parseExpressionIgnores();
optional<TestData> parseTestData(const filesystem::path&);
std::optional<TestData> 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<Value> toValue(const style::expression::Value&);
std::optional<Value> toValue(const style::expression::Value&);
std::unique_ptr<style::expression::Expression> parseExpression(const JSValue&,
optional<PropertySpec>&,
std::optional<PropertySpec>&,
TestResult&);
std::unique_ptr<style::expression::Expression> parseExpression(const optional<Value>&,
optional<PropertySpec>&,
std::unique_ptr<style::expression::Expression> parseExpression(const std::optional<Value>&,
std::optional<PropertySpec>&,
TestResult&);

View File

@@ -40,7 +40,7 @@ try {
ignoreReason = (*it).reason;
}
optional<TestRunOutput> testRun;
std::optional<TestRunOutput> testRun;
if (auto testData = parseTestData(path)) {
testRun = runExpressionTest(*testData, rootPath.string(), id);
}

View File

@@ -118,7 +118,7 @@ bool deepEqual(const Value& a, const Value& b) {
return false;
}
bool deepEqual(const optional<Value>& a, const optional<Value>& b) {
bool deepEqual(const std::optional<Value>& a, const std::optional<Value>& b) {
if ((a && !b) || (!a && b)) {
return false;
}

View File

@@ -10,4 +10,4 @@ using namespace mbgl;
Value stripPrecision(const Value& value);
std::vector<std::string> tokenize(std::string str);
bool deepEqual(const Value& a, const Value& b);
bool deepEqual(const optional<Value>& a, const optional<Value>& b);
bool deepEqual(const std::optional<Value>& a, const std::optional<Value>& b);

View File

@@ -1,7 +1,5 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <functional>
#include <memory>
#include <mutex>

View File

@@ -1,7 +1,5 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <future>
#include <utility>

View File

@@ -73,8 +73,8 @@ public:
Mutable<Impl> mutableImpl() const;
private:
optional<conversion::Error> setPropertyInternal(const std::string& name,
const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name,
const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string&) const final;
std::unique_ptr<Layer> cloneRef(const std::string& id) const final;
Mutable<Layer::Impl> mutableBaseImpl() const final;

View File

@@ -1,16 +1,15 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <memory>
#include <string>
#include <optional>
namespace mbgl {
namespace platform {
class Collator {
public:
explicit Collator(bool caseSensitive, bool diacriticSensitive, const optional<std::string>& locale = nullopt);
explicit Collator(bool caseSensitive, bool diacriticSensitive, const std::optional<std::string>& locale = std::nullopt);
int compare(const std::string& lhs, const std::string& rhs) const;
std::string resolvedLocale() const;
bool operator==(const Collator& other) const;

View File

@@ -36,7 +36,7 @@ public:
virtual std::unique_ptr<Layout> createLayout(const LayoutParameters&, std::unique_ptr<GeometryTileLayer>, const std::vector<Immutable<style::LayerProperties>>&) noexcept;
protected:
optional<std::string> getSource(const style::conversion::Convertible& value) const noexcept;
std::optional<std::string> getSource(const style::conversion::Convertible& value) const noexcept;
};
} // namespace mbgl

View File

@@ -1,7 +1,8 @@
#pragma once
#include <mbgl/util/geo.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
@@ -28,19 +29,19 @@ struct BoundOptions {
}
/// Constrain the center of the camera to be within these bounds.
optional<LatLngBounds> bounds;
std::optional<LatLngBounds> bounds;
/// Maximum zoom level allowed.
optional<double> maxZoom;
std::optional<double> maxZoom;
/// Minimum zoom level allowed.
optional<double> minZoom;
std::optional<double> minZoom;
/// Maximum pitch allowed in degrees.
optional<double> maxPitch;
std::optional<double> maxPitch;
/// Minimum pitch allowed in degrees.
optional<double> minPitch;
std::optional<double> minPitch;
};
} // namespace mbgl

View File

@@ -2,10 +2,11 @@
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/unitbezier.hpp>
#include <mbgl/util/vectors.hpp>
#include <optional>
#include <functional>
namespace mbgl {
@@ -16,34 +17,34 @@ namespace mbgl {
center point when both are set.
*/
struct CameraOptions {
CameraOptions& withCenter(const optional<LatLng>& o) { center = o; return *this; }
CameraOptions& withPadding(const optional<EdgeInsets>& p) { padding = p; return *this; }
CameraOptions& withAnchor(const optional<ScreenCoordinate>& o) { anchor = o; return *this; }
CameraOptions& withZoom(const optional<double>& o) { zoom = o; return *this; }
CameraOptions& withBearing(const optional<double>& o) { bearing = o; return *this; }
CameraOptions& withPitch(const optional<double>& o) { pitch = o; return *this; }
CameraOptions& withCenter(const std::optional<LatLng>& o) { center = o; return *this; }
CameraOptions& withPadding(const std::optional<EdgeInsets>& p) { padding = p; return *this; }
CameraOptions& withAnchor(const std::optional<ScreenCoordinate>& o) { anchor = o; return *this; }
CameraOptions& withZoom(const std::optional<double>& o) { zoom = o; return *this; }
CameraOptions& withBearing(const std::optional<double>& o) { bearing = o; return *this; }
CameraOptions& withPitch(const std::optional<double>& o) { pitch = o; return *this; }
/** Coordinate at the center of the map. */
optional<LatLng> center;
std::optional<LatLng> center;
/** Padding around the interior of the view that affects the frame of
reference for `center`. */
optional<EdgeInsets> padding;
std::optional<EdgeInsets> padding;
/** Point of reference for `zoom` and `angle`, assuming an origin at the
top-left corner of the view. */
optional<ScreenCoordinate> anchor;
std::optional<ScreenCoordinate> anchor;
/** Zero-based zoom level. Constrained to the minimum and maximum zoom
levels. */
optional<double> zoom;
std::optional<double> zoom;
/** Bearing, measured in degrees from true north. Wrapped to [0, 360). */
optional<double> bearing;
std::optional<double> bearing;
/** Pitch toward the horizon measured in degrees , with 0 deg resulting in a
two-dimensional map. */
optional<double> pitch;
std::optional<double> 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> duration;
std::optional<Duration> duration;
/** Average velocity of a flyTo() transition, measured in screenfuls per
second, assuming a linear timing curve.
A <i>screenful</i> is the visible span in pixels. It does not correspond
to a fixed physical distance but rather varies by zoom level. */
optional<double> velocity;
std::optional<double> velocity;
/** Zero-based zoom level at the peak of the flyTo() transition’s flight
path. */
optional<double> minZoom;
std::optional<double> minZoom;
/** The easing timing curve of the transition. */
optional<mbgl::util::UnitBezier> easing;
std::optional<mbgl::util::UnitBezier> 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<vec3> position = nullopt;
std::optional<vec3> 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<vec4> orientation = nullopt;
std::optional<vec4> 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<LatLngAltitude> getLocation() const;
std::optional<LatLngAltitude> 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<vec3>& upVector = nullopt);
void lookAtPoint(const LatLng& location, const std::optional<vec3>& upVector = std::nullopt);
/** Helper function for setting the orientation of the camera as a pitch and a bearing.
Both values are in degrees */

View File

@@ -1,6 +1,5 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/map/bound_options.hpp>
#include <mbgl/map/map_observer.hpp>
@@ -20,6 +19,7 @@
#include <functional>
#include <vector>
#include <memory>
#include <optional>
namespace mbgl {
@@ -63,26 +63,26 @@ public:
bool isPanning() const;
// Camera
CameraOptions getCameraOptions(const optional<EdgeInsets>& = {}) const;
CameraOptions getCameraOptions(const std::optional<EdgeInsets>& = 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<ScreenCoordinate>& anchor, const AnimationOptions& animation = {});
void scaleBy(double scale, const std::optional<ScreenCoordinate>& 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<double>& bearing = {},
const optional<double>& pitch = {}) const;
const std::optional<double>& bearing = std::nullopt,
const std::optional<double>& pitch = std::nullopt) const;
CameraOptions cameraForLatLngs(const std::vector<LatLng>&,
const EdgeInsets&,
const optional<double>& bearing = {},
const optional<double>& pitch = {}) const;
const std::optional<double>& bearing = std::nullopt,
const std::optional<double>& pitch = std::nullopt) const;
CameraOptions cameraForGeometry(const Geometry<double>&,
const EdgeInsets&,
const optional<double>& bearing = {},
const optional<double>& pitch = {}) const;
const std::optional<double>& bearing = std::nullopt,
const std::optional<double>& pitch = std::nullopt) const;
LatLngBounds latLngBoundsForCamera(const CameraOptions&) const;
LatLngBounds latLngBoundsForCameraUnwrapped(const CameraOptions&) const;

View File

@@ -1,8 +1,7 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <functional>
#include <optional>
namespace mbgl {
@@ -18,17 +17,17 @@ struct ProjectionMode {
/**
* @brief Set to True to enable axonometric rendering, false otherwise.
*/
optional<bool> axonometric;
std::optional<bool> axonometric;
/**
* @brief The X skew value represents how much to skew on the x-axis.
*/
optional<double> xSkew;
std::optional<double> xSkew;
/**
* @brief The Y skew value represents how much to skew on the y-axis.
*/
optional<double> ySkew;
std::optional<double> ySkew;
};
} // namespace mbgl

View File

@@ -1,10 +1,10 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <mbgl/style/filter.hpp>
#include <string>
#include <vector>
#include <optional>
namespace mbgl {
@@ -13,15 +13,15 @@ namespace mbgl {
*/
class RenderedQueryOptions {
public:
RenderedQueryOptions(optional<std::vector<std::string>> layerIDs_ = {},
optional<style::Filter> filter_ = {})
RenderedQueryOptions(std::optional<std::vector<std::string>> layerIDs_ = std::nullopt,
std::optional<style::Filter> filter_ = std::nullopt)
: layerIDs(std::move(layerIDs_)),
filter(std::move(filter_)) {}
/** layerIDs to include in the query */
optional<std::vector<std::string>> layerIDs;
std::optional<std::vector<std::string>> layerIDs;
optional<style::Filter> filter;
std::optional<style::Filter> filter;
};
/**
@@ -29,15 +29,15 @@ public:
*/
class SourceQueryOptions {
public:
SourceQueryOptions(optional<std::vector<std::string>> sourceLayers_ = {},
optional<style::Filter> filter_ = {})
SourceQueryOptions(std::optional<std::vector<std::string>> sourceLayers_ = std::nullopt,
std::optional<style::Filter> filter_ = std::nullopt)
: sourceLayers(std::move(sourceLayers_)),
filter(std::move(filter_)) {}
/// Required for VectorSource, ignored for GeoJSONSource
optional<std::vector<std::string>> sourceLayers;
std::optional<std::vector<std::string>> sourceLayers;
optional<style::Filter> filter;
std::optional<style::Filter> filter;
};
} // namespace mbgl

View File

@@ -25,9 +25,9 @@ struct PlacedSymbolData {
/// Contents of the label
std::u16string key;
/// If symbol contains text, text collision box in viewport coordinates
optional<mapbox::geometry::box<float>> textCollisionBox;
std::optional<mapbox::geometry::box<float>> textCollisionBox;
/// If symbol contains icon, icon collision box in viewport coordinates
optional<mapbox::geometry::box<float>> iconCollisionBox;
std::optional<mapbox::geometry::box<float>> 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<std::string>& localFontFamily = {});
Renderer(gfx::RendererBackend&, float pixelRatio_, const std::optional<std::string>& localFontFamily = std::nullopt);
~Renderer();
void markContextLost();
@@ -65,20 +65,20 @@ public:
const Feature& feature,
const std::string& extension,
const std::string& extensionField,
const optional<std::map<std::string, Value>>& args = {}) const;
const std::optional<std::map<std::string, Value>>& args = std::nullopt) const;
void setFeatureState(const std::string& sourceID, const optional<std::string>& sourceLayerID,
void setFeatureState(const std::string& sourceID, const std::optional<std::string>& sourceLayerID,
const std::string& featureID, const FeatureState& state);
void getFeatureState(FeatureState& state,
const std::string& sourceID,
const optional<std::string>& sourceLayerID,
const std::optional<std::string>& sourceLayerID,
const std::string& featureID) const;
void removeFeatureState(const std::string& sourceID,
const optional<std::string>& sourceLayerID,
const optional<std::string>& featureID,
const optional<std::string>& stateKey);
const std::optional<std::string>& sourceLayerID,
const std::optional<std::string>& featureID,
const std::optional<std::string>& stateKey);
// Debug
void dumpDebugLogs();

View File

@@ -3,7 +3,6 @@
#include <mbgl/storage/file_source.hpp>
#include <mbgl/storage/offline.hpp>
#include <mbgl/util/expected.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {

View File

@@ -3,7 +3,6 @@
#include <mbgl/util/geo.hpp>
#include <mbgl/util/geometry.hpp>
#include <mbgl/util/range.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/storage/response.hpp>

View File

@@ -3,7 +3,8 @@
#include <mbgl/storage/file_source.hpp>
#include <mbgl/storage/resource_options.hpp>
#include <mbgl/util/client_options.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {

View File

@@ -2,11 +2,11 @@
#include <mbgl/storage/response.hpp>
#include <mbgl/util/bitmask_operations.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/tileset.hpp>
#include <string>
#include <optional>
namespace mbgl {
@@ -55,7 +55,7 @@ public:
Resource(Kind kind_,
std::string url_,
optional<TileData> tileData_ = {},
std::optional<TileData> 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> tileData;
std::optional<TileData> tileData;
optional<Timestamp> priorModified = {};
optional<Timestamp> priorExpires = {};
optional<std::string> priorEtag = {};
std::optional<Timestamp> priorModified = std::nullopt;
std::optional<Timestamp> priorExpires = std::nullopt;
std::optional<std::string> priorEtag = std::nullopt;
std::shared_ptr<const std::string> priorData;
Duration minimumUpdateInterval{Duration::zero()};
StoragePolicy storagePolicy{StoragePolicy::Permanent};

View File

@@ -1,8 +1,8 @@
#pragma once
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
#include <string>
#include <memory>
@@ -33,9 +33,9 @@ public:
// The actual data of the response. Present only for non-error, non-notModified responses.
std::shared_ptr<const std::string> data;
optional<Timestamp> modified;
optional<Timestamp> expires;
optional<std::string> etag;
std::optional<Timestamp> modified;
std::optional<Timestamp> expires;
std::optional<std::string> 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<Timestamp> retryAfter;
std::optional<Timestamp> retryAfter;
public:
Error(Reason, std::string = "", optional<Timestamp> = {});
Error(Reason, std::string = "", std::optional<Timestamp> = std::nullopt);
};
} // namespace mbgl

View File

@@ -9,7 +9,7 @@ namespace conversion {
template <>
struct Converter<ColorRampPropertyValue> {
optional<ColorRampPropertyValue> operator()(const Convertible& value, Error& error, bool /* allowDataExpressions */ = false, bool /* convertTokens */ = false) const;
std::optional<ColorRampPropertyValue> operator()(const Convertible& value, Error& error, bool /* allowDataExpressions */ = false, bool /* convertTokens */ = false) const;
};
} // namespace conversion

View File

@@ -16,52 +16,52 @@ namespace conversion {
template <>
struct Converter<bool> {
optional<bool> operator()(const Convertible& value, Error& error) const;
std::optional<bool> operator()(const Convertible& value, Error& error) const;
};
template <>
struct Converter<float> {
optional<float> operator()(const Convertible& value, Error& error) const;
std::optional<float> operator()(const Convertible& value, Error& error) const;
};
template <>
struct Converter<std::string> {
optional<std::string> operator()(const Convertible& value, Error& error) const;
std::optional<std::string> operator()(const Convertible& value, Error& error) const;
};
template <class T>
struct Converter<T, typename std::enable_if_t<std::is_enum_v<T>>> {
optional<T> operator()(const Convertible& value, Error& error) const;
std::optional<T> operator()(const Convertible& value, Error& error) const;
};
template <class T>
struct Converter<std::vector<T>, typename std::enable_if_t<std::is_enum_v<T>>> {
optional<std::vector<T>> operator()(const Convertible& value, Error& error) const;
std::optional<std::vector<T>> operator()(const Convertible& value, Error& error) const;
};
template <>
struct Converter<Color> {
optional<Color> operator()(const Convertible& value, Error& error) const;
std::optional<Color> operator()(const Convertible& value, Error& error) const;
};
template <size_t N>
struct Converter<std::array<float, N>> {
optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const;
std::optional<std::array<float, N>> operator()(const Convertible& value, Error& error) const;
};
template <>
struct Converter<std::vector<float>> {
optional<std::vector<float>> operator()(const Convertible& value, Error& error) const;
std::optional<std::vector<float>> operator()(const Convertible& value, Error& error) const;
};
template <size_t N>
struct Converter<std::array<double, N>> {
optional<std::array<double, N>> operator()(const Convertible& value, Error& error) const;
std::optional<std::array<double, N>> operator()(const Convertible& value, Error& error) const;
};
template <>
struct Converter<std::vector<std::string>> {
optional<std::vector<std::string>> operator()(const Convertible& value, Error& error) const;
std::optional<std::vector<std::string>> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -2,7 +2,8 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/geo.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -11,7 +12,7 @@ namespace conversion {
template<>
struct Converter<LatLng> {
public:
optional<LatLng> operator() (const Convertible& value, Error& error) const;
std::optional<LatLng> operator() (const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/sources/custom_geometry_source.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
@@ -10,7 +9,7 @@ namespace conversion {
template <>
struct Converter<CustomGeometrySource::Options> {
optional<CustomGeometrySource::Options> operator()(const Convertible& value, Error& error) const;
std::optional<CustomGeometrySource::Options> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/filter.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
@@ -11,7 +10,7 @@ namespace conversion {
template <>
struct Converter<Filter> {
public:
optional<Filter> operator()(const Convertible& value, Error& error) const;
std::optional<Filter> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -6,6 +6,8 @@
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/style/expression/value.hpp>
#include <optional>
namespace mbgl {
namespace style {
namespace conversion {
@@ -15,10 +17,10 @@ std::unique_ptr<expression::Expression> convertTokenStringToFormatExpression(con
std::unique_ptr<expression::Expression> convertTokenStringToImageExpression(const std::string&);
std::unique_ptr<expression::Expression> convertTokenStringToExpression(const std::string&);
optional<std::unique_ptr<expression::Expression>> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens);
std::optional<std::unique_ptr<expression::Expression>> convertFunctionToExpression(expression::type::Type, const Convertible&, Error&, bool convertTokens);
template <class T>
optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens);
std::optional<PropertyExpression<T>> convertFunctionToExpression(const Convertible& value, Error& error, bool convertTokens);
} // namespace conversion
} // namespace style

View File

@@ -2,19 +2,20 @@
#include <mbgl/util/geojson.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
namespace conversion {
// Workaround until https://github.com/mapbox/mapbox-gl-native/issues/5623 is done.
optional<GeoJSON> parseGeoJSON(const std::string&, Error&);
std::optional<GeoJSON> parseGeoJSON(const std::string&, Error&);
template <>
struct Converter<GeoJSON> {
public:
optional<GeoJSON> operator()(const Convertible&, Error&) const;
std::optional<GeoJSON> operator()(const Convertible&, Error&) const;
};
} // namespace conversion

View File

@@ -2,7 +2,6 @@
#include <mbgl/style/sources/geojson_source.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
namespace mbgl {
namespace style {
@@ -10,7 +9,7 @@ namespace conversion {
template <>
struct Converter<GeoJSONOptions> {
optional<GeoJSONOptions> operator()(const Convertible& value, Error& error) const;
std::optional<GeoJSONOptions> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -2,9 +2,9 @@
#include <mbgl/style/layer.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <memory>
#include <optional>
namespace mbgl {
namespace style {
@@ -13,10 +13,10 @@ namespace conversion {
template <>
struct Converter<std::unique_ptr<Layer>> {
public:
optional<std::unique_ptr<Layer>> operator()(const Convertible& value, Error& error) const;
std::optional<std::unique_ptr<Layer>> operator()(const Convertible& value, Error& error) const;
};
optional<Error> setPaintProperties(Layer& layer, const Convertible& value);
std::optional<Error> setPaintProperties(Layer& layer, const Convertible& value);
} // namespace conversion
} // namespace style

View File

@@ -2,7 +2,8 @@
#include <mbgl/style/light.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -11,7 +12,7 @@ namespace conversion {
template <>
struct Converter<Light> {
public:
optional<Light> operator()(const Convertible& value, Error& error) const;
std::optional<Light> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -2,7 +2,8 @@
#include <mbgl/style/position.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -10,7 +11,7 @@ namespace conversion {
template <>
struct Converter<Position> {
optional<Position> operator()(const Convertible& value, Error& error) const;
std::optional<Position> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -10,13 +10,15 @@
#include <mbgl/style/expression/parsing_context.hpp>
#include <mbgl/style/expression/literal.hpp>
#include <optional>
namespace mbgl {
namespace style {
namespace conversion {
template <class T>
struct Converter<PropertyValue<T>> {
optional<PropertyValue<T>> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const;
std::optional<PropertyValue<T>> operator()(const Convertible& value, Error& error, bool allowDataExpressions, bool convertTokens) const;
template <class S>
PropertyValue<T> maybeConvertTokens(const S& t) const {
@@ -49,7 +51,7 @@ struct Converter<PropertyValue<T>> {
template <>
struct Converter<PropertyValue<std::array<double, 3>>, void> {
optional<PropertyValue<std::array<double, 3>>> operator()(const Convertible& value, Error& error, bool, bool) const;
std::optional<PropertyValue<std::array<double, 3>>> operator()(const Convertible& value, Error& error, bool, bool) const;
};
} // namespace conversion
} // namespace style

View File

@@ -2,7 +2,8 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/style/rotation.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -10,7 +11,7 @@ namespace conversion {
template <>
struct Converter<style::Rotation> {
optional<style::Rotation> operator()(const Convertible& value, Error& error) const;
std::optional<style::Rotation> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -2,9 +2,9 @@
#include <mbgl/style/source.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <memory>
#include <optional>
namespace mbgl {
namespace style {
@@ -13,7 +13,7 @@ namespace conversion {
template <>
struct Converter<std::unique_ptr<Source>> {
public:
optional<std::unique_ptr<Source>> operator()(const Convertible& value, Error& error, const std::string& id) const;
std::optional<std::unique_ptr<Source>> operator()(const Convertible& value, Error& error, const std::string& id) const;
};
} // namespace conversion

View File

@@ -2,7 +2,8 @@
#include <mbgl/util/tileset.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -11,7 +12,7 @@ namespace conversion {
template <>
struct Converter<Tileset> {
public:
optional<Tileset> operator()(const Convertible& value, Error& error) const;
std::optional<Tileset> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -2,7 +2,8 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -11,7 +12,7 @@ namespace conversion {
template <>
struct Converter<TransitionOptions> {
public:
optional<TransitionOptions> operator()(const Convertible& value, Error& error) const;
std::optional<TransitionOptions> operator()(const Convertible& value, Error& error) const;
};
} // namespace conversion

View File

@@ -9,7 +9,6 @@
#include <mbgl/style/transition_options.hpp>
#include <mbgl/util/feature.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/traits.hpp>
#include <mapbox/compatibility/value.hpp>
@@ -18,6 +17,7 @@
#include <chrono>
#include <string>
#include <type_traits>
#include <optional>
namespace mbgl {
namespace style {
@@ -34,7 +34,7 @@ namespace style {
A single template function serves as the public interface:
template <class T>
optional<T> convert(const Convertible& input, Error& error);
std::optional<T> 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<Error> {...})` -- called
* `eachMember(v, [] (const std::string&, const V&) -> std::optional<Error> {...})` -- 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<Convertible> objectMember(const Convertible& v, const char * name) {
friend inline std::optional<Convertible> objectMember(const Convertible& v, const char * name) {
assert(v.vtable);
return v.vtable->objectMember(v.storage, name);
}
friend inline optional<Error> eachMember(const Convertible& v, const std::function<optional<Error> (const std::string&, const Convertible&)>& fn) {
friend inline std::optional<Error> eachMember(const Convertible& v, const std::function<std::optional<Error> (const std::string&, const Convertible&)>& fn) {
assert(v.vtable);
return v.vtable->eachMember(v.storage, fn);
}
friend inline optional<bool> toBool(const Convertible& v) {
friend inline std::optional<bool> toBool(const Convertible& v) {
assert(v.vtable);
return v.vtable->toBool(v.storage);
}
friend inline optional<float> toNumber(const Convertible& v) {
friend inline std::optional<float> toNumber(const Convertible& v) {
assert(v.vtable);
return v.vtable->toNumber(v.storage);
}
friend inline optional<double> toDouble(const Convertible& v) {
friend inline std::optional<double> toDouble(const Convertible& v) {
assert(v.vtable);
return v.vtable->toDouble(v.storage);
}
friend inline optional<std::string> toString(const Convertible& v) {
friend inline std::optional<std::string> toString(const Convertible& v) {
assert(v.vtable);
return v.vtable->toString(v.storage);
}
friend inline optional<Value> toValue(const Convertible& v) {
friend inline std::optional<Value> toValue(const Convertible& v) {
assert(v.vtable);
return v.vtable->toValue(v.storage);
}
friend inline optional<GeoJSON> toGeoJSON(const Convertible& v, Error& error) {
friend inline std::optional<GeoJSON> 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<Convertible> (*objectMember) (const Storage&, const char *);
optional<Error> (*eachMember) (const Storage&, const std::function<optional<Error> (const std::string&, const Convertible&)>&);
std::optional<Convertible> (*objectMember) (const Storage&, const char *);
std::optional<Error> (*eachMember) (const Storage&, const std::function<std::optional<Error> (const std::string&, const Convertible&)>&);
optional<bool> (*toBool) (const Storage&);
optional<float> (*toNumber) (const Storage&);
optional<double> (*toDouble) (const Storage&);
optional<std::string> (*toString) (const Storage&);
optional<Value> (*toValue) (const Storage&);
std::optional<bool> (*toBool) (const Storage&);
std::optional<float> (*toNumber) (const Storage&);
std::optional<double> (*toDouble) (const Storage&);
std::optional<std::string> (*toString) (const Storage&);
std::optional<Value> (*toValue) (const Storage&);
// https://github.com/mapbox/mapbox-gl-native/issues/5623
optional<GeoJSON> (*toGeoJSON) (const Storage&, Error&);
std::optional<GeoJSON> (*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 <typename T>
static auto vtableEachMember(const Storage& s, const std::function<optional<Error>(const std::string&, const Convertible&)>& fn) {
static auto vtableEachMember(const Storage& s, const std::function<std::optional<Error>(const std::string&, const Convertible&)>& fn) {
return ConversionTraits<T>::eachMember(reinterpret_cast<const T&>(s), [&](const std::string& k, T&& v) {
return fn(k, Convertible(std::move(v)));
});
@@ -262,11 +262,11 @@ private:
return Traits::isObject(reinterpret_cast<const T&>(s));
},
[] (const Storage& s, const char * key) {
optional<T> member = Traits::objectMember(reinterpret_cast<const T&>(s), key);
std::optional<T> member = Traits::objectMember(reinterpret_cast<const T&>(s), key);
if (member) {
return optional<Convertible>(Convertible(std::move(*member)));
return std::optional<Convertible>(Convertible(std::move(*member)));
} else {
return optional<Convertible>();
return std::optional<Convertible>();
}
},
vtableEachMember<T>,
@@ -297,7 +297,7 @@ private:
};
template <class T, class...Args>
optional<T> convert(const Convertible& value, Error& error, Args&&...args) {
std::optional<T> convert(const Convertible& value, Error& error, Args&&...args) {
return Converter<T>()(value, error, std::forward<Args>(args)...);
}

View File

@@ -22,7 +22,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override;

View File

@@ -29,8 +29,8 @@ public:
return false;
}
std::vector<optional<Value>> possibleOutputs() const override {
return { nullopt };
std::vector<std::optional<Value>> possibleOutputs() const override {
return { std::nullopt };
}
std::string getOperator() const override { return "at"; }

View File

@@ -21,7 +21,7 @@ public:
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> 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<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override { return "all"; }
private:

View File

@@ -26,7 +26,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override { return "case"; }
private:

View File

@@ -1,7 +1,6 @@
#pragma once
#include <mbgl/style/expression/type.hpp>
#include <mbgl/util/optional.hpp>
#include <memory>
namespace mbgl {
@@ -9,7 +8,7 @@ namespace style {
namespace expression {
namespace type {
optional<std::string> checkSubtype(const Type& expected, const Type& t);
std::optional<std::string> checkSubtype(const Type& expected, const Type& t);
} // namespace type
} // namespace expression

View File

@@ -28,7 +28,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::size_t getLength() const {
return args.size();

View File

@@ -23,7 +23,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override;
private:

View File

@@ -1,9 +1,9 @@
#pragma once
#include <mbgl/i18n/collator.hpp>
#include <mbgl/util/optional.hpp>
#include <string>
#include <optional>
namespace mbgl {
namespace style {
@@ -11,7 +11,7 @@ namespace expression {
class Collator {
public:
Collator(bool caseSensitive, bool diacriticSensitive, const optional<std::string>& locale = {});
Collator(bool caseSensitive, bool diacriticSensitive, const std::optional<std::string>& locale = std::nullopt);
bool operator==(const Collator& other) const;

View File

@@ -14,7 +14,7 @@ class CollatorExpression : public Expression {
public:
CollatorExpression(std::unique_ptr<Expression> caseSensitive,
std::unique_ptr<Expression> diacriticSensitive,
optional<std::unique_ptr<Expression>> locale);
std::optional<std::unique_ptr<Expression>> 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<optional<Value>> possibleOutputs() const override {
std::vector<std::optional<Value>> 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<Expression> caseSensitive;
std::unique_ptr<Expression> diacriticSensitive;
optional<std::unique_ptr<Expression>> locale;
std::optional<std::unique_ptr<Expression>> locale;
};
} // namespace expression

View File

@@ -25,7 +25,7 @@ public:
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression&) const override;
EvaluationResult evaluate(const EvaluationContext&) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override;
private:
@@ -49,7 +49,7 @@ public:
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression&) const override;
EvaluationResult evaluate(const EvaluationContext&) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override;
private:

View File

@@ -5,10 +5,10 @@
#include <mbgl/style/expression/type.hpp>
#include <mbgl/style/expression/value.hpp>
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/optional.hpp>
#include <memory>
#include <vector>
#include <optional>
namespace mbgl {
namespace style {
@@ -33,11 +33,11 @@ public:
std::string getOperator() const override;
EvaluationResult evaluate(const EvaluationContext& evaluationParams) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
optional<std::size_t> getParameterCount() const;
std::optional<std::size_t> getParameterCount() const;
static bool exists(const std::string& name);

View File

@@ -33,7 +33,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override;

View File

@@ -24,7 +24,7 @@ public:
return EvaluationError{message};
}
std::vector<optional<Value>> possibleOutputs() const override {
std::vector<std::optional<Value>> possibleOutputs() const override {
return {};
}

View File

@@ -5,12 +5,12 @@
#include <mbgl/style/expression/value.hpp>
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/optional.hpp>
#include <mbgl/util/variant.hpp>
#include <array>
#include <vector>
#include <memory>
#include <optional>
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<mbgl::Value> accumulated_, GeometryTileFeature const * feature_) :
EvaluationContext(std::optional<mbgl::Value> 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<float> zoom_, GeometryTileFeature const * feature_, optional<double> colorRampParameter_) :
EvaluationContext(std::optional<float> zoom_, GeometryTileFeature const * feature_, std::optional<double> colorRampParameter_) :
zoom(std::move(zoom_)), feature(feature_), colorRampParameter(std::move(colorRampParameter_))
{}
@@ -59,10 +59,10 @@ public:
return *this;
};
optional<float> zoom;
optional<mbgl::Value> accumulated;
std::optional<float> zoom;
std::optional<mbgl::Value> accumulated;
GeometryTileFeature const* feature = nullptr;
optional<double> colorRampParameter;
std::optional<double> colorRampParameter;
// Contains formatted section object, std::unordered_map<std::string, Value>.
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<float> zoom, const Feature& feature, optional<double> colorRampParameter) const;
EvaluationResult evaluate(optional<float> zoom,
EvaluationResult evaluate(std::optional<float> zoom, const Feature& feature, std::optional<double> colorRampParameter) const;
EvaluationResult evaluate(std::optional<float> zoom,
const Feature& feature,
optional<double> colorRampParameter,
std::optional<double> colorRampParameter,
const std::set<std::string>& availableImages) const;
EvaluationResult evaluate(optional<float> zoom,
EvaluationResult evaluate(std::optional<float> zoom,
const Feature& feature,
optional<double> colorRampParameter,
std::optional<double> colorRampParameter,
const std::set<std::string>& availableImages,
const CanonicalTileID& canonical) const;
EvaluationResult evaluate(optional<mbgl::Value> accumulated, const Feature& feature) const;
EvaluationResult evaluate(std::optional<mbgl::Value> 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<optional<Value>> possibleOutputs() const = 0;
virtual std::vector<std::optional<Value>> possibleOutputs() const = 0;
virtual mbgl::Value serialize() const {
std::vector<mbgl::Value> serialized;

View File

@@ -5,13 +5,14 @@
#include <mbgl/style/expression/step.hpp>
#include <mbgl/util/variant.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
namespace expression {
optional<variant<const Interpolate*, const Step*, ParsingError>> findZoomCurve(const expression::Expression* e);
std::optional<variant<const Interpolate*, const Step*, ParsingError>> findZoomCurve(const expression::Expression* e);
variant<std::nullptr_t, const Interpolate*, const Step*> findZoomCurveChecked(const expression::Expression* e);

View File

@@ -10,17 +10,17 @@ namespace expression {
struct FormatExpressionSection {
explicit FormatExpressionSection(std::unique_ptr<Expression> content_);
void setTextSectionOptions(optional<std::unique_ptr<Expression>> fontScale_,
optional<std::unique_ptr<Expression>> textFont_,
optional<std::unique_ptr<Expression>> textColor_);
void setTextSectionOptions(std::optional<std::unique_ptr<Expression>> fontScale_,
std::optional<std::unique_ptr<Expression>> textFont_,
std::optional<std::unique_ptr<Expression>> textColor_);
// Content can be expression that evaluates to String or Image.
std::shared_ptr<Expression> content;
// Text related section options.
optional<std::shared_ptr<Expression>> fontScale;
optional<std::shared_ptr<Expression>> textFont;
optional<std::shared_ptr<Expression>> textColor;
std::optional<std::shared_ptr<Expression>> fontScale;
std::optional<std::shared_ptr<Expression>> textFont;
std::optional<std::shared_ptr<Expression>> textColor;
};
class FormatExpression final : public Expression {
@@ -34,10 +34,10 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override {
std::vector<std::optional<Value>> 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<FormatExpressionSection>& getSections() const { return sections; }

View File

@@ -70,8 +70,8 @@ public:
return false;
}
std::vector<optional<Value>> possibleOutputs() const final {
return {nullopt};
std::vector<std::optional<Value>> possibleOutputs() const final {
return {std::nullopt};
}
std::string getOperator() const final { return "format-section-override"; }

View File

@@ -4,10 +4,10 @@
#include <mbgl/style/expression/image.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/font_stack.hpp>
#include <mbgl/util/optional.hpp>
#include <vector>
#include <string>
#include <optional>
namespace mbgl {
namespace style {
@@ -19,9 +19,9 @@ extern const char* const kFormattedSectionTextColor;
struct FormattedSection {
explicit FormattedSection(std::string text_,
optional<double> fontScale_,
optional<FontStack> fontStack_,
optional<Color> textColor_)
std::optional<double> fontScale_,
std::optional<FontStack> fontStack_,
std::optional<Color> 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> image;
optional<double> fontScale;
optional<FontStack> fontStack;
optional<Color> textColor;
std::optional<Image> image;
std::optional<double> fontScale;
std::optional<FontStack> fontStack;
std::optional<Color> 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<FormattedSection> sections_)
@@ -65,7 +65,7 @@ namespace conversion {
template <>
struct Converter<expression::Formatted> {
public:
optional<expression::Formatted> operator()(const Convertible& value, Error& error) const;
std::optional<expression::Formatted> operator()(const Convertible& value, Error& error) const;
};
template <>

View File

@@ -2,10 +2,10 @@
#include <mbgl/style/conversion.hpp>
#include <mbgl/util/color.hpp>
#include <mbgl/util/optional.hpp>
#include <string>
#include <vector>
#include <optional>
namespace mbgl {
namespace style {
@@ -35,7 +35,7 @@ namespace conversion {
template <>
struct Converter<expression::Image> {
public:
optional<expression::Image> operator()(const Convertible& value, Error& error) const;
std::optional<expression::Image> operator()(const Convertible& value, Error& error) const;
};
template <>

View File

@@ -19,7 +19,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override { return {nullopt}; }
std::vector<std::optional<Value>> possibleOutputs() const override { return {std::nullopt}; }
mbgl::Value serialize() const override;
std::string getOperator() const override { return "image"; }

View File

@@ -19,7 +19,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override;

View File

@@ -9,6 +9,7 @@
#include <memory>
#include <map>
#include <cmath>
#include <optional>
namespace mbgl {
namespace style {
@@ -65,7 +66,7 @@ public:
return false;
}
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override { return "interpolate"; }

View File

@@ -20,7 +20,7 @@ public:
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
std::string getOperator() const override { return "length"; }
private:

View File

@@ -6,6 +6,7 @@
#include <memory>
#include <map>
#include <optional>
namespace mbgl {
namespace style {
@@ -34,7 +35,7 @@ public:
return false;
}
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
Expression* getResult() const {
return result.get();
@@ -65,7 +66,7 @@ public:
return false;
}
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override { return "var"; }

View File

@@ -33,7 +33,7 @@ public:
return false;
}
std::vector<optional<Value>> possibleOutputs() const override {
std::vector<std::optional<Value>> possibleOutputs() const override {
return {{ value }};
}

View File

@@ -30,7 +30,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override { return "match"; }

View File

@@ -22,7 +22,7 @@ public:
EvaluationResult evaluate(const EvaluationContext& params) const override;
void eachChild(const std::function<void(const Expression&)>& visit) const override;
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override { return "number-format"; }

View File

@@ -1,6 +1,5 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/style/expression/type.hpp>
#include <mbgl/style/conversion.hpp>
@@ -12,6 +11,7 @@
#include <unordered_map>
#include <utility>
#include <vector>
#include <optional>
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<std::unique_ptr<Expression>>;
using ParseResult = std::optional<std::unique_ptr<Expression>>;
namespace detail {
@@ -39,14 +39,14 @@ public:
const std::map<std::string, std::shared_ptr<Expression>>& bindings;
std::shared_ptr<Scope> parent;
optional<std::shared_ptr<Expression>> get(const std::string& name) {
std::optional<std::shared_ptr<Expression>> 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<std::shared_ptr<Expression>>();
return std::optional<std::shared_ptr<Expression>>();
}
}
};
@@ -86,7 +86,7 @@ public:
ParsingContext& operator=(const ParsingContext&) = delete;
std::string getKey() const { return key; }
optional<type::Type> getExpected() const { return expected; }
std::optional<type::Type> getExpected() const { return expected; }
const std::vector<ParsingError>& 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<TypeAnnotationOption>& = {});
const std::optional<TypeAnnotationOption>& = 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<type::Type> = {},
const optional<TypeAnnotationOption>& = {});
std::optional<type::Type> = std::nullopt,
const std::optional<TypeAnnotationOption>& = 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<type::Type>,
std::optional<type::Type>,
const std::map<std::string, std::shared_ptr<Expression>>&);
/**
Check whether `t` is a subtype of `expected`, collecting an error if not.
*/
optional<std::string> checkType(const type::Type& t);
std::optional<std::string> checkType(const type::Type& t);
optional<std::shared_ptr<Expression>> getBinding(const std::string& name) {
if (!scope) return optional<std::shared_ptr<Expression>>();
std::optional<std::shared_ptr<Expression>> getBinding(const std::string& name) {
if (!scope) return std::optional<std::shared_ptr<Expression>>();
return scope->get(name);
}
@@ -153,7 +153,7 @@ public:
private:
ParsingContext(std::string key_,
std::shared_ptr<std::vector<ParsingError>> errors_,
optional<type::Type> expected_,
std::optional<type::Type> expected_,
std::shared_ptr<detail::Scope> 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<TypeAnnotationOption>& = {});
ParseResult parse(const mbgl::style::conversion::Convertible& value, const std::optional<TypeAnnotationOption>& = std::nullopt);
std::string key;
optional<type::Type> expected;
std::optional<type::Type> expected;
std::shared_ptr<detail::Scope> scope;
std::shared_ptr<std::vector<ParsingError>> errors;
};

View File

@@ -8,6 +8,7 @@
#include <memory>
#include <map>
#include <optional>
namespace mbgl {
namespace style {
@@ -28,7 +29,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
static ParseResult parse(const mbgl::style::conversion::Convertible& value, ParsingContext& ctx);

View File

@@ -1,10 +1,11 @@
#pragma once
#include <mbgl/util/optional.hpp>
#include <mbgl/util/string.hpp>
#include <mbgl/util/variant.hpp>
#include <vector>
#include <optional>
namespace mbgl {
namespace style {
namespace expression {
@@ -109,7 +110,7 @@ using Type = variant<NullType,
struct Array {
explicit Array(Type itemType_) : itemType(std::move(itemType_)) {}
Array(Type itemType_, std::size_t N_) : itemType(std::move(itemType_)), N(N_) {}
Array(Type itemType_, optional<std::size_t> N_) : itemType(std::move(itemType_)), N(std::move(N_)) {}
Array(Type itemType_, std::optional<std::size_t> 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<std::size_t> N;
std::optional<std::size_t> N;
};
template <class T>

View File

@@ -14,6 +14,7 @@
#include <array>
#include <vector>
#include <optional>
namespace mbgl {
namespace style {
@@ -77,8 +78,8 @@ struct ValueConverter {
return Value(value);
}
static optional<T> fromExpressionValue(const Value& value) {
return value.template is<T>() ? value.template get<T>() : optional<T>();
static std::optional<T> fromExpressionValue(const Value& value) {
return value.template is<T>() ? value.template get<T>() : std::optional<T>();
}
};
@@ -86,7 +87,7 @@ template <>
struct ValueConverter<Value> {
static type::Type expressionType() { return type::Value; }
static Value toExpressionValue(const Value& value) { return value; }
static optional<Value> fromExpressionValue(const Value& value) { return value; }
static std::optional<Value> fromExpressionValue(const Value& value) { return value; }
};
template <>
@@ -99,7 +100,7 @@ template <>
struct ValueConverter<float> {
static type::Type expressionType() { return type::Number; }
static Value toExpressionValue(float value);
static optional<float> fromExpressionValue(const Value& value);
static std::optional<float> fromExpressionValue(const Value& value);
};
template <typename T, std::size_t N>
@@ -108,7 +109,7 @@ struct ValueConverter<std::array<T, N>> {
return type::Array(valueTypeToExpressionType<T>(), N);
}
static Value toExpressionValue(const std::array<T, N>& value);
static optional<std::array<T, N>> fromExpressionValue(const Value& value);
static std::optional<std::array<T, N>> fromExpressionValue(const Value& value);
};
template <typename T>
@@ -117,21 +118,21 @@ struct ValueConverter<std::vector<T>> {
return type::Array(valueTypeToExpressionType<T>());
}
static Value toExpressionValue(const std::vector<T>& value);
static optional<std::vector<T>> fromExpressionValue(const Value& value);
static std::optional<std::vector<T>> fromExpressionValue(const Value& value);
};
template <>
struct ValueConverter<Position> {
static type::Type expressionType() { return type::Array(type::Number, 3); }
static Value toExpressionValue(const mbgl::style::Position& value);
static optional<Position> fromExpressionValue(const Value& v);
static std::optional<Position> fromExpressionValue(const Value& v);
};
template <typename T>
struct ValueConverter<T, std::enable_if_t< std::is_enum_v<T> >> {
static type::Type expressionType() { return type::String; }
static Value toExpressionValue(const T& value);
static optional<T> fromExpressionValue(const Value& value);
static std::optional<T> fromExpressionValue(const Value& value);
};
template <typename T>
@@ -140,16 +141,16 @@ Value toExpressionValue(const T& value) {
}
template <typename T>
optional<T> fromExpressionValue(const Value& value) {
std::optional<T> fromExpressionValue(const Value& value) {
return ValueConverter<T>::fromExpressionValue(value);
}
template <typename T>
std::vector<optional<T>> fromExpressionValues(const std::vector<optional<Value>>& values) {
std::vector<optional<T>> result;
std::vector<std::optional<T>> fromExpressionValues(const std::vector<std::optional<Value>>& values) {
std::vector<std::optional<T>> result;
result.reserve(values.size());
for (const auto& value : values) {
result.push_back(value ? fromExpressionValue<T>(*value) : nullopt);
result.push_back(value ? fromExpressionValue<T>(*value) : std::nullopt);
}
return result;
}
@@ -158,7 +159,7 @@ template <>
struct ValueConverter<Rotation> {
static type::Type expressionType() { return type::Number; }
static Value toExpressionValue(const mbgl::style::Rotation& value);
static optional<Rotation> fromExpressionValue(const Value& v);
static std::optional<Rotation> fromExpressionValue(const Value& v);
};
} // namespace expression

View File

@@ -2,7 +2,8 @@
#include <mbgl/style/expression/expression.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -22,7 +23,7 @@ public:
bool operator==(const Expression& e) const override;
std::vector<optional<Value>> possibleOutputs() const override;
std::vector<std::optional<Value>> possibleOutputs() const override;
mbgl::Value serialize() const override;
std::string getOperator() const override;

View File

@@ -8,19 +8,20 @@
#include <string>
#include <vector>
#include <tuple>
#include <optional>
namespace mbgl {
namespace style {
class Filter {
public:
optional<std::shared_ptr<const expression::Expression>> expression;
std::optional<std::shared_ptr<const expression::Expression>> expression;
private:
optional<mbgl::Value> legacyFilter;
std::optional<mbgl::Value> legacyFilter;
public:
Filter() = default;
Filter(expression::ParseResult _expression, optional<mbgl::Value> _filter = {})
Filter(expression::ParseResult _expression, std::optional<mbgl::Value> _filter = std::nullopt)
: expression(std::move(*_expression)),
legacyFilter(std::move(_filter)){
assert(!expression || *expression != nullptr);

View File

@@ -2,11 +2,11 @@
#include <mbgl/util/image.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/util/optional.hpp>
#include <string>
#include <utility>
#include <vector>
#include <optional>
namespace mbgl {
namespace style {
@@ -34,13 +34,13 @@ public:
bool sdf,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
const optional<ImageContent>& content = nullopt);
const std::optional<ImageContent>& content = std::nullopt);
Image(std::string id,
PremultipliedImage&& image,
float pixelRatio,
ImageStretches stretchX = {},
ImageStretches stretchY = {},
const optional<ImageContent>& content = nullopt)
const std::optional<ImageContent>& 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<ImageContent>& getContent() const;
const std::optional<ImageContent>& getContent() const;
class Impl;
Immutable<Impl> baseImpl;

View File

@@ -4,7 +4,6 @@
#include <mbgl/style/style_property.hpp>
#include <mbgl/style/types.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/util/optional.hpp>
#include <mapbox/std/weak.hpp>
#include <mapbox/util/type_wrapper.hpp>
@@ -13,6 +12,7 @@
#include <memory>
#include <string>
#include <stdexcept>
#include <optional>
namespace mbgl {
namespace style {
@@ -111,7 +111,7 @@ public:
void setMaxZoom(float);
// Dynamic properties
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
std::optional<conversion::Error> 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<Impl> mutableBaseImpl() const = 0;
void serializeProperty(Value&, const StyleProperty&, const char* propertyName, bool isPaint) const;
virtual optional<conversion::Error> setPropertyInternal(const std::string& name,
virtual std::optional<conversion::Error> setPropertyInternal(const std::string& name,
const conversion::Convertible& value) = 0;
LayerObserver* observer;
mapbox::base::WeakPtrFactory<Layer> weakFactory {this};
private:
optional<conversion::Error> setVisibility(const conversion::Convertible& value);
optional<conversion::Error> setMinZoom(const conversion::Convertible& value);
optional<conversion::Error> setMaxZoom(const conversion::Convertible& value);
std::optional<conversion::Error> setVisibility(const conversion::Convertible& value);
std::optional<conversion::Error> setMinZoom(const conversion::Convertible& value);
std::optional<conversion::Error> setMaxZoom(const conversion::Convertible& value);
};
} // namespace style

View File

@@ -50,7 +50,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -104,7 +104,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -80,7 +80,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -80,7 +80,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -63,7 +63,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -68,7 +68,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -72,7 +72,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -123,7 +123,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -107,7 +107,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -80,7 +80,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -285,7 +285,7 @@ public:
protected:
// Dynamic properties
optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
std::optional<conversion::Error> setPropertyInternal(const std::string& name, const conversion::Convertible& value) final;
StyleProperty getProperty(const std::string& name) const final;
Value serialize() const final;

View File

@@ -22,7 +22,7 @@ public:
~Light();
// Dynamic properties
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
std::optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
StyleProperty getProperty(const std::string&) const;
static LightAnchorType getDefaultAnchor();

View File

@@ -25,7 +25,7 @@ public:
~Light();
// Dynamic properties
optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
std::optional<conversion::Error> setProperty(const std::string& name, const conversion::Convertible& value);
StyleProperty getProperty(const std::string&) const;
<% for (const property of properties) { -%>

View File

@@ -7,6 +7,8 @@
#include <mbgl/style/expression/find_zoom_curve.hpp>
#include <mbgl/util/range.hpp>
#include <optional>
namespace mbgl {
namespace style {
@@ -40,7 +42,7 @@ template <class T>
class PropertyExpression final : public PropertyExpressionBase {
public:
// Second parameter to be used only for conversions from legacy functions.
PropertyExpression(std::unique_ptr<expression::Expression> expression_, optional<T> defaultValue_ = nullopt)
PropertyExpression(std::unique_ptr<expression::Expression> expression_, std::optional<T> 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<T> typed = expression::fromExpressionValue<T>(*result);
const std::optional<T> typed = expression::fromExpressionValue<T>(*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<optional<T>> possibleOutputs() const {
std::vector<std::optional<T>> possibleOutputs() const {
return expression::fromExpressionValues<T>(expression->possibleOutputs());
}
@@ -133,7 +135,7 @@ public:
}
private:
optional<T> defaultValue;
std::optional<T> defaultValue;
};
} // namespace style

View File

@@ -3,13 +3,13 @@
#include <mbgl/style/types.hpp>
#include <mbgl/util/chrono.hpp>
#include <mbgl/util/immutable.hpp>
#include <mbgl/util/optional.hpp>
#include <mapbox/std/weak.hpp>
#include <mapbox/util/type_wrapper.hpp>
#include <memory>
#include <string>
#include <optional>
namespace mbgl {
@@ -64,7 +64,7 @@ public:
SourceType getType() const;
std::string getID() const;
optional<std::string> getAttribution() const;
std::optional<std::string> 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<uint8_t> delta) noexcept;
optional<uint8_t> getPrefetchZoomDelta() const noexcept;
void setPrefetchZoomDelta(std::optional<uint8_t> delta) noexcept;
std::optional<uint8_t> 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<uint8_t> overscaleFactor) noexcept;
optional<uint8_t> getMaxOverscaleFactorForParentTiles() const noexcept;
void setMaxOverscaleFactorForParentTiles(std::optional<uint8_t> overscaleFactor) noexcept;
std::optional<uint8_t> getMaxOverscaleFactorForParentTiles() const noexcept;
void dumpDebugLogs() const;
virtual bool supportsLayerType(const mbgl::style::LayerTypeInfo*) const = 0;

View File

@@ -5,7 +5,6 @@
#include <mbgl/tile/tile_id.hpp>
#include <mbgl/util/constants.hpp>
#include <mbgl/util/geojson.hpp>
#include <mbgl/util/optional.hpp>
#include <map>
#include <memory>
@@ -65,7 +64,7 @@ public:
void setGeoJSON(const GeoJSON&);
void setGeoJSONData(std::shared_ptr<GeoJSONData>);
optional<std::string> getURL() const;
std::optional<std::string> getURL() const;
const GeoJSONOptions& getOptions() const;
class Impl;
@@ -83,7 +82,7 @@ protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
optional<std::string> url;
std::optional<std::string> url;
std::unique_ptr<AsyncRequest> req;
std::shared_ptr<Scheduler> threadPool;
mapbox::base::WeakPtrFactory<Source> weakFactory {this};

View File

@@ -2,7 +2,8 @@
#include <mbgl/style/source.hpp>
#include <mbgl/util/image.hpp>
#include <mbgl/util/optional.hpp>
#include <optional>
namespace mbgl {
class LatLng;
@@ -15,7 +16,7 @@ public:
ImageSource(std::string id, std::array<LatLng, 4>);
~ImageSource() override;
optional<std::string> getURL() const;
std::optional<std::string> getURL() const;
void setURL(const std::string& url);
void setImage(PremultipliedImage&&);
@@ -38,7 +39,7 @@ protected:
Mutable<Source::Impl> createMutable() const noexcept final;
private:
optional<std::string> url;
std::optional<std::string> url;
std::unique_ptr<AsyncRequest> req;
mapbox::base::WeakPtrFactory<Source> weakFactory {this};
};

View File

@@ -16,7 +16,7 @@ public:
~RasterSource() override;
const variant<std::string, Tileset>& getURLOrTileset() const;
optional<std::string> getURL() const;
std::optional<std::string> getURL() const;
uint16_t getTileSize() const;

View File

@@ -12,12 +12,12 @@ namespace style {
class VectorSource final : public Source {
public:
VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset, optional<float> maxZoom = nullopt,
optional<float> minZoom = nullopt);
VectorSource(std::string id, variant<std::string, Tileset> urlOrTileset, std::optional<float> maxZoom = std::nullopt,
std::optional<float> minZoom = std::nullopt);
~VectorSource() final;
const variant<std::string, Tileset>& getURLOrTileset() const;
optional<std::string> getURL() const;
std::optional<std::string> getURL() const;
class Impl;
const Impl& impl() const;
@@ -37,8 +37,8 @@ private:
const variant<std::string, Tileset> urlOrTileset;
std::unique_ptr<AsyncRequest> req;
mapbox::base::WeakPtrFactory<Source> weakFactory {this};
optional<float> maxZoom;
optional<float> minZoom;
std::optional<float> maxZoom;
std::optional<float> minZoom;
};
template <>

Some files were not shown because too many files have changed in this diff Show More