diff liboctave/DiagArray2.h @ 10363:a0728e81ed25

improve diag matrix interface & implementation
author Jaroslav Hajek <highegg@gmail.com>
date Fri, 26 Feb 2010 11:44:38 +0100
parents b47ab50a6aa8
children 96ed7c629bbd
line wrap: on
line diff
--- a/liboctave/DiagArray2.h
+++ b/liboctave/DiagArray2.h
@@ -30,19 +30,6 @@
 #include <cstdlib>
 
 #include "Array.h"
-#include "lo-error.h"
-
-// A two-dimensional array with diagonal elements only.
-// Idea and example code for Proxy class and functions from:
-//
-// From: kanze@us-es.sel.de (James Kanze)
-// Subject: Re: How to overload [] to do READ/WRITE differently ?
-// Message-ID: <KANZE.93Nov29151407@slsvhdt.us-es.sel.de>
-// Sender: news@us-es.sel.de
-// Date: 29 Nov 1993 14:14:07 GMT
-// --
-// James Kanze                             email: kanze@us-es.sel.de
-// GABI Software, Sarl., 8 rue du Faisan, F-67000 Strasbourg, France
 
 // Array<T> is inherited privately so that some methods, like index, don't
 // produce unexpected results.
@@ -51,40 +38,6 @@
 class
 DiagArray2 : protected Array<T>
 {
-private:
-
-  T get (octave_idx_type i) { return Array<T>::xelem (i); }
-
-  void set (const T& val, octave_idx_type i) { Array<T>::xelem (i) = val; }
-
-  class Proxy
-  {
-  public:
-
-    Proxy (DiagArray2<T> *ref, octave_idx_type r, octave_idx_type c)
-      : i (r), j (c), object (ref) { } 
-
-    const Proxy& operator = (const T& val) const;
-
-    operator T () const;
-
-  private:
-
-    // FIXME -- this is declared private to keep the user from
-    // taking the address of a Proxy.  Maybe it should be implemented
-    // by means of a companion function in the DiagArray2 class.
-
-    T *operator& () const { assert (0); return 0; }
-
-    octave_idx_type i;
-    octave_idx_type j;
-
-    DiagArray2<T> *object;
-
-  };
-
-  friend class Proxy;
-
 protected:
   octave_idx_type d1, d2;
 
@@ -104,18 +57,10 @@
   DiagArray2 (octave_idx_type r, octave_idx_type c, const T& val) 
     : Array<T> (std::min (r, c), 1, val), d1 (r), d2 (c) { }
 
-  DiagArray2 (const dim_vector& dv)
-    : Array<T> (std::min (dv(0), dv(1)), 1), d1 (dv(0)), d2 (dv(0))
-    {
-      if (dv.length () != 2)
-        (*current_liboctave_error_handler) ("too many dimensions");
-    }
-
-  DiagArray2 (const Array<T>& a) 
+  explicit DiagArray2 (const Array<T>& a) 
     : Array<T> (a.as_column ()), d1 (a.numel ()), d2 (a.numel ()) { }
 
-  DiagArray2 (const Array<T>& a, octave_idx_type r, octave_idx_type c) 
-    : Array<T> (a.as_column ()), d1 (r), d2 (c) { }
+  DiagArray2 (const Array<T>& a, octave_idx_type r, octave_idx_type c);
 
   DiagArray2 (const DiagArray2<T>& a) 
     : Array<T> (a), d1 (a.d1), d2 (a.d2) { }
@@ -178,7 +123,6 @@
     { return Array<T>::elem (i); }
 
   T checkelem (octave_idx_type r, octave_idx_type c) const;
-  Proxy checkelem (octave_idx_type r, octave_idx_type c);
 
   T operator () (octave_idx_type r, octave_idx_type c) const
     {
@@ -189,19 +133,6 @@
 #endif
     }
 
-  // FIXME: can this cause problems?
-#if defined (BOUNDS_CHECKING)
-  Proxy operator () (octave_idx_type r, octave_idx_type c)
-    {
-      return checkelem (r, c);
-    }
-#else
-  T& operator () (octave_idx_type r, octave_idx_type c) 
-    {
-      return elem (r, c);
-    }
-#endif
-
   // No checking.
 
   T xelem (octave_idx_type r, octave_idx_type c) const
@@ -221,7 +152,7 @@
   DiagArray2<T> transpose (void) const;
   DiagArray2<T> hermitian (T (*fcn) (const T&) = 0) const;
 
-  operator Array<T> (void) const;
+  Array<T> array_value (void) const;
 
   const T *data (void) const { return Array<T>::data (); }