[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Easy way to interpret octave_value as XXX?
From: |
John W. Eaton |
Subject: |
Re: Easy way to interpret octave_value as XXX? |
Date: |
Tue, 18 Dec 2012 11:54:42 -0500 |
On 18-Dec-2012, Rik wrote:
| I used Michael's solution here
| (http://hg.savannah.gnu.org/hgweb/octave/rev/317f4857c1e1). I was
| modifying class() to return the true Java class name rather than merely
| "octave_java". It was a one-liner call to jobj->java_class_name () as soon
| as I actually had it coerced into the correct class.
For this particular case, there is already an octave_value::class_name
method that forwards to rep->class_name. So I would do something like
the attached patch so that octave_java::class_name will work much like
octave_class:class_name.
Maybe we should also deprecate "java_class_name" in favor of using
"class_name"?
jwe
diff --git a/libinterp/octave-value/ov-class.cc
b/libinterp/octave-value/ov-class.cc
--- 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
diff --git a/libinterp/octave-value/ov-java.cc
b/libinterp/octave-value/ov-java.cc
--- a/libinterp/octave-value/ov-java.cc
+++ b/libinterp/octave-value/ov-java.cc
@@ -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
diff --git a/libinterp/octave-value/ov-java.h b/libinterp/octave-value/ov-java.h
--- a/libinterp/octave-value/ov-java.h
+++ b/libinterp/octave-value/ov-java.h
@@ -312,15 +312,27 @@
private:
- DECLARE_OCTAVE_ALLOCATOR
-
- DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA
-
jobject java_object;
jclass java_class;
std::string java_type;
+
+ 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_class_name (); }
+
+ 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