diff options
Diffstat (limited to 'platform/android')
-rw-r--r-- | platform/android/config.cmake | 1 | ||||
-rw-r--r-- | platform/android/src/style/android_conversion.hpp | 147 | ||||
-rw-r--r-- | platform/android/src/style/conversion/filter.hpp | 3 | ||||
-rw-r--r-- | platform/android/src/style/conversion/geojson.hpp | 24 | ||||
-rw-r--r-- | platform/android/src/style/conversion/url_or_tileset.hpp | 9 | ||||
-rw-r--r-- | platform/android/src/style/layers/layer.cpp | 21 | ||||
-rw-r--r-- | platform/android/src/style/sources/geojson_source.cpp | 10 | ||||
-rw-r--r-- | platform/android/src/style/value.cpp | 2 | ||||
-rw-r--r-- | platform/android/src/style/value.hpp | 8 |
9 files changed, 111 insertions, 114 deletions
diff --git a/platform/android/config.cmake b/platform/android/config.cmake index 8dd537d36e..db75b850f1 100644 --- a/platform/android/config.cmake +++ b/platform/android/config.cmake @@ -146,7 +146,6 @@ add_library(mbgl-android STATIC # Style conversion Java -> C++ platform/android/src/style/android_conversion.hpp - platform/android/src/style/conversion/geojson.hpp platform/android/src/style/value.cpp platform/android/src/style/value.hpp platform/android/src/style/conversion/url_or_tileset.hpp diff --git a/platform/android/src/style/android_conversion.hpp b/platform/android/src/style/android_conversion.hpp index 082fe411e2..510a9f8444 100644 --- a/platform/android/src/style/android_conversion.hpp +++ b/platform/android/src/style/android_conversion.hpp @@ -4,8 +4,9 @@ #include <mbgl/util/feature.hpp> #include <mbgl/util/logging.hpp> -#include <mbgl/style/conversion.hpp> #include <mbgl/util/optional.hpp> +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/geojson.hpp> #include <jni/jni.hpp> @@ -13,89 +14,105 @@ namespace mbgl { namespace style { namespace conversion { -inline bool isUndefined(const mbgl::android::Value& value) { - return value.isNull(); -} +template <> +class ConversionTraits<mbgl::android::Value> { +public: + static bool isUndefined(const mbgl::android::Value& value) { + return value.isNull(); + } -inline bool isArray(const mbgl::android::Value& value) { - return value.isArray(); -} + static bool isArray(const mbgl::android::Value& value) { + return value.isArray(); + } -inline bool isObject(const mbgl::android::Value& value) { - return value.isObject(); -} + static bool isObject(const mbgl::android::Value& value) { + return value.isObject(); + } -inline std::size_t arrayLength(const mbgl::android::Value& value) { - return value.getLength();; -} + static std::size_t arrayLength(const mbgl::android::Value& value) { + return value.getLength();; + } -inline mbgl::android::Value arrayMember(const mbgl::android::Value& value, std::size_t i) { - return value.get(i); -} + static mbgl::android::Value arrayMember(const mbgl::android::Value& value, std::size_t i) { + return value.get(i); + } -inline optional<mbgl::android::Value> objectMember(const mbgl::android::Value& value, const char* key) { - mbgl::android::Value member = value.get(key); + static 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; + } else { + return {}; + } + } - if (!member.isNull()) { - return member; - } else { + template <class Fn> + static optional<Error> eachMember(const mbgl::android::Value&, Fn&&) { + // TODO + mbgl::Log::Warning(mbgl::Event::Android, "eachMember not implemented"); return {}; } -} -template <class Fn> -optional<Error> eachMember(const mbgl::android::Value&, Fn&&) { - // TODO - mbgl::Log::Warning(mbgl::Event::Android, "eachMember not implemented"); - return {}; -} + static optional<bool> toBool(const mbgl::android::Value& value) { + if (value.isBool()) { + return value.toBool(); + } else { + return {}; + } + } -inline optional<bool> toBool(const mbgl::android::Value& value) { - if (value.isBool()) { - return value.toBool(); - } else { - return {}; + static optional<float> toNumber(const mbgl::android::Value& value) { + if (value.isNumber()) { + auto num = value.toFloat(); + return num; + } else { + return {}; + } } -} -inline optional<float> toNumber(const mbgl::android::Value& value) { - if (value.isNumber()) { - auto num = value.toFloat(); - return num; - } else { - return {}; + static optional<double> toDouble(const mbgl::android::Value& value) { + if (value.isNumber()) { + return value.toDouble(); + } else { + return {}; + } } -} -inline optional<double> toDouble(const mbgl::android::Value& value) { - if (value.isNumber()) { - return value.toDouble(); - } else { - return {}; + static optional<std::string> toString(const mbgl::android::Value& value) { + if (value.isString()) { + return value.toString(); + } else { + return {}; + } } -} -inline optional<std::string> toString(const mbgl::android::Value& value) { - if (value.isString()) { - return value.toString(); - } else { - return {}; + static optional<Value> toValue(const mbgl::android::Value& value) { + if (value.isNull()) { + return {}; + } else if (value.isBool()) { + return { value.toBool() }; + } else if (value.isString()) { + return { value.toString() }; + } else if (value.isNumber()) { + auto doubleVal = value.toDouble(); + return { doubleVal - (int) doubleVal > 0.0 ? doubleVal : value.toLong() }; + } else { + return {}; + } } -} -inline optional<Value> toValue(const mbgl::android::Value& value) { - if (value.isNull()) { - return {}; - } else if (value.isBool()) { - return { value.toBool() }; - } else if (value.isString()) { - return { value.toString() }; - } else if (value.isNumber()) { - auto doubleVal = value.toDouble(); - return { doubleVal - (int) doubleVal > 0.0 ? doubleVal : value.toLong() }; - } else { - return {}; + static optional<GeoJSON> toGeoJSON(const mbgl::android::Value &value, Error &error) { + if (value.isNull() || !value.isString()) { + error = { "no json data found" }; + return {}; + } + return parseGeoJSON(value.toString(), error); } +}; + +template <class T, class...Args> +optional<T> convert(mbgl::android::Value&& value, Error& error, Args&&...args) { + return convert<T>(Convertible(std::move(value)), error, std::forward<Args>(args)...); } } // namespace conversion diff --git a/platform/android/src/style/conversion/filter.hpp b/platform/android/src/style/conversion/filter.hpp index 1f0abcf3a4..c154e88e7c 100644 --- a/platform/android/src/style/conversion/filter.hpp +++ b/platform/android/src/style/conversion/filter.hpp @@ -16,9 +16,8 @@ namespace conversion { inline optional<mbgl::style::Filter> toFilter(jni::JNIEnv& env, jni::Array<jni::Object<>> jfilter) { mbgl::optional<mbgl::style::Filter> filter; if (jfilter) { - Value filterValue(env, jfilter); mbgl::style::conversion::Error error; - auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(filterValue, error); + auto converted = mbgl::style::conversion::convert<mbgl::style::Filter>(Value(env, jfilter), error); if (!converted) { mbgl::Log::Error(mbgl::Event::JNI, "Error converting filter: " + error.message); } diff --git a/platform/android/src/style/conversion/geojson.hpp b/platform/android/src/style/conversion/geojson.hpp deleted file mode 100644 index 748fe7361e..0000000000 --- a/platform/android/src/style/conversion/geojson.hpp +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#include <mapbox/geojson.hpp> -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/conversion/geojson.hpp> -#include <jni/jni.hpp> - -namespace mbgl { -namespace style { -namespace conversion { - -template <> -optional<GeoJSON> Converter<GeoJSON>::operator()(const mbgl::android::Value& value, Error& error) const { - if(value.isNull() || !value.isString()) { - error = { "no json data found" }; - return {}; - } - - return convert<GeoJSON>(value.toString(), error); -} - -} // namespace conversion -} // namespace style -} // namespace mbgl diff --git a/platform/android/src/style/conversion/url_or_tileset.hpp b/platform/android/src/style/conversion/url_or_tileset.hpp index 00ef913d41..92c1182a63 100644 --- a/platform/android/src/style/conversion/url_or_tileset.hpp +++ b/platform/android/src/style/conversion/url_or_tileset.hpp @@ -17,18 +17,19 @@ namespace android { // This conversion is expected not to fail because it's used only in contexts where // the value was originally a String or TileSet object on the Java side. If it fails // to convert, it's a bug in our serialization or Java-side static typing. -inline variant<std::string, Tileset> convertURLOrTileset(const Value& value) { +inline variant<std::string, Tileset> convertURLOrTileset(mbgl::android::Value&& value) { using namespace mbgl::style::conversion; - if (isObject(value)) { + const Convertible convertible(std::move(value)); + if (isObject(convertible)) { Error error; - optional<Tileset> tileset = convert<Tileset>(value, error); + optional<Tileset> tileset = convert<Tileset>(convertible, error); if (!tileset) { throw std::logic_error(error.message); } return { *tileset }; } else { - return { *toString(value) }; + return { *toString(convertible) }; } } diff --git a/platform/android/src/style/layers/layer.cpp b/platform/android/src/style/layers/layer.cpp index 02a1f0be82..31032b117f 100644 --- a/platform/android/src/style/layers/layer.cpp +++ b/platform/android/src/style/layers/layer.cpp @@ -4,11 +4,20 @@ #include <jni/jni.hpp> #include <mbgl/style/style.hpp> +#include <mbgl/style/filter.hpp> #include <mbgl/style/transition_options.hpp> +#include <mbgl/style/layers/background_layer.hpp> +#include <mbgl/style/layers/circle_layer.hpp> +#include <mbgl/style/layers/fill_layer.hpp> +#include <mbgl/style/layers/fill_extrusion_layer.hpp> +#include <mbgl/style/layers/line_layer.hpp> +#include <mbgl/style/layers/raster_layer.hpp> +#include <mbgl/style/layers/symbol_layer.hpp> #include <mbgl/util/logging.hpp> // Java -> C++ conversion #include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/filter.hpp> #include <mbgl/style/conversion/layer.hpp> #include <mbgl/style/conversion/source.hpp> @@ -78,10 +87,8 @@ namespace android { } void Layer::setLayoutProperty(jni::JNIEnv& env, jni::String jname, jni::Object<> jvalue) { - Value value(env, jvalue); - // Convert and set property - optional<mbgl::style::conversion::Error> error = mbgl::style::conversion::setLayoutProperty(layer, jni::Make<std::string>(env, jname), value); + optional<mbgl::style::conversion::Error> error = mbgl::style::conversion::setLayoutProperty(layer, 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); return; @@ -89,10 +96,8 @@ namespace android { } void Layer::setPaintProperty(jni::JNIEnv& env, jni::String jname, jni::Object<> jvalue) { - Value value(env, jvalue); - // Convert and set property - optional<mbgl::style::conversion::Error> error = mbgl::style::conversion::setPaintProperty(layer, jni::Make<std::string>(env, jname), value); + optional<mbgl::style::conversion::Error> error = mbgl::style::conversion::setPaintProperty(layer, 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); return; @@ -116,10 +121,8 @@ namespace android { using namespace mbgl::style; using namespace mbgl::style::conversion; - Value wrapped(env, jfilter); - Error error; - optional<Filter> converted = convert<Filter>(wrapped, error); + optional<Filter> converted = convert<Filter>(Value(env, jfilter), error); if (!converted) { mbgl::Log::Error(mbgl::Event::JNI, "Error setting filter: " + error.message); return; diff --git a/platform/android/src/style/sources/geojson_source.cpp b/platform/android/src/style/sources/geojson_source.cpp index 90ef851eba..4468b453f3 100644 --- a/platform/android/src/style/sources/geojson_source.cpp +++ b/platform/android/src/style/sources/geojson_source.cpp @@ -5,15 +5,15 @@ // Java -> C++ conversion #include "../android_conversion.hpp" #include "../conversion/filter.hpp" -#include "../conversion/geojson.hpp" +#include <mbgl/style/conversion.hpp> +#include <mbgl/style/conversion/geojson.hpp> +#include <mbgl/style/conversion/geojson_options.hpp> // C++ -> Java conversion #include "../../conversion/conversion.hpp" #include "../../conversion/collection.hpp" #include "../../geojson/conversion/feature.hpp" #include "../conversion/url_or_tileset.hpp" -#include <mbgl/style/conversion.hpp> -#include <mbgl/style/conversion/geojson_options.hpp> #include <string> @@ -29,7 +29,7 @@ namespace android { return style::GeoJSONOptions(); } Error error; - optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>(Value(env, options), error); + optional<style::GeoJSONOptions> result = convert<style::GeoJSONOptions>(mbgl::android::Value(env, options), error); if (!result) { throw std::logic_error(error.message); } @@ -54,7 +54,7 @@ namespace android { // Convert the jni object Error error; - optional<GeoJSON> converted = convert<GeoJSON>(Value(env, json), error); + optional<GeoJSON> converted = convert<GeoJSON>(mbgl::android::Value(env, json), error); if(!converted) { mbgl::Log::Error(mbgl::Event::JNI, "Error setting geo json: " + error.message); return; diff --git a/platform/android/src/style/value.cpp b/platform/android/src/style/value.cpp index e1cd81d7fd..70bdea6677 100644 --- a/platform/android/src/style/value.cpp +++ b/platform/android/src/style/value.cpp @@ -24,8 +24,6 @@ namespace android { Value::Value(jni::JNIEnv& _env, jni::jobject* _value) : env(_env), value(_value, ObjectDeleter(env)) {} - Value::~Value() = default; - bool Value::isNull() const { return value == nullptr; } diff --git a/platform/android/src/style/value.hpp b/platform/android/src/style/value.hpp index 7464bae832..2057b93454 100644 --- a/platform/android/src/style/value.hpp +++ b/platform/android/src/style/value.hpp @@ -9,9 +9,13 @@ namespace android { class Value { public: - Value(jni::JNIEnv&, jni::jobject*); - virtual ~Value(); + + Value(Value&&) = default; + Value& operator=(Value&&) = default; + + Value(const Value&) = delete; + Value& operator=(const Value&) = delete; bool isNull() const; bool isArray() const; |