changeset 2109:356f70c8fcbd

[project @ 1996-04-30 12:31:30 by jwe]
author jwe
date Tue, 30 Apr 1996 12:31:30 +0000
parents 2b67abb63030
children dece5cc39e00
files liboctave/Array.cc liboctave/Array.h liboctave/Array2.cc liboctave/Array2.h
diffstat 4 files changed, 56 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc	Tue Apr 30 10:44:44 1996 +0000
+++ b/liboctave/Array.cc	Tue Apr 30 12:31:30 1996 +0000
@@ -169,20 +169,19 @@
     }
   return rep->data;
 }
-
 template <class T>
 T
-Array<T>::range_error (void) const
+Array<T>::range_error (const char *fcn, int n) const
 {
-  (*current_liboctave_error_handler) ("range error");
+  (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n);
   return T ();
 }
 
 template <class T>
 T&
-Array<T>::range_error (void)
+Array<T>::range_error (const char *fcn, int n)
 {
-  (*current_liboctave_error_handler) ("range error");
+  (*current_liboctave_error_handler) ("%s (%d): range error", fcn, n);
   static T foo;
   return foo;
 }
--- a/liboctave/Array.h	Tue Apr 30 10:44:44 1996 +0000
+++ b/liboctave/Array.h	Tue Apr 30 12:31:30 1996 +0000
@@ -31,8 +31,6 @@
 #include <cassert>
 #include <cstdlib>
 
-#include "lo-error.h"
-
 class idx_vector;
 
 // For now, define this here if it is not already defined.  Not doing
@@ -176,11 +174,7 @@
   T& Array<T>::checkelem (int n)
     {
       if (n < 0 || n >= rep->length ())
-	{
-	  (*current_liboctave_error_handler) ("range error");
-	  static T foo;
-	  return foo;
-	}
+	return range_error ("T& Array<T>::checkelem", n);
       else
 	{
 	  make_unique ();
@@ -194,7 +188,7 @@
   T& elem (int n)
     {
       make_unique ();
-      return xelem ();
+      return xelem (n);
     }
 #endif
 
@@ -203,7 +197,7 @@
   T Array<T>::checkelem (int n) const
     {
       if (n < 0 || n >= rep->length ())
-	return range_error ();
+	return range_error ("T Array<T>::checkelem", n);
       else
 	return xelem (n);
     }
@@ -236,8 +230,8 @@
       return *this;
     }
 
-  T range_error (void) const;
-  T& range_error (void);
+  T range_error (const char *fcn, int n) const;
+  T& range_error (const char *fcn, int n);
 
 #ifdef HEAVYWEIGHT_INDEXING
   void set_max_indices (int mi) { max_indices = mi; }
--- a/liboctave/Array2.cc	Tue Apr 30 10:44:44 1996 +0000
+++ b/liboctave/Array2.cc	Tue Apr 30 12:31:30 1996 +0000
@@ -42,6 +42,25 @@
 
 #include "lo-error.h"
 
+template <class T>
+T
+Array2<T>::range_error (const char *fcn, int i, int j) const
+{
+  (*current_liboctave_error_handler)
+    ("%s (%d, %d): range error", fcn, i, j);
+  return T ();
+}
+
+template <class T>
+T&
+Array2<T>::range_error (const char *fcn, int i, int j)
+{
+  (*current_liboctave_error_handler)
+    ("%s (%d, %d): range error", fcn, i, j);
+  static T foo;
+  return foo;
+}
+
 // Two dimensional array class.
 
 template <class T>
@@ -50,7 +69,8 @@
 {
   if (r < 0 || c < 0)
     {
-      (*current_liboctave_error_handler) ("can't resize to negative dimension");
+      (*current_liboctave_error_handler)
+	("can't resize to negative dimension");
       return;
     }
 
@@ -89,7 +109,8 @@
 {
   if (r < 0 || c < 0)
     {
-      (*current_liboctave_error_handler) ("can't resize to negative dimension");
+      (*current_liboctave_error_handler)
+	("can't resize to negative dimension");
       return;
     }
 
--- a/liboctave/Array2.h	Tue Apr 30 10:44:44 1996 +0000
+++ b/liboctave/Array2.h	Tue Apr 30 12:31:30 1996 +0000
@@ -115,51 +115,60 @@
   int cols (void) const { return d2; }
   int columns (void) const { return d2; }
 
-  T& elem (int i, int j) { return Array<T>::elem (d1*j+i); }
+  // No checking of any kind, ever.
+
+  T& xelem (int i, int j) { return Array<T>::xelem (d1*j+i); }
+  T xelem (int i, int j) const { return Array<T>::xelem (d1*j+i); }
+
+  // Note that the following element references don't use
+  // Array2<T>::xelem() because they still need to make use of the
+  // code in Array<T> that checks the reference count.
 
   T& checkelem (int i, int j)
     {
       if (i < 0 || j < 0 || i >= d1 || j >= d2)
 	{
-	  (*current_liboctave_error_handler) ("range error");
+	  (*current_liboctave_error_handler)
+	    ("T& Array2<T>::checkelem (%d, %d): range error", i, j);
 	  static T foo;
 	  return foo;
 	}
       else
-	return elem (i, j);
+	return Array<T>::elem (d1*j+i);
     }
 
-#if defined (NO_BOUNDS_CHECKING)
-  T& operator () (int i, int j) { return elem (i, j); }
+#if defined (BOUNDS_CHECKING)
+  T& elem (int i, int j) { return checkelem (i, j); }
 #else
-  T& operator () (int i, int j) { return checkelem (i, j); }
+  T& elem (int i, int j) { return Array<T>::elem (d1*j+i); }
 #endif
 
-  T elem (int i, int j) const { return Array<T>::elem (d1*j+i); }
+  T& operator () (int i, int j) { return elem (i, j); }
 
   T checkelem (int i, int j) const
     {
       if (i < 0 || j < 0 || i >= d1 || j >= d2)
 	{
-	  (*current_liboctave_error_handler) ("range error");
+	  (*current_liboctave_error_handler)
+	    ("T Array2<T>::checkelem (%d, %d): range error", i, j);
 	  T foo;
 	  static T *bar = &foo;
 	  return foo;
 	}
       else
-	return elem (i, j);
+	return Array<T>::elem (d1*j+i);
     }
 
-#if defined (NO_BOUNDS_CHECKING)
-  T operator () (int i, int j) const { return elem (i, j); }
+#if defined (BOUNDS_CHECKING)
+  T elem (int i, int j) const { return checkelem (i, j); }
 #else
-  T operator () (int i, int j) const { return checkelem (i, j); }
+  T elem (int i, int j) const { return Array<T>::elem (d1*j+i); }
 #endif
 
-  // No checking of any kind, ever.
+  T operator () (int i, int j) const { return elem (i, j); }
 
-  T& xelem (int i, int j) { return Array<T>::xelem (d1*j+i); }
-  T xelem (int i, int j) const { return Array<T>::xelem (d1*j+i); }
+  T range_error (const char *fcn, int i, int j) const;
+  T& range_error (const char *fcn, int i, int j);
 
   void resize (int n, int m);
   void resize (int n, int m, const T& val);