Use std::optional instead of mbgl::optional (#911)
This commit is contained in:
@@ -4,11 +4,11 @@
|
||||
|
||||
#include <mbgl/util/feature.hpp>
|
||||
#include <mbgl/util/logging.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
#include <mbgl/style/conversion/geojson.hpp>
|
||||
#include <mbgl/style/conversion_impl.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
#include <optional>
|
||||
|
||||
namespace mbgl {
|
||||
namespace style {
|
||||
@@ -37,7 +37,7 @@ public:
|
||||
return value.get(i);
|
||||
}
|
||||
|
||||
static optional<mbgl::android::Value> objectMember(const mbgl::android::Value& value, const char* key) {
|
||||
static std::optional<mbgl::android::Value> objectMember(const mbgl::android::Value& value, const char* key) {
|
||||
mbgl::android::Value member = value.get(key);
|
||||
if (!member.isNull()) {
|
||||
return member;
|
||||
@@ -47,14 +47,14 @@ public:
|
||||
}
|
||||
|
||||
template <class Fn>
|
||||
static optional<Error> eachMember(const mbgl::android::Value& value, Fn&& fn) {
|
||||
static std::optional<Error> eachMember(const mbgl::android::Value& value, Fn&& fn) {
|
||||
assert(value.isObject());
|
||||
mbgl::android::Value keys = value.keyArray();
|
||||
std::size_t length = arrayLength(keys);
|
||||
for(std::size_t i = 0; i < length; ++i){
|
||||
const auto k = keys.get(i).toString();
|
||||
auto v = value.get(k.c_str());
|
||||
optional<Error> result = fn(k, std::move(v));
|
||||
std::optional<Error> result = fn(k, std::move(v));
|
||||
if (result) {
|
||||
return result;
|
||||
}
|
||||
@@ -62,7 +62,7 @@ public:
|
||||
return {};
|
||||
}
|
||||
|
||||
static optional<bool> toBool(const mbgl::android::Value& value) {
|
||||
static std::optional<bool> toBool(const mbgl::android::Value& value) {
|
||||
if (value.isBool()) {
|
||||
return value.toBool();
|
||||
} else {
|
||||
@@ -70,7 +70,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static optional<float> toNumber(const mbgl::android::Value& value) {
|
||||
static std::optional<float> toNumber(const mbgl::android::Value& value) {
|
||||
if (value.isNumber()) {
|
||||
auto num = value.toFloat();
|
||||
return num;
|
||||
@@ -79,7 +79,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static optional<double> toDouble(const mbgl::android::Value& value) {
|
||||
static std::optional<double> toDouble(const mbgl::android::Value& value) {
|
||||
if (value.isNumber()) {
|
||||
return value.toDouble();
|
||||
} else {
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static optional<std::string> toString(const mbgl::android::Value& value) {
|
||||
static std::optional<std::string> toString(const mbgl::android::Value& value) {
|
||||
if (value.isString()) {
|
||||
return value.toString();
|
||||
} else {
|
||||
@@ -95,7 +95,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static optional<Value> toValue(const mbgl::android::Value& value) {
|
||||
static std::optional<Value> toValue(const mbgl::android::Value& value) {
|
||||
if (value.isNull()) {
|
||||
return {};
|
||||
} else if (value.isBool()) {
|
||||
@@ -109,7 +109,7 @@ public:
|
||||
}
|
||||
}
|
||||
|
||||
static optional<GeoJSON> toGeoJSON(const mbgl::android::Value &value, Error &error) {
|
||||
static std::optional<GeoJSON> toGeoJSON(const mbgl::android::Value &value, Error &error) {
|
||||
if (value.isNull()) {
|
||||
error = { "no json data found" };
|
||||
return {};
|
||||
@@ -139,7 +139,7 @@ public:
|
||||
};
|
||||
|
||||
template <class T, class...Args>
|
||||
optional<T> convert(mbgl::android::Value&& value, Error& error, Args&&...args) {
|
||||
std::optional<T> convert(mbgl::android::Value&& value, Error& error, Args&&...args) {
|
||||
return convert<T>(Convertible(std::move(value)), error, std::forward<Args>(args)...);
|
||||
}
|
||||
|
||||
|
||||
@@ -8,8 +8,8 @@ namespace mbgl {
|
||||
namespace android {
|
||||
namespace conversion {
|
||||
|
||||
optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, const jni::Array<jni::Object<>>& jfilter) {
|
||||
mbgl::optional<mbgl::style::Filter> filter;
|
||||
std::optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, const jni::Array<jni::Object<>>& jfilter) {
|
||||
std::optional<mbgl::style::Filter> filter;
|
||||
if (jfilter) {
|
||||
mbgl::style::conversion::Error error;
|
||||
auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(Value(env, jfilter), error);
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <mbgl/style/filter.hpp>
|
||||
#include <mbgl/util/optional.hpp>
|
||||
|
||||
#include <jni/jni.hpp>
|
||||
|
||||
@@ -9,7 +8,7 @@ namespace mbgl {
|
||||
namespace android {
|
||||
namespace conversion {
|
||||
|
||||
optional<mbgl::style::Filter> toFilter(jni::JNIEnv&, const jni::Array<jni::Object<>>&);
|
||||
std::optional<mbgl::style::Filter> toFilter(jni::JNIEnv&, const jni::Array<jni::Object<>>&);
|
||||
|
||||
} // namespace conversion
|
||||
} // namespace android
|
||||
|
||||
@@ -16,7 +16,7 @@ variant<std::string, Tileset> convertURLOrTileset(mbgl::android::Value&& value)
|
||||
const Convertible convertible(std::move(value));
|
||||
if (isObject(convertible)) {
|
||||
Error error;
|
||||
optional<Tileset> tileset = convert<Tileset>(convertible, error);
|
||||
std::optional<Tileset> tileset = convert<Tileset>(convertible, error);
|
||||
if (!tileset) {
|
||||
throw std::logic_error(error.message);
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ namespace android {
|
||||
Layer::~Layer() {
|
||||
}
|
||||
|
||||
void Layer::addToStyle(mbgl::style::Style& style, mbgl::optional<std::string> before) {
|
||||
void Layer::addToStyle(mbgl::style::Style& style, std::optional<std::string> before) {
|
||||
// Check to see if we own the layer first
|
||||
if (!ownedLayer) {
|
||||
throw std::runtime_error("Cannot add layer twice");
|
||||
@@ -69,7 +69,7 @@ namespace android {
|
||||
|
||||
void Layer::setProperty(jni::JNIEnv& env, const jni::String& jname, const jni::Object<>& jvalue) {
|
||||
// Convert and set property
|
||||
optional<mbgl::style::conversion::Error> error =
|
||||
std::optional<mbgl::style::conversion::Error> error =
|
||||
layer.setProperty(jni::Make<std::string>(env, jname), Value(env, jvalue));
|
||||
if (error) {
|
||||
mbgl::Log::Error(mbgl::Event::JNI, "Error setting property: " + jni::Make<std::string>(env, jname) + " " + error->message);
|
||||
@@ -82,7 +82,7 @@ namespace android {
|
||||
using namespace mbgl::style::conversion;
|
||||
|
||||
Error error;
|
||||
optional<Filter> converted = convert<Filter>(Value(env, jfilter), error);
|
||||
std::optional<Filter> converted = convert<Filter>(Value(env, jfilter), error);
|
||||
if (!converted) {
|
||||
mbgl::Log::Error(mbgl::Event::JNI, "Error setting filter: " + error.message);
|
||||
return;
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
*/
|
||||
void setLayer(std::unique_ptr<mbgl::style::Layer>);
|
||||
|
||||
void addToStyle(mbgl::style::Style&, mbgl::optional<std::string>);
|
||||
void addToStyle(mbgl::style::Style&, std::optional<std::string>);
|
||||
|
||||
// Release the owned view and return it
|
||||
std::unique_ptr<mbgl::style::Layer> releaseCoreLayer();
|
||||
|
||||
@@ -30,7 +30,7 @@ namespace android {
|
||||
return style::CustomGeometrySource::Options();
|
||||
}
|
||||
Error error;
|
||||
optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, options), error);
|
||||
std::optional<style::CustomGeometrySource::Options> result = convert<style::CustomGeometrySource::Options>(Value(env, options), error);
|
||||
if (!result) {
|
||||
throw std::logic_error(error.message);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ static Immutable<style::GeoJSONOptions> convertGeoJSONOptions(jni::JNIEnv& env,
|
||||
return style::GeoJSONOptions::defaultOptions();
|
||||
}
|
||||
Error error;
|
||||
optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>(mbgl::android::Value(env, options), error);
|
||||
std::optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>(mbgl::android::Value(env, options), error);
|
||||
if (!result) {
|
||||
throw std::logic_error(error.message);
|
||||
}
|
||||
@@ -85,7 +85,7 @@ void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, const jni::String& jStrin
|
||||
}
|
||||
|
||||
jni::Local<jni::String> GeoJSONSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<style::GeoJSONSource>()->getURL();
|
||||
std::optional<std::string> url = source.as<style::GeoJSONSource>()->getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
@@ -231,7 +231,7 @@ void GeoJSONSource::setGeoJSONString(jni::JNIEnv& env, const jni::String& jStrin
|
||||
android::UniqueEnv _env = android::AttachEnv();
|
||||
// Convert the jni object
|
||||
Error error;
|
||||
optional<GeoJSON> converted = parseGeoJSON(*json, error);
|
||||
std::optional<GeoJSON> converted = parseGeoJSON(*json, error);
|
||||
if(!converted) {
|
||||
mbgl::Log::Error(mbgl::Event::JNI, "Error setting geo json: " + error.message);
|
||||
return;
|
||||
|
||||
@@ -34,7 +34,7 @@ namespace android {
|
||||
}
|
||||
|
||||
jni::Local<jni::String> ImageSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::ImageSource>()->ImageSource::getURL();
|
||||
std::optional<std::string> url = source.as<mbgl::style::ImageSource>()->ImageSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace android {
|
||||
RasterDEMSource::~RasterDEMSource() = default;
|
||||
|
||||
jni::Local<jni::String> RasterDEMSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::RasterDEMSource>()->RasterDEMSource::getURL();
|
||||
std::optional<std::string> url = source.as<mbgl::style::RasterDEMSource>()->RasterDEMSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ namespace android {
|
||||
RasterSource::~RasterSource() = default;
|
||||
|
||||
jni::Local<jni::String> RasterSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::RasterSource>()->RasterSource::getURL();
|
||||
std::optional<std::string> url = source.as<mbgl::style::RasterSource>()->RasterSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
|
||||
@@ -108,7 +108,7 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
|
||||
|
||||
void Source::setPrefetchZoomDelta(jni::JNIEnv& env, jni::Integer& delta) {
|
||||
if (!delta) {
|
||||
source.setPrefetchZoomDelta(nullopt);
|
||||
source.setPrefetchZoomDelta(std::nullopt);
|
||||
} else {
|
||||
source.setPrefetchZoomDelta(jni::Unbox(env, delta));
|
||||
}
|
||||
@@ -124,7 +124,7 @@ static std::unique_ptr<Source> createSourcePeer(jni::JNIEnv& env,
|
||||
|
||||
void Source::setMaxOverscaleFactorForParentTiles(jni::JNIEnv& env, jni::Integer& maxOverscaleFactor) {
|
||||
if (!maxOverscaleFactor) {
|
||||
source.setMaxOverscaleFactorForParentTiles(nullopt);
|
||||
source.setMaxOverscaleFactorForParentTiles(std::nullopt);
|
||||
} else {
|
||||
source.setMaxOverscaleFactorForParentTiles(jni::Unbox(env, maxOverscaleFactor));
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ namespace android {
|
||||
VectorSource::~VectorSource() = default;
|
||||
|
||||
jni::Local<jni::String> VectorSource::getURL(jni::JNIEnv& env) {
|
||||
optional<std::string> url = source.as<mbgl::style::VectorSource>()->VectorSource::getURL();
|
||||
std::optional<std::string> url = source.as<mbgl::style::VectorSource>()->VectorSource::getURL();
|
||||
return url ? jni::Make<jni::String>(env, *url) : jni::Local<jni::String>();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user