changeset 3724:3dfae66ad67c

[project @ 2000-10-12 05:45:11 by jwe]
author jwe
date Thu, 12 Oct 2000 05:45:12 +0000
parents 4c3774db5b3c
children 7d2d642cbb53
files src/ChangeLog src/ov-cell.h src/pt-select.cc
diffstat 3 files changed, 68 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Thu Oct 12 05:10:09 2000 +0000
+++ b/src/ChangeLog	Thu Oct 12 05:45:12 2000 +0000
@@ -1,3 +1,11 @@
+2000-10-12  Paul Kienzle  <pkienzle@kienzle.powernet.co.uk>
+
+	* ov-cell.h (octave_cell::is_cell): New function.
+
+	* pt-select.cc (equal): New static function.
+	(tree_switch_case::label_matches): Use it to compare case label
+	against arg.  Handle cell arrays as case labels.
+
 2000-10-12  John W. Eaton  <jwe@bevo.che.wisc.edu>
 
 	Change patterned after patch by Cai Jianming
--- a/src/ov-cell.h	Thu Oct 12 05:10:09 2000 +0000
+++ b/src/ov-cell.h	Thu Oct 12 05:45:12 2000 +0000
@@ -74,6 +74,8 @@
 
   bool is_constant (void) const { return true; }
 
+  bool is_cell (void) const { return true; }
+
   Cell cell_value (void) const { return cell_val; }
 
   void print (std::ostream& os, bool pr_as_read_syntax = false) const;
--- a/src/pt-select.cc	Thu Oct 12 05:10:09 2000 +0000
+++ b/src/pt-select.cc	Thu Oct 12 05:45:12 2000 +0000
@@ -36,6 +36,8 @@
 #include "pt-select.h"
 #include "pt-stmt.h"
 #include "pt-walk.h"
+#include "Cell.h"
+#include "ov-typeinfo.h"
 
 // If clauses.
 
@@ -121,37 +123,78 @@
   delete lead_comm;
 }
 
-bool
-tree_switch_case::label_matches (const octave_value& val)
+
+// Compare two octave values, returning true if equal, false if not
+// XXX FIXME XXX --- should be member or friend of octave_value class.
+
+static bool
+equal (const octave_value& val, const octave_value& test)
 {
   bool retval = false;
 
+  int t1 = val.type_id ();
+  int t2 = test.type_id ();
+
+  binary_op_fcn f
+    = octave_value_typeinfo::lookup_binary_op (octave_value::op_eq, t1, t2);
+
+  // If there is no op_eq for these types, we can't compare values.
+
+  if (f && val.rows () == test.rows () && val.columns () == test.columns ())
+    {
+      octave_value tmp = do_binary_op (octave_value::op_eq, val, test);
+
+      if (! error_state && tmp.is_defined ())
+	retval = tmp.is_true ();
+    }
+
+  return retval;
+}
+
+bool
+tree_switch_case::label_matches (const octave_value& val)
+{
   octave_value label_value = label->rvalue ();
 
-  if (! error_state)
+  if (! error_state && label_value.is_defined() )
     {
-      if (label_value.is_defined ())
+      if (label_value.is_cell ())
 	{
-	  octave_value tmp = do_binary_op (octave_value::op_eq,
-					   val, label_value);
+	  Cell cell (label_value.cell_value ());
+
+	  for (int i = 0; i < cell.rows (); i++)
+	    {
+	      for (int j = 0; j < cell.columns (); j++)
+		{
+		  bool match = equal (val, cell(i,j));
 
-	  if (! error_state)
+		  if (error_state)
+		    {
+		      eval_error ();
+		      return false;
+		    }
+		  else if (match)
+		    return true;
+		}
+	    }
+	}
+      else
+	{
+	  bool match = equal (val, label_value);
+
+	  if (error_state)
 	    {
-	      if (tmp.is_defined ())
-		retval = tmp.is_true ();
-	      else
-		eval_error ();
+	      eval_error ();
+	      return false;
 	    }
 	  else
-	    eval_error ();
+	    return match;
 	}
-      else
-	eval_error ();
     }
   else
     eval_error ();
 
-  return retval;
+  return false;
 }
 
 int