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-06 17:26:28 -0700 |
commit | 9cd50a891dbd320e9e4816eef4545e0a41f9ab32 (patch) | |
tree | b424e2dcee3090d9c3f37864112d19799dd9af35 /platform/android/src/style/value.cpp | |
parent | 70a204924552463eaeca975a5dd28c00b21aa53d (diff) | |
download | qtlocation-mapboxgl-upstream/jni.hpp-4.tar.gz |
[android] jni.hpp 4.0.0upstream/jni.hpp-4
Diffstat (limited to 'platform/android/src/style/value.cpp')
-rw-r--r-- | platform/android/src/style/value.cpp | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/platform/android/src/style/value.cpp b/platform/android/src/style/value.cpp index 6cdf134931..f916909687 100644 --- a/platform/android/src/style/value.cpp +++ b/platform/android/src/style/value.cpp @@ -10,64 +10,67 @@ namespace android { : env(_env), value(std::move(_value)) {} + Value::Value(jni::JNIEnv& _env, const jni::Object<>& _value) + : env(_env), + value(jni::NewLocal(_env, _value)) {} + bool Value::isNull() const { return !value; } bool Value::isArray() const { - return jni::IsInstanceOf(env, value->Get(), *java::ObjectArray::jclass); + return jni::IsInstanceOf(env, value.get(), *java::ObjectArray::jclass); } bool Value::isObject() const { - return jni::IsInstanceOf(env, value->Get(), *java::Map::jclass); + return jni::IsInstanceOf(env, value.get(), *java::Map::jclass); } bool Value::isString() const { - return jni::IsInstanceOf(env, value->Get(), *java::String::jclass); + return jni::IsInstanceOf(env, value.get(), *java::String::jclass); } bool Value::isBool() const { - return jni::IsInstanceOf(env, value->Get(), *java::Boolean::jclass); + return jni::IsInstanceOf(env, value.get(), *java::Boolean::jclass); } bool Value::isNumber() const { - return jni::IsInstanceOf(env, value->Get(), *java::Number::jclass); + return jni::IsInstanceOf(env, value.get(), *java::Number::jclass); } std::string Value::toString() const { - jni::jstring* string = reinterpret_cast<jni::jstring*>(value->Get()); - return jni::Make<std::string>(env, jni::String(string)); + return jni::Make<std::string>(env, jni::Cast(env, jni::Class<jni::StringTag>::Singleton(env), value)); } float Value::toFloat() const { - return jni::CallMethod<jni::jfloat>(env, value->Get(), *java::Number::floatValueMethodId); + return jni::CallMethod<jni::jfloat>(env, value.get(), *java::Number::floatValueMethodId); } double Value::toDouble() const { - return jni::CallMethod<jni::jdouble>(env, value->Get(), *java::Number::doubleValueMethodId); + return jni::CallMethod<jni::jdouble>(env, value.get(), *java::Number::doubleValueMethodId); } long Value::toLong() const { - return jni::CallMethod<jni::jlong>(env, value->Get(), *java::Number::longValueMethodId); + return jni::CallMethod<jni::jlong>(env, value.get(), *java::Number::longValueMethodId); } bool Value::toBool() const { - return jni::CallMethod<jni::jboolean>(env, value->Get(), *java::Boolean::booleanValueMethodId); + return jni::CallMethod<jni::jboolean>(env, value.get(), *java::Boolean::booleanValueMethodId); } Value Value::get(const char* key) const { - jni::jobject* member = jni::CallMethod<jni::jobject*>(env, value->Get(), *java::Map::getMethodId, jni::Make<jni::String>(env, std::string(key)).Get()); - return Value(env, jni::SeizeLocal(env, jni::Object<>(member))); + jni::jobject* member = jni::CallMethod<jni::jobject*>(env, value.get(), *java::Map::getMethodId, jni::Make<jni::String>(env, std::string(key)).get()); + return Value(env, jni::Local<jni::Object<>>(env, member)); } int Value::getLength() const { - auto array = (jni::jarray<jni::jobject>*) value->Get(); + auto array = (jni::jarray<jni::jobject>*) value.get(); return jni::GetArrayLength(env, *array); } Value Value::get(const int index) const { - auto array = (jni::jarray<jni::jobject>*) value->Get(); - return Value(env, jni::SeizeLocal(env, jni::Object<>(jni::GetObjectArrayElement(env, *array, index)))); + auto array = (jni::jarray<jni::jobject>*) value.get(); + return Value(env, jni::Local<jni::Object<>>(env, jni::GetObjectArrayElement(env, *array, index))); } } } |