Mercurial > hg > octave-terminal
changeset 1735:d2ee993d40cd
[project @ 1996-01-12 07:46:09 by jwe]
author | jwe |
---|---|
date | Fri, 12 Jan 1996 07:48:03 +0000 |
parents | d0e2735fcaec |
children | e1ebb2808140 |
files | liboctave/Array-C.cc liboctave/Array-ch.cc liboctave/Array-d.cc liboctave/Array-i.cc liboctave/Array-idx.h liboctave/Array-s.cc liboctave/Array.cc liboctave/Array.h |
diffstat | 8 files changed, 56 insertions(+), 113 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array-C.cc +++ b/liboctave/Array-C.cc @@ -28,7 +28,6 @@ #include "oct-cmplx.h" -template class ArrayRep<Complex>; template class Array<Complex>; template class Array2<Complex>; template class DiagArray<Complex>;
--- a/liboctave/Array-ch.cc +++ b/liboctave/Array-ch.cc @@ -28,7 +28,6 @@ #include "Array.h" #include "Array.cc" -template class ArrayRep<char>; template class Array<char>; template class Array2<char>;
--- a/liboctave/Array-d.cc +++ b/liboctave/Array-d.cc @@ -26,7 +26,6 @@ #include "Array.h" #include "Array.cc" -template class ArrayRep<double>; template class Array<double>; template class Array2<double>; template class DiagArray<double>;
--- a/liboctave/Array-i.cc +++ b/liboctave/Array-i.cc @@ -28,7 +28,6 @@ #include "Array.h" #include "Array.cc" -template class ArrayRep<int>; template class Array<int>; template class Array2<int>;
--- a/liboctave/Array-idx.h +++ b/liboctave/Array-idx.h @@ -151,7 +151,7 @@ if (--rep->count <= 0) delete rep; - rep = new ArrayRep<T> (new_data, new_len); + rep = new ArrayRep (new_data, new_len); set_max_indices (1); } @@ -433,7 +433,7 @@ if (--rep->count <= 0) delete rep; - rep = new ArrayRep<T> (new_data, nr * new_nc); + rep = new ArrayRep (new_data, nr * new_nc); d2 = new_nc; @@ -482,7 +482,7 @@ if (--rep->count <= 0) delete rep; - rep = new ArrayRep<T> (new_data, new_nr * nc); + rep = new ArrayRep (new_data, new_nr * nc); d1 = new_nr;
--- a/liboctave/Array-s.cc +++ b/liboctave/Array-s.cc @@ -28,7 +28,6 @@ #include "Array.h" #include "Array.cc" -template class ArrayRep<short>; template class Array<short>; template class Array2<short>;
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -42,54 +42,13 @@ #include "lo-error.h" -// The real representation of all arrays. - -template <class T> -ArrayRep<T>::ArrayRep (int n) -{ - len = n; - count = 1; - data = new T [len]; -} - -template <class T> -ArrayRep<T>::ArrayRep (const ArrayRep<T>& a) -{ - len = a.len; - count = 1; - - data = new T [len]; - for (int i = 0; i < len; i++) - data[i] = a.data[i]; -} - -template <class T> -ArrayRep<T>::~ArrayRep (void) -{ - delete [] data; -} - -template <class T> -T& -ArrayRep<T>::elem (int n) -{ - return data[n]; -} - -template <class T> -T -ArrayRep<T>::elem (int n) const -{ - return data[n]; -} - // One dimensional array class. Handles the reference counting for // all the derived classes. template <class T> Array<T>::Array (int n, const T& val) { - rep = new ArrayRep<T> (n); + rep = new ArrayRep (n); for (int i = 0; i < n; i++) rep->data[i] = val; @@ -188,11 +147,11 @@ if (n == length ()) return; - ArrayRep<T> *old_rep = rep; + ArrayRep *old_rep = rep; const T *old_data = data (); int old_len = length (); - rep = new ArrayRep<T> (n); + rep = new ArrayRep (n); if (old_data && old_len > 0) { @@ -219,11 +178,11 @@ if (n == length ()) return; - ArrayRep<T> *old_rep = rep; + ArrayRep *old_rep = rep; const T *old_data = data (); int old_len = length (); - rep = new ArrayRep<T> (n); + rep = new ArrayRep (n); int min_len = old_len < n ? old_len : n; @@ -247,7 +206,7 @@ if (rep->count > 1) { --rep->count; - rep = new ArrayRep<T> (*rep); + rep = new ArrayRep (*rep); } return rep->data; } @@ -315,14 +274,14 @@ if (r == dim1 () && c == dim2 ()) return; - ArrayRep<T> *old_rep = rep; + ArrayRep *old_rep = rep; const T *old_data = data (); int old_d1 = dim1 (); int old_d2 = dim2 (); int old_len = length (); - rep = new ArrayRep<T> (r*c); + rep = new ArrayRep (r*c); d1 = r; d2 = c; @@ -354,13 +313,13 @@ if (r == dim1 () && c == dim2 ()) return; - ArrayRep<T> *old_rep = rep; + ArrayRep *old_rep = rep; const T *old_data = data (); int old_d1 = dim1 (); int old_d2 = dim2 (); int old_len = length (); - rep = new ArrayRep<T> (r*c); + rep = new ArrayRep (r*c); d1 = r; d2 = c; @@ -566,13 +525,13 @@ if (r == dim1 () && c == dim2 ()) return; - ArrayRep<T> *old_rep = rep; + ArrayRep *old_rep = rep; const T *old_data = data (); int old_len = length (); int new_len = r < c ? r : c; - rep = new ArrayRep<T> (new_len); + rep = new ArrayRep (new_len); nr = r; nc = c; @@ -602,13 +561,13 @@ if (r == dim1 () && c == dim2 ()) return; - ArrayRep<T> *old_rep = rep; + ArrayRep *old_rep = rep; const T *old_data = data (); int old_len = length (); int new_len = r < c ? r : c; - rep = new ArrayRep<T> (new_len); + rep = new ArrayRep (new_len); nr = r; nc = c;
--- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -38,7 +38,6 @@ // Classes we declare. -template <class T> class ArrayRep; template <class T> class Array; template <class T> class Array2; template <class T> class Array3; @@ -47,50 +46,6 @@ template <class T> class DiagArray; #endif -// The real representation of all arrays. - -template <class T> -class ArrayRep -{ - // Rethink resize()? - - friend class Array<T>; - friend class Array2<T>; - friend class Array3<T>; - -#ifndef NO_DIAG_ARRAY - friend class DiagArray<T>; -#endif - -private: - - T *data; - int len; - int count; - - ArrayRep<T>& operator = (const ArrayRep<T>& a); - -protected: - - ArrayRep (T *d, int l) : data (d), len (l), count (1) { } - -public: - - ArrayRep (void) : data (0), len (0), count (1) { } - - ArrayRep (int n); - - ArrayRep (const ArrayRep<T>& a); - - ~ArrayRep (void); - - int length (void) const { return len; } - - T& elem (int n); - - T elem (int n) const; -}; - // One dimensional array class. Handles the reference counting for // all the derived classes. @@ -99,6 +54,40 @@ { private: +// The real representation of all arrays. + + class ArrayRep + { + public: + + T *data; + int len; + int count; + + ArrayRep& operator = (const ArrayRep& a); + + ArrayRep (T *d, int l) : data (d), len (l), count (1) { } + + ArrayRep (void) : data (0), len (0), count (1) { } + + ArrayRep (int n) : data (new T [n]), len (n), count (1) { } + + ArrayRep (const ArrayRep& a) + : data (new T [a.len]), len (a.len), count (1) + { + for (int i = 0; i < len; i++) + data[i] = a.data[i]; + } + + ~ArrayRep (void) { delete [] data; } + + int length (void) const { return len; } + + T& elem (int n) { return data[n]; } + + T elem (int n) const { return data[n]; } + }; + #ifdef HEAVYWEIGHT_INDEXING idx_vector *idx; int max_indices; @@ -107,11 +96,11 @@ protected: - ArrayRep<T> *rep; + ArrayRep *rep; Array (T *d, int l) { - rep = new ArrayRep<T> (d, l); + rep = new ArrayRep (d, l); #ifdef HEAVYWEIGHT_INDEXING idx = 0; @@ -124,7 +113,7 @@ Array (void) { - rep = new ArrayRep<T> (); + rep = new ArrayRep (); #ifdef HEAVYWEIGHT_INDEXING idx = 0; @@ -135,7 +124,7 @@ Array (int n) { - rep = new ArrayRep<T> (n); + rep = new ArrayRep (n); #ifdef HEAVYWEIGHT_INDEXING idx = 0; @@ -170,7 +159,7 @@ if (rep->count > 1) { --rep->count; - rep = new ArrayRep<T> (*rep); + rep = new ArrayRep (*rep); } return rep->elem (n); }