changeset 15770:e61405133a76

Add new isjava function. * libinterp/octave-value/ov-base.h: Add new virtual function is_java (). Returns false. libinterp/octave-value/ov-java.h: Overload virtual function is_java to return true for objects in class octave_java. libinterp/octave-value/ov.h: Add is_java function that calls objects is_java function. * libinterp/octave-value/ov-java.cc: Add new DEFUN (isjava) which uses is_java. Placed outside HAVE_JAVA ifdef so that it is always available.
author Rik <rik@octave.org>
date Wed, 12 Dec 2012 13:15:31 -0800
parents eade542fedaa
children 4698ea77aa75
files libinterp/octave-value/ov-base.h libinterp/octave-value/ov-java.cc libinterp/octave-value/ov-java.h libinterp/octave-value/ov.h
diffstat 4 files changed, 26 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/octave-value/ov-base.h	Wed Dec 12 08:35:29 2012 -0800
+++ b/libinterp/octave-value/ov-base.h	Wed Dec 12 13:15:31 2012 -0800
@@ -365,6 +365,8 @@
 
   virtual bool is_object (void) const { return false; }
 
+  virtual bool is_java (void) const { return false; }
+
   virtual bool is_cs_list (void) const { return false; }
 
   virtual bool is_magic_colon (void) const { return false; }
--- a/libinterp/octave-value/ov-java.cc	Wed Dec 12 08:35:29 2012 -0800
+++ b/libinterp/octave-value/ov-java.cc	Wed Dec 12 13:15:31 2012 -0800
@@ -2209,3 +2209,22 @@
 
 #endif
 
+// Outside of #ifdef HAVE_JAVA because it is desirable to be able to
+// merely test for the presence of a Java object without having Java installed. 
+DEFUN (isjava, args, ,
+  "-*- texinfo -*-\n\
+@deftypefn {Built-in Function} {} isjava (@var{x})\n\
+Return true if @var{x} is a Java object.\n\
+@seealso{class, typeinfo, isa}\n\
+@end deftypefn")
+{
+  octave_value retval;
+
+  if (args.length () != 1)
+    print_usage ();
+  else
+    retval = args(0).is_java ();
+
+  return retval;
+}
+
--- a/libinterp/octave-value/ov-java.h	Wed Dec 12 08:35:29 2012 -0800
+++ b/libinterp/octave-value/ov-java.h	Wed Dec 12 13:15:31 2012 -0800
@@ -149,6 +149,8 @@
 
   bool is_map (void) const { return true; }
 
+  bool is_java (void) const { return true; }
+
   string_vector map_keys (void) const;
 
   dim_vector dims (void) const;
--- a/libinterp/octave-value/ov.h	Wed Dec 12 08:35:29 2012 -0800
+++ b/libinterp/octave-value/ov.h	Wed Dec 12 13:15:31 2012 -0800
@@ -563,6 +563,9 @@
   bool is_object (void) const
     { return rep->is_object (); }
 
+  bool is_java (void) const
+    { return rep->is_java (); }
+
   bool is_cs_list (void) const
     { return rep->is_cs_list (); }