diff options
author | John Firebaugh <john.firebaugh@gmail.com> | 2018-08-22 12:27:43 -0700 |
---|---|---|
committer | John Firebaugh <john.firebaugh@gmail.com> | 2018-09-07 09:44:12 -0700 |
commit | 79bf0e8af6bf9ec829a352d56b8e70ccc8f4fa41 (patch) | |
tree | 2b646523d45f0fa9917612ed80de12bbd35d5b1e /platform/android/src/gson/json_object.cpp | |
parent | 5911e3b13f2f2b6741e26db3e41513ed21cc95b4 (diff) | |
download | qtlocation-mapboxgl-79bf0e8af6bf9ec829a352d56b8e70ccc8f4fa41.tar.gz |
[android] jni.hpp 4.0.0
Diffstat (limited to 'platform/android/src/gson/json_object.cpp')
-rw-r--r-- | platform/android/src/gson/json_object.cpp | 30 |
1 files changed, 14 insertions, 16 deletions
diff --git a/platform/android/src/gson/json_object.cpp b/platform/android/src/gson/json_object.cpp index 5dcb07642f..10d244ee48 100644 --- a/platform/android/src/gson/json_object.cpp +++ b/platform/android/src/gson/json_object.cpp @@ -9,48 +9,46 @@ namespace android { namespace gson { -jni::Object<JsonObject> JsonObject::New(jni::JNIEnv& env, const mbgl::PropertyMap& values) { - static auto javaClass = jni::Class<JsonObject>::Singleton(env); +jni::Local<jni::Object<JsonObject>> JsonObject::New(jni::JNIEnv& env, const mbgl::PropertyMap& values) { + static auto& javaClass = jni::Class<JsonObject>::Singleton(env); static auto constructor = javaClass.GetConstructor(env); static auto addMethod = javaClass.GetMethod<void (jni::String, jni::Object<JsonElement>)>(env, "add"); - jni::Object<JsonObject> jsonObject = javaClass.New(env, constructor); + auto jsonObject = javaClass.New(env, constructor); for (auto &item : values) { jsonObject.Call(env, addMethod, - *jni::SeizeLocal(env, jni::Make<jni::String>(env, item.first)), - *jni::SeizeLocal(env, JsonElement::New(env, item.second))); + jni::Make<jni::String>(env, item.first), + JsonElement::New(env, item.second)); } return jsonObject; } template <typename F> // void (jni::String, jni::Object<gson::JsonElement>) -static void iterateEntrySet(jni::JNIEnv& env, jni::Object<JsonObject> jsonObject, F callback) { +static void iterateEntrySet(jni::JNIEnv& env, const jni::Object<JsonObject>& jsonObject, F callback) { // Get Set<Map.Entry<String, JsonElement>> - static auto javaClass = jni::Class<JsonObject>::Singleton(env); + static auto& javaClass = jni::Class<JsonObject>::Singleton(env); static auto method = javaClass.GetMethod<jni::Object<java::util::Set> ()>(env, "entrySet"); - auto entryArray = - jni::SeizeLocal(env, java::util::Set::toArray<java::util::Map::Entry>(env, - *jni::SeizeLocal(env, jsonObject.Call(env, method)))); + auto entryArray = java::util::Set::toArray<java::util::Map::Entry>(env, jsonObject.Call(env, method)); - size_t size = entryArray->Length(env); + size_t size = entryArray.Length(env); for (size_t i = 0; i < size; i++) { - auto entry = jni::SeizeLocal(env, entryArray->Get(env, i)); + auto entry = entryArray.Get(env, i); if (entry) { callback( - *jni::SeizeLocal(env, java::util::Map::Entry::getKey<jni::StringTag>(env, *entry)), - *jni::SeizeLocal(env, java::util::Map::Entry::getValue<gson::JsonElement>(env, *entry))); + java::util::Map::Entry::getKey<jni::StringTag>(env, entry), + java::util::Map::Entry::getValue<gson::JsonElement>(env, entry)); } } } -mbgl::PropertyMap JsonObject::convert(jni::JNIEnv &env, jni::Object<JsonObject> jsonObject) { +mbgl::PropertyMap JsonObject::convert(jni::JNIEnv& env, const jni::Object<JsonObject>& jsonObject) { mbgl::PropertyMap map; if (jsonObject) { - iterateEntrySet(env, jsonObject, [&map, &env](jni::String jId, jni::Object<gson::JsonElement> jsonElement) { + iterateEntrySet(env, jsonObject, [&map, &env](const jni::String& jId, const jni::Object<gson::JsonElement>& jsonElement) { map[jni::Make<std::string>(env, jId)] = JsonElement::convert(env, jsonElement); }); } |