diff src/ov-struct.cc @ 7046:fbf8576cf399

[project @ 2007-10-22 12:12:20 by dbateman]
author dbateman
date Mon, 22 Oct 2007 12:12:20 +0000
parents 1f16da18d85d
children 745a8299c2b5 eaaa74f38140
line wrap: on
line diff
--- a/src/ov-struct.cc	Mon Oct 22 11:52:39 2007 +0000
+++ b/src/ov-struct.cc	Mon Oct 22 12:12:20 2007 +0000
@@ -403,6 +403,68 @@
   return retval;
 }
 
+octave_value
+octave_struct::do_index_op (const octave_value_list& idx, bool resize_ok)
+{
+  octave_value retval;
+
+  octave_idx_type n_idx = idx.length ();
+
+  int nd = map.ndims ();
+
+  switch (n_idx)
+    {
+    case 0:
+      retval = map;
+      break;
+
+    case 1:
+      {
+	idx_vector i = idx (0).index_vector ();
+
+	if (! error_state)
+	  retval = map.index (i, resize_ok, Cell::resize_fill_value ());
+      }
+      break;
+
+    default:
+      {
+	if (n_idx == 2 && nd == 2)
+	  {
+	    idx_vector i = idx (0).index_vector ();
+
+	    if (! error_state)
+	      {
+		idx_vector j = idx (1).index_vector ();
+
+		if (! error_state)
+		  retval = map.index (i, j, resize_ok,
+				      Cell::resize_fill_value ());
+	      }
+	  }
+	else
+	  {
+	    Array<idx_vector> idx_vec (n_idx);
+
+	    for (octave_idx_type i = 0; i < n_idx; i++)
+	      {
+		idx_vec(i) = idx(i).index_vector ();
+
+		if (error_state)
+		  break;
+	      }
+
+	    if (! error_state)
+	      retval = map.index (idx_vec, resize_ok,
+				  Cell::resize_fill_value ());
+	  }
+      }
+      break;
+    }
+
+  return retval;
+}
+
 size_t
 octave_struct::byte_size (void) const
 {