本文整理汇总了C++中JEnv::GetObjectArrayElement方法的典型用法代码示例。如果您正苦于以下问题:C++ JEnv::GetObjectArrayElement方法的具体用法?C++ JEnv::GetObjectArrayElement怎么用?C++ JEnv::GetObjectArrayElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JEnv
的用法示例。
在下文中一共展示了JEnv::GetObjectArrayElement方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: className
vector<string> NativeScriptRuntime::GetTypeMetadata(const string& name, int index)
{
JEnv env;
string canonicalName = Util::ConvertFromJniToCanonicalName(name);
JniLocalRef className(env.NewStringUTF(canonicalName.c_str()));
jint idx = index;
JniLocalRef pubApi(env.CallStaticObjectMethod(PlatformClass, GET_TYPE_METADATA, (jstring) className, idx));
jsize length = env.GetArrayLength(pubApi);
assert(length > 0);
vector<string> result;
for (jsize i=0; i<length; i++)
{
JniLocalRef s(env.GetObjectArrayElement(pubApi, i));
const char *pc = env.GetStringUTFChars(s, nullptr);
result.push_back(string(pc));
env.ReleaseStringUTFChars(s, pc);
}
return result;
}
示例2: handleScope
Local<Value> ArrayElementAccessor::GetArrayElement(const Local<Object>& array, uint32_t index, const string& arraySignature)
{
JEnv env;
Isolate* isolate = Isolate::GetCurrent();
EscapableHandleScope handleScope(isolate);
jweak arr = objectManager->GetJavaObjectByJsObject(array);
Local<Value> value;
jsize startIndex = index;
const jsize length = 1;
const string elementSignature = arraySignature.substr(1);
jboolean isCopy = false;
if (elementSignature == "Z")
{
jbooleanArray boolArr = reinterpret_cast<jbooleanArray>(arr);
jboolean boolArrValue;
env.GetBooleanArrayRegion(boolArr, startIndex, length, &boolArrValue);
value = ConvertToJsValue(env, elementSignature, &boolArrValue);
}
else if (elementSignature == "B")
{
jbyteArray byteArr = reinterpret_cast<jbyteArray>(arr);
jbyte byteArrValue;
env.GetByteArrayRegion(byteArr, startIndex, length, &byteArrValue);
value = ConvertToJsValue(env, elementSignature, &byteArrValue);
}
else if (elementSignature == "C")
{
jcharArray charArr = reinterpret_cast<jcharArray>(arr);
jchar charArrValue;
env.GetCharArrayRegion(charArr, startIndex, length, &charArrValue);
JniLocalRef s(env.NewString(&charArrValue, 1));
const char* singleChar = env.GetStringUTFChars(s, &isCopy);
value = ConvertToJsValue(env, elementSignature, singleChar);
env.ReleaseStringUTFChars(s, singleChar);
}
else if (elementSignature == "S")
{
jshortArray shortArr = reinterpret_cast<jshortArray>(arr);
jshort shortArrValue;
env.GetShortArrayRegion(shortArr, startIndex, length, &shortArrValue);
value = ConvertToJsValue(env, elementSignature, &shortArrValue);
}
else if (elementSignature == "I")
{
jintArray intArr = reinterpret_cast<jintArray>(arr);
jint intArrValue;
env.GetIntArrayRegion(intArr, startIndex, length, &intArrValue);
value = ConvertToJsValue(env, elementSignature, &intArrValue);
}
else if (elementSignature == "J")
{
jlongArray longArr = reinterpret_cast<jlongArray>(arr);
jlong longArrValue;
env.GetLongArrayRegion(longArr, startIndex, length, &longArrValue);
value = ConvertToJsValue(env, elementSignature, &longArrValue);
}
else if (elementSignature == "F")
{
jfloatArray floatArr = reinterpret_cast<jfloatArray>(arr);
jfloat floatArrValue;
env.GetFloatArrayRegion(floatArr, startIndex, length, &floatArrValue);
value = ConvertToJsValue(env, elementSignature, &floatArrValue);
}
else if (elementSignature == "D")
{
jdoubleArray doubleArr = reinterpret_cast<jdoubleArray>(arr);
jdouble doubleArrValue;
env.GetDoubleArrayRegion(doubleArr, startIndex, length, &doubleArrValue);
value = ConvertToJsValue(env, elementSignature, &doubleArrValue);
}
else
{
jobject result = env.GetObjectArrayElement(reinterpret_cast<jobjectArray>(arr), index);
value = ConvertToJsValue(env, elementSignature, &result);
env.DeleteLocalRef(result);
}
return handleScope.Escape(value);
}
示例3: argTypeIDObj
Local<Array> ArgConverter::ConvertJavaArgsToJsArgs(jobjectArray args)
{
JEnv env;
auto isolate = Isolate::GetCurrent();
int argc = env.GetArrayLength(args) / 3;
Local<Array> arr(Array::New(isolate, argc));
int jArrayIndex = 0;
for (int i = 0; i < argc; i++)
{
JniLocalRef argTypeIDObj(env.GetObjectArrayElement(args, jArrayIndex++));
JniLocalRef arg(env.GetObjectArrayElement(args, jArrayIndex++));
JniLocalRef argJavaClassPath(env.GetObjectArrayElement(args, jArrayIndex++));
jint length;
Type argTypeID = (Type)JType::IntValue(env, argTypeIDObj);
Local<Value> jsArg;
switch (argTypeID)
{
case Type::Boolean:
jsArg = Boolean::New(isolate, JType::BooleanValue(env, arg));
break;
case Type::Char:
jsArg =jcharToV8String(JType::CharValue(env, arg));
break;
case Type::Byte:
jsArg = Number::New(isolate, JType::ByteValue(env, arg));
break;
case Type::Short:
jsArg = Number::New(isolate, JType::ShortValue(env, arg));
break;
case Type::Int:
jsArg = Number::New(isolate, JType::IntValue(env, arg));
break;
case Type::Long:
jsArg = Number::New(isolate, JType::LongValue(env, arg));
break;
case Type::Float:
jsArg = Number::New(isolate, JType::FloatValue(env, arg));
break;
case Type::Double:
jsArg = Number::New(isolate, JType::DoubleValue(env, arg));
break;
case Type::String:
jsArg = jstringToV8String((jstring)arg);
break;
case Type::JsObject:
{
jint javaObjectID = JType::IntValue(env, arg);
jsArg = ObjectManager::GetJsObjectByJavaObjectStatic(javaObjectID);
if (jsArg.IsEmpty())
{
string argClassName = jstringToString(ObjectToString(argJavaClassPath));
argClassName = Util::ConvertFromCanonicalToJniName(argClassName);
jsArg = ObjectManager::CreateJSWrapperStatic(javaObjectID, argClassName);
}
break;
}
case Type::Null:
jsArg = Null(isolate);
break;
}
arr->Set(i, jsArg);
}
return arr;
}