00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #if !defined (octave_Array2_h)
00025 #define octave_Array2_h 1
00026
00027 #if defined (__GNUG__) && defined (USE_PRAGMA_INTERFACE_IMPLEMENTATION)
00028 #pragma interface
00029 #endif
00030
00031 #include <cassert>
00032 #include <climits>
00033 #include <cmath>
00034 #include <cstdlib>
00035
00036 #include "Array.h"
00037 #include "lo-error.h"
00038
00039 class idx_vector;
00040
00041
00042
00043 template <class T>
00044 class
00045 Array2 : public Array<T>
00046 {
00047 protected:
00048
00049 static int get_size (int r, int c) { return Array<T>::get_size (r, c); }
00050
00051 Array2 (T *d, int r, int c) : Array<T> (d, dim_vector (r, c)) { }
00052
00053 public:
00054
00055 Array2 (void) : Array<T> (dim_vector (0, 0)) { }
00056
00057 Array2 (int r, int c) : Array<T> (dim_vector (r, c)) { }
00058
00059 Array2 (int r, int c, const T& val)
00060 : Array<T> (dim_vector (r, c), val) { }
00061
00062 Array2 (const Array2<T>& a) : Array<T> (a, a.dims ()) { }
00063
00064 Array2 (const Array<T>& a, int r, int c)
00065 : Array<T> (a, dim_vector (r, c)) { }
00066
00067 ~Array2 (void) { }
00068
00069 Array2<T>& operator = (const Array2<T>& a)
00070 {
00071 if (this != &a)
00072 Array<T>::operator = (a);
00073
00074 return *this;
00075 }
00076
00077 void resize (int r, int c) { this->resize_no_fill (r, c); }
00078
00079 void resize (int r, int c, const T& val)
00080 { this->resize_and_fill (r, c, val); }
00081
00082 Array2<T>& insert (const Array2<T>& a, int r, int c)
00083 {
00084 Array<T>::insert (a, r, c);
00085 return *this;
00086 }
00087
00088 Array2<T> transpose (void) const
00089 {
00090 Array<T> tmp = Array<T>::transpose ();
00091 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00092 }
00093
00094 Array2<T> index (idx_vector& i, int resize_ok = 0,
00095 const T& rfv = resize_fill_value (T ())) const
00096 {
00097 Array<T> tmp = Array<T>::index (i, resize_ok, rfv);
00098 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00099 }
00100
00101 Array2<T> index (idx_vector& i, idx_vector& j, int resize_ok = 0,
00102 const T& rfv = resize_fill_value (T ())) const
00103 {
00104 Array<T> tmp = Array<T>::index (i, j, resize_ok, rfv);
00105 return Array2<T> (tmp, tmp.rows (), tmp.columns ());
00106 }
00107 };
00108
00109 #endif
00110
00111
00112
00113
00114
00115