summaryrefslogtreecommitdiff
path: root/platform/android/src/geojson
diff options
context:
space:
mode:
Diffstat (limited to 'platform/android/src/geojson')
-rw-r--r--platform/android/src/geojson/conversion/feature.cpp55
-rw-r--r--platform/android/src/geojson/conversion/feature.hpp22
-rw-r--r--platform/android/src/geojson/feature.cpp72
-rw-r--r--platform/android/src/geojson/feature.hpp17
4 files changed, 46 insertions, 120 deletions
diff --git a/platform/android/src/geojson/conversion/feature.cpp b/platform/android/src/geojson/conversion/feature.cpp
deleted file mode 100644
index 7386e29df5..0000000000
--- a/platform/android/src/geojson/conversion/feature.cpp
+++ /dev/null
@@ -1,55 +0,0 @@
-#include "feature.hpp"
-
-#include "../../gson/json_object.hpp"
-
-namespace mbgl {
-namespace android {
-namespace conversion {
-
-using namespace gson;
-
-/**
- * Turn feature identifier into std::string
- */
-class FeatureIdVisitor {
-public:
-
- template<class T>
- std::string operator()(const T& i) const {
- return std::to_string(i);
- }
-
- std::string operator()(const std::string& i) const {
- return i;
- }
-
- std::string operator()(const std::nullptr_t&) const {
- return "";
- }
-
-};
-
-jni::Object<android::geojson::Feature> convertFeature(jni::JNIEnv& env, const mbgl::Feature& value) {
- using namespace mbgl::android::geojson;
-
- return Feature::fromGeometry(env,
- *jni::SeizeLocal(env, Geometry::New(env, value.geometry)),
- *jni::SeizeLocal(env, JsonObject::New(env, value.properties)),
- *jni::SeizeLocal(env, jni::Make<jni::String>(env, value.id ? value.id.value().match(FeatureIdVisitor()) : "")));
-}
-
-Result<jni::Array<jni::Object<android::geojson::Feature>>> Converter<jni::Array<jni::Object<android::geojson::Feature>>, std::vector<mbgl::Feature>>::operator()(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) const {
- using namespace mbgl::android::geojson;
-
- auto features = jni::Array<jni::Object<Feature>>::New(env, value.size());
-
- for (size_t i = 0; i < value.size(); i = i + 1) {
- features.Set(env, i, *jni::SeizeLocal(env, convertFeature(env, value.at(i))));
- }
-
- return {features};
-}
-
-} // namespace conversion
-} // namespace android
-} // namespace mbgl
diff --git a/platform/android/src/geojson/conversion/feature.hpp b/platform/android/src/geojson/conversion/feature.hpp
deleted file mode 100644
index d9fc0a0b67..0000000000
--- a/platform/android/src/geojson/conversion/feature.hpp
+++ /dev/null
@@ -1,22 +0,0 @@
-#pragma once
-
-#include "../../conversion/conversion.hpp"
-#include "../feature.hpp"
-
-#include <mbgl/util/feature.hpp>
-#include <jni/jni.hpp>
-
-#include <vector>
-
-namespace mbgl {
-namespace android {
-namespace conversion {
-
-template <>
-struct Converter<jni::Array<jni::Object<android::geojson::Feature>>, std::vector<mbgl::Feature>> {
- Result<jni::Array<jni::Object<android::geojson::Feature>>> operator()(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) const;
-};
-
-} // namespace conversion
-} // namespace android
-} // namespace mbgl
diff --git a/platform/android/src/geojson/feature.cpp b/platform/android/src/geojson/feature.cpp
index 1e02c756eb..809ac42ef7 100644
--- a/platform/android/src/geojson/feature.cpp
+++ b/platform/android/src/geojson/feature.cpp
@@ -1,50 +1,66 @@
#include "feature.hpp"
-
#include "geometry.hpp"
+#include "../gson/json_object.hpp"
namespace mbgl {
namespace android {
namespace geojson {
+using namespace gson;
+
mbgl::Feature Feature::convert(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
- auto jGeometry = jni::SeizeLocal(env, geometry(env, jFeature));
- auto jProperties = jni::SeizeLocal(env, Feature::properties(env, jFeature));
+ static auto javaClass = jni::Class<Feature>::Singleton(env);
+ static auto id = javaClass.GetMethod<jni::String ()>(env, "id");
+ static auto geometry = javaClass.GetMethod<jni::Object<Geometry> ()>(env, "geometry");
+ static auto properties = javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "properties");
- std::experimental::optional<mapbox::geometry::identifier> id;
- auto jId = jni::SeizeLocal(env, Feature::id(env, jFeature));
- if (jId) {
- id = { jni::Make<std::string>(env, *jId) };
- }
+ auto jId = jni::SeizeLocal(env, jFeature.Call(env, id));
return mbgl::Feature {
- Geometry::convert(env, *jGeometry),
- gson::JsonObject::convert(env, *jProperties),
- id
+ Geometry::convert(env, *jni::SeizeLocal(env, jFeature.Call(env, geometry))),
+ JsonObject::convert(env, *jni::SeizeLocal(env, jFeature.Call(env, properties))),
+ jId ? std::experimental::optional<mapbox::geometry::identifier>(jni::Make<std::string>(env, *jId))
+ : std::experimental::nullopt
};
}
-jni::Object<Geometry> Feature::geometry(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
- static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetMethod<jni::Object<Geometry> ()>(env, "geometry");
- return jFeature.Call(env, method);
-}
+/**
+ * Turn feature identifier into std::string
+ */
+class FeatureIdVisitor {
+public:
+ template<class T>
+ std::string operator()(const T& i) const {
+ return std::to_string(i);
+ }
-jni::Object<gson::JsonObject> Feature::properties(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
- static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetMethod<jni::Object<gson::JsonObject> ()>(env, "properties");
- return jFeature.Call(env, method);
-}
+ std::string operator()(const std::string& i) const {
+ return i;
+ }
+
+ std::string operator()(const std::nullptr_t&) const {
+ return "";
+ }
+};
-jni::String Feature::id(jni::JNIEnv& env, jni::Object<Feature> jFeature) {
+jni::Object<Feature> convertFeature(jni::JNIEnv& env, const mbgl::Feature& value) {
static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetMethod<jni::String ()>(env, "id");
- return jFeature.Call(env, method);
+ static auto method = javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<JsonObject>, jni::String)>(env, "fromGeometry");
+
+ return javaClass.Call(env, method,
+ *jni::SeizeLocal(env, Geometry::New(env, value.geometry)),
+ *jni::SeizeLocal(env, JsonObject::New(env, value.properties)),
+ *jni::SeizeLocal(env, jni::Make<jni::String>(env, value.id ? value.id.value().match(FeatureIdVisitor()) : "")));
}
-jni::Object<Feature> Feature::fromGeometry(jni::JNIEnv& env, jni::Object<Geometry> geometry, jni::Object<gson::JsonObject> properties, jni::String id) {
- static auto javaClass = jni::Class<Feature>::Singleton(env);
- static auto method = javaClass.GetStaticMethod<jni::Object<Feature> (jni::Object<Geometry>, jni::Object<gson::JsonObject>, jni::String)>(env, "fromGeometry");
- return javaClass.Call(env, method, geometry, properties, id);
+jni::Array<jni::Object<Feature>> Feature::convert(jni::JNIEnv& env, const std::vector<mbgl::Feature>& value) {
+ auto features = jni::Array<jni::Object<Feature>>::New(env, value.size());
+
+ for (size_t i = 0; i < value.size(); i = i + 1) {
+ features.Set(env, i, *jni::SeizeLocal(env, convertFeature(env, value.at(i))));
+ }
+
+ return features;
}
void Feature::registerNative(jni::JNIEnv& env) {
diff --git a/platform/android/src/geojson/feature.hpp b/platform/android/src/geojson/feature.hpp
index de38e9b1e3..fba4815e0c 100644
--- a/platform/android/src/geojson/feature.hpp
+++ b/platform/android/src/geojson/feature.hpp
@@ -1,32 +1,19 @@
#pragma once
#include <mbgl/util/feature.hpp>
-#include <mbgl/util/geometry.hpp>
-#include <mbgl/util/noncopyable.hpp>
#include <jni/jni.hpp>
-#include "geometry.hpp"
-#include "../gson/json_object.hpp"
-
namespace mbgl {
namespace android {
namespace geojson {
-class Feature : private mbgl::util::noncopyable {
+class Feature : public jni::ObjectTag {
public:
-
static constexpr auto Name() { return "com/mapbox/geojson/Feature"; };
- static jni::Object<Feature> fromGeometry(jni::JNIEnv&, jni::Object<Geometry>, jni::Object<gson::JsonObject>, jni::String);
-
static mbgl::Feature convert(jni::JNIEnv&, jni::Object<Feature>);
-
- static jni::Object<Geometry> geometry(jni::JNIEnv&, jni::Object<Feature>);
-
- static jni::String id(jni::JNIEnv&, jni::Object<Feature>);
-
- static jni::Object<gson::JsonObject> properties(jni::JNIEnv&, jni::Object<Feature>);
+ static jni::Array<jni::Object<Feature>> convert(jni::JNIEnv&, const std::vector<mbgl::Feature>&);
static void registerNative(jni::JNIEnv&);
};