Mercurial > hg > octave-nkf
changeset 15813:10d6ab9b1b4f
Implement octave_value function class_name() for class "octave_java"
* libinterp/octave-value/ov-class.cc(Fclass): Remove special code
for Java objects; Just call class_name() on octave_value object.
* libinterp/octave-value/ov-java.h: Declare octave_value type functions.
Rename confusing octave_java class private variable java_type to
java_classname.
* libinterp/octave-value/ov-java.cc: Replace tests for Java object
from class_name() == "octave_java" to is_java().
author | Rik <rik@octave.org> |
---|---|
date | Tue, 18 Dec 2012 10:29:51 -0800 |
parents | 83bf6fd9e46d |
children | 1eee8d8c59fd |
files | libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-java.cc libinterp/octave-value/ov-java.h |
diffstat | 3 files changed, 37 insertions(+), 24 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/octave-value/ov-class.cc +++ b/libinterp/octave-value/ov-class.cc @@ -1942,15 +1942,7 @@ print_usage (); else if (nargin == 1) // Called for class of object - if (! args(0).is_java ()) - retval = args(0).class_name (); - else - { -#ifdef HAVE_JAVA - octave_java *jobj = dynamic_cast<octave_java*>(args(0).internal_rep ()); - retval = jobj->java_class_name (); -#endif - } + retval = args(0).class_name (); else { // Called as class constructor
--- a/libinterp/octave-value/ov-java.cc +++ b/libinterp/octave-value/ov-java.cc @@ -1063,7 +1063,7 @@ { octave_value retval = box (jni_env, jobj, jcls); - if (retval.class_name () == "octave_java") + if (retval.is_java ()) { retval = octave_value (); @@ -1153,7 +1153,7 @@ { int found = 1; - if (val.class_name () == "octave_java") + if (val.is_java ()) { octave_java *ovj = TO_JAVA (val); jobj = ovj->to_java (); @@ -1514,7 +1514,16 @@ DEFINE_OCTAVE_ALLOCATOR (octave_java); -DEFINE_OV_TYPEID_FUNCTIONS_AND_DATA (octave_java, "octave_java", "octave_java"); +int octave_java::t_id (-1); + +const std::string octave_java::t_name ("octave_java"); + +void +octave_java::register_type (void) +{ + t_id = octave_value_typeinfo::register_type + (octave_java::t_name, "<unknown>", octave_value (new octave_java ())); +} dim_vector octave_java::dims (void) const @@ -1978,7 +1987,7 @@ for (int i=2; i<args.length (); i++) tmp(i-2) = args(i); - if (args(1).class_name () == "octave_java") + if (args(1).is_java ()) { octave_java *jobj = TO_JAVA (args(1)); retval = jobj->do_javaMethod (current_env, methodname, tmp); @@ -2040,7 +2049,7 @@ std::string name = args(1).string_value (); if (! error_state) { - if (args(0).class_name () == "octave_java") + if (args(0).is_java ()) { octave_java *jobj = TO_JAVA (args(0)); retval = jobj->do_java_get (current_env, name); @@ -2102,7 +2111,7 @@ std::string name = args(1).string_value (); if (! error_state) { - if (args(0).class_name () == "octave_java") + if (args(0).is_java ()) { octave_java *jobj = TO_JAVA (args(0)); retval = jobj->do_java_set (current_env, name, args(2)); @@ -2146,7 +2155,7 @@ if (args.length () == 1) { - if (args(0).class_name () == "octave_java") + if (args(0).is_java ()) { octave_java *jobj = TO_JAVA (args(0)); retval(0) = box_more (current_env, jobj->to_java (), 0);
--- a/libinterp/octave-value/ov-java.h +++ b/libinterp/octave-value/ov-java.h @@ -140,7 +140,7 @@ jobject to_java (void) const { return java_object; } jclass to_class (void) const { return java_class; } - std::string java_class_name (void) const { return java_type; } + std::string java_class_name (void) const { return java_classname; } octave_base_value* clone (void) const { return new octave_java (*this); } octave_base_value* empty_clone (void) const { return new octave_java (); } @@ -157,7 +157,7 @@ void print (std::ostream& os, bool pr_as_read_syntax = false) const { - os << "<Java object: " << java_type << ">"; + os << "<Java object: " << java_classname << ">"; newline(os); } @@ -288,7 +288,7 @@ jclass_ref clsCls (current_env, current_env->GetObjectClass (java_class)); jmethodID mID = current_env->GetMethodID (clsCls, "getCanonicalName", "()Ljava/lang/String;"); jobject_ref resObj (current_env, current_env->CallObjectMethod (java_class, mID)); - java_type = jstring_to_string (current_env, resObj); + java_classname = jstring_to_string (current_env, resObj); } } } @@ -312,15 +312,27 @@ private: - DECLARE_OCTAVE_ALLOCATOR - - DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA - jobject java_object; jclass java_class; - std::string java_type; + std::string java_classname; + + DECLARE_OCTAVE_ALLOCATOR + +public: + int type_id (void) const { return t_id; } + std::string type_name (void) const { return t_name; } + std::string class_name (void) const { return java_classname; } + + static int static_type_id (void) { return t_id; } + static std::string static_type_name (void) { return t_name; } + static std::string static_class_name (void) { return "<unknown>"; } + static void register_type (void); + +private: + static int t_id; + static const std::string t_name; }; #endif