本文整理汇总了C++中JNIContext::getObjectArrayElement方法的典型用法代码示例。如果您正苦于以下问题:C++ JNIContext::getObjectArrayElement方法的具体用法?C++ JNIContext::getObjectArrayElement怎么用?C++ JNIContext::getObjectArrayElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JNIContext
的用法示例。
在下文中一共展示了JNIContext::getObjectArrayElement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: convert__object_array_type
void convert__object_array_type(long& java_value, long& cxx_value, const CXXTypeHierarchy cxx_type_hierarchy, const converter_t& converter_type, std::stack<long>& converter_stack)
{
JNIContext *jni = JNIContext::sharedInstance();
if (converter_type == CONVERT_TO_JAVA)
{
jni->pushLocalFrame();
cxx_converter item_converter = get_converter(converter_stack);
std::vector<long> *cxx_vector = (std::vector<long> *) cxx_value;
int count = cxx_vector->size();
std::string child_type = jni->getJNIName( std::string("java.lang.Object") );
CXXTypeHierarchy item_type;
item_type.type_name = child_type;
std::vector<CXXTypeHierarchy> child_types = cxx_type_hierarchy.child_types;
if (child_types.size() > 0)
{
item_type = child_types.at(0);
child_type = jni->getJNIName( item_type.type_name );
}
java_value = (long) jni->createObjectArray(count, jni->getClassRef( child_type.c_str() ));
for(std::vector<long>::iterator it = cxx_vector->begin(); it != cxx_vector->end(); ++it)
{
long cxx_item_ptr = (long) *it;
long java_item_ptr = 0;
int item_idx = it - cxx_vector->begin();
item_converter(java_item_ptr, cxx_item_ptr, item_type, converter_type, converter_stack);
jni->setObjectArrayElement((jobjectArray) java_value, item_idx, (jobject) java_item_ptr);
}
java_value = (long) jni->popLocalFrame((jobject) java_value);
}
else if (converter_type == CONVERT_TO_CXX)
{
jni->pushLocalFrame();
std::string child_type = jni->getJNIName( std::string("java.lang.Object") );
CXXTypeHierarchy item_type;
item_type.type_name = child_type;
std::vector<CXXTypeHierarchy> child_types = cxx_type_hierarchy.child_types;
if (child_types.size() > 0)
{
item_type = child_types.at(0);
child_type = jni->getJNIName( item_type.type_name );
}
cxx_converter item_converter = get_converter(converter_stack);
std::vector<long> *cxx_vector = (std::vector<long> *) cxx_value;
int size = (int) jni->getArrayLength((jobjectArray) java_value);
for (int idx = 0 ; idx < size; idx++)
{
long java_item_ptr = (long) jni->getObjectArrayElement((jobjectArray) java_value, idx);
long cxx_item_ptr = 0;
item_converter(java_item_ptr, cxx_item_ptr, item_type, converter_type, converter_stack);
cxx_vector->push_back(cxx_item_ptr);
}
jni->popLocalFrame();
}
}