comparison libinterp/octave-value/ov-java.cc @ 15859:0e393e744e5e

ov-java.cc: Replace instances of comma operator for code clarity. * libinterp/octave-value/ov-java.cc: Replace instances of comma operator for code clarity.
author Rik <rik@octave.org>
date Thu, 27 Dec 2012 23:04:46 -0800
parents fb756e8d6620
children f69530e3600d
comparison
equal deleted inserted replaced
15858:fb756e8d6620 15859:0e393e744e5e
175 175
176 JavaVMInitArgs vm_args; 176 JavaVMInitArgs vm_args;
177 177
178 std::list<std::string> java_opts; 178 std::list<std::string> java_opts;
179 }; 179 };
180
181 void
182 octave_java::print (std::ostream& os, bool) const
183 {
184 print_raw (os);
185 newline (os);
186 }
187
188 void
189 octave_java::print_raw (std::ostream& os, bool) const
190 {
191 os << "<Java object: " << java_classname << ">";
192 }
193
194 static dim_vector compute_array_dimensions (JNIEnv* jni_env, jobject obj);
195 180
196 #ifdef __WIN32__ 181 #ifdef __WIN32__
197 static std::string 182 static std::string
198 read_registry_string (const std::string& key, const std::string& value) 183 read_registry_string (const std::string& key, const std::string& value)
199 { 184 {
737 compute_array_dimensions (JNIEnv* jni_env, jobject obj) 722 compute_array_dimensions (JNIEnv* jni_env, jobject obj)
738 { 723 {
739 jobjectArray_ref jobj (jni_env, reinterpret_cast<jobjectArray> (obj)); 724 jobjectArray_ref jobj (jni_env, reinterpret_cast<jobjectArray> (obj));
740 jclass_ref jcls (jni_env, jni_env->GetObjectClass (obj)); 725 jclass_ref jcls (jni_env, jni_env->GetObjectClass (obj));
741 jclass_ref ccls (jni_env, jni_env->GetObjectClass (jcls)); 726 jclass_ref ccls (jni_env, jni_env->GetObjectClass (jcls));
742 jmethodID isArray_ID = jni_env->GetMethodID (ccls, "isArray", "()Z"), 727 jmethodID isArray_ID = jni_env->GetMethodID (ccls, "isArray", "()Z");
743 getComponentType_ID = jni_env->GetMethodID (ccls, "getComponentType", "()Ljava/lang/Class;"); 728 jmethodID getComponentType_ID = jni_env->GetMethodID (ccls, "getComponentType", "()Ljava/lang/Class;");
744 729
745 dim_vector dv (1, 1); 730 dim_vector dv (1, 1);
746 int idx = 0; 731 int idx = 0;
747 732
748 jobj.detach (); 733 jobj.detach ();
821 const octave_value_list& idx, const octave_value& rhs) 806 const octave_value_list& idx, const octave_value& rhs)
822 { 807 {
823 octave_value retval; 808 octave_value retval;
824 809
825 jclass_ref rhsCls (jni_env); 810 jclass_ref rhsCls (jni_env);
826 jobject_ref resObj (jni_env), rhsObj (jni_env); 811 jobject_ref resObj (jni_env);
812 jobject_ref rhsObj (jni_env);
827 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx)); 813 jobject_ref java_idx (jni_env, make_java_index (jni_env, idx));
828 814
829 if (! error_state && unbox (jni_env, rhs, rhsObj, rhsCls)) 815 if (! error_state && unbox (jni_env, rhs, rhsObj, rhsCls))
830 { 816 {
831 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper")); 817 jclass_ref helperClass (jni_env, find_octave_class (jni_env, "org/octave/ClassHelper"));
850 836
851 if (jni_env) 837 if (jni_env)
852 { 838 {
853 jclass_ref cls (jni_env, jni_env->GetObjectClass (jobj)); 839 jclass_ref cls (jni_env, jni_env->GetObjectClass (jobj));
854 jclass_ref ccls (jni_env, jni_env->GetObjectClass (cls)); 840 jclass_ref ccls (jni_env, jni_env->GetObjectClass (cls));
855 jmethodID getMethods_ID = jni_env->GetMethodID (ccls, "getMethods", "()[Ljava/lang/reflect/Method;"), 841 jmethodID getMethods_ID = jni_env->GetMethodID (ccls, "getMethods", "()[Ljava/lang/reflect/Method;");
856 getFields_ID = jni_env->GetMethodID (ccls, "getFields", "()[Ljava/lang/reflect/Field;"); 842 jmethodID getFields_ID = jni_env->GetMethodID (ccls, "getFields", "()[Ljava/lang/reflect/Field;");
857 jobjectArray_ref mList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getMethods_ID))), 843 jobjectArray_ref mList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getMethods_ID)));
858 fList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getFields_ID))); 844 jobjectArray_ref fList (jni_env, reinterpret_cast<jobjectArray> (jni_env->CallObjectMethod (cls, getFields_ID)));
859 int mLen = jni_env->GetArrayLength (mList), fLen = jni_env->GetArrayLength (fList); 845 int mLen = jni_env->GetArrayLength (mList);
860 jclass_ref mCls (jni_env, jni_env->FindClass ("java/lang/reflect/Method")), 846 int fLen = jni_env->GetArrayLength (fList);
861 fCls (jni_env, jni_env->FindClass ("java/lang/reflect/Field")); 847 jclass_ref mCls (jni_env, jni_env->FindClass ("java/lang/reflect/Method"));
862 jmethodID m_getName_ID = jni_env->GetMethodID (mCls, "getName", "()Ljava/lang/String;"), 848 jclass_ref fCls (jni_env, jni_env->FindClass ("java/lang/reflect/Field"));
863 f_getName_ID = jni_env->GetMethodID (fCls, "getName", "()Ljava/lang/String;"); 849 jmethodID m_getName_ID = jni_env->GetMethodID (mCls, "getName", "()Ljava/lang/String;");
850 jmethodID f_getName_ID = jni_env->GetMethodID (fCls, "getName", "()Ljava/lang/String;");
864 851
865 for (int i = 0; i < mLen; i++) 852 for (int i = 0; i < mLen; i++)
866 { 853 {
867 jobject_ref meth (jni_env, jni_env->GetObjectArrayElement (mList, i)); 854 jobject_ref meth (jni_env, jni_env->GetObjectArrayElement (mList, i));
868 jstring_ref methName (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (meth, m_getName_ID))); 855 jstring_ref methName (jni_env, reinterpret_cast<jstring> (jni_env->CallObjectMethod (meth, m_getName_ID)));
1241 && (val.rows () == 1 || val.columns () == 1)) 1228 && (val.rows () == 1 || val.columns () == 1))
1242 || val.is_range ())) 1229 || val.is_range ()))
1243 { 1230 {
1244 Matrix m = val.matrix_value (); 1231 Matrix m = val.matrix_value ();
1245 jdoubleArray dv = jni_env->NewDoubleArray (m.length ()); 1232 jdoubleArray dv = jni_env->NewDoubleArray (m.length ());
1246 //for (int i = 0; i < m.length (); i++) 1233 jni_env->SetDoubleArrayRegion (dv, 0, m.length (), m.fortran_vec ());
1247 jni_env->SetDoubleArrayRegion (dv, 0, m.length (), m.fortran_vec ());
1248 jobj = dv; 1234 jobj = dv;
1249 jcls = jni_env->GetObjectClass (jobj); 1235 jcls = jni_env->GetObjectClass (jobj);
1250 } 1236 }
1251 else if (Vjava_matrix_autoconversion 1237 else if (Vjava_matrix_autoconversion
1252 && (val.is_matrix_type () || val.is_range ()) && val.is_real_type ()) 1238 && (val.is_matrix_type () || val.is_range ()) && val.is_real_type ())
1747 return convert_to_string (current_env, to_java (), force, type); 1733 return convert_to_string (current_env, to_java (), force, type);
1748 else 1734 else
1749 return octave_value (""); 1735 return octave_value ("");
1750 } 1736 }
1751 1737
1738 void
1739 octave_java::print (std::ostream& os, bool) const
1740 {
1741 print_raw (os);
1742 newline (os);
1743 }
1744
1745 void
1746 octave_java::print_raw (std::ostream& os, bool) const
1747 {
1748 os << "<Java object: " << java_classname << ">";
1749 }
1750
1752 octave_value 1751 octave_value
1753 octave_java::do_javaMethod (JNIEnv* jni_env, const std::string& name, 1752 octave_java::do_javaMethod (JNIEnv* jni_env, const std::string& name,
1754 const octave_value_list& args) 1753 const octave_value_list& args)
1755 { 1754 {
1756 octave_value retval; 1755 octave_value retval;