void convert__int_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<int> *cxx_vector = (std::vector<int> *) cxx_value; int count = cxx_vector->size(); int java_array[count]; int item_idx = 0; for(std::vector<int>::iterator it = cxx_vector->begin(); it != cxx_vector->end(); ++it) { int item = (int) *it; java_array[item_idx++] = item; } java_value = (long) jni->createIntArray(*java_array, count); java_value = (long) jni->popLocalFrame((jobject) java_value); } else if (converter_type == CONVERT_TO_CXX) { jni->pushLocalFrame(); cxx_converter item_converter = get_converter(converter_stack); std::vector<int> *cxx_vector = new std::vector<int>(); int count = (int) jni->getArrayLength((jarray) java_value); int * java_array = jni->getIntArray((jintArray) java_value); for (int idx = 0 ; idx < count; idx++) { int item = (int) java_array[idx]; cxx_vector->push_back(item); } cxx_value = (long) cxx_vector; jni->popLocalFrame(); } }
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(); } }