Mercurial > hg > octave-nkf
changeset 1619:1a35c8c91349
[project @ 1995-11-04 11:07:21 by jwe]
author | jwe |
---|---|
date | Sat, 04 Nov 1995 11:07:21 +0000 |
parents | 9c1fca4bd859 |
children | 43df82dfb1f7 |
files | liboctave/Array-idx.h liboctave/Array.cc liboctave/Array.h |
diffstat | 3 files changed, 72 insertions(+), 83 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array-idx.h +++ b/liboctave/Array-idx.h @@ -21,6 +21,7 @@ */ +#include "error.h" #include "idx-vector.h" #include "lo-error.h" @@ -38,8 +39,10 @@ template <class T> void -ArrayRep<T>::clear_index (void) +Array<T>::clear_index (void) { + cerr << "clearing index for " << this << "\n"; + delete [] idx; idx = 0; idx_count = 0; @@ -47,8 +50,10 @@ template <class T> void -ArrayRep<T>::set_index (const idx_vector& i) +Array<T>::set_index (const idx_vector& i) { + cerr << "setting index for " << this << "\n"; + if (! idx) idx = new idx_vector [max_indices]; @@ -60,6 +65,7 @@ { (*current_liboctave_error_handler) ("invalid number of indices specified"); + clear_index (); } }
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -49,12 +49,6 @@ { len = n; data = new T [len]; - -#ifdef HEAVYWEIGHT_INDEXING - idx = 0; - max_indices = 0; - idx_count = 0; -#endif } template <class T> @@ -66,26 +60,12 @@ data = new T [len]; for (int i = 0; i < len; i++) data[i] = a.data[i]; - -#ifdef HEAVYWEIGHT_INDEXING - max_indices = a.max_indices; - idx_count = a.idx_count; - if (a.idx) - { - idx_vector *idx = new idx_vector [max_indices]; - for (int i = 0; i < max_indices; i++) - idx[i] = a.idx[i]; - } - else - idx = 0; -#endif } template <class T> ArrayRep<T>::~ArrayRep (void) { delete [] data; - delete [] idx; } template <class T> @@ -109,9 +89,28 @@ Array<T>::Array (int n, const T& val) { rep = new ArrayRep<T> (n); + rep->count = 1; + for (int i = 0; i < n; i++) rep->data[i] = val; + +#ifdef HEAVYWEIGHT_INDEXING + max_indices = 1; + idx_count = 0; + idx = 0; +#endif +} + +template <class T> +Array<T>::~Array (void) +{ + if (--rep->count <= 0) + delete rep; + +#ifdef HEAVYWEIGHT_INDEXING + delete [] idx; +#endif } template <class T> @@ -126,6 +125,13 @@ rep = a.rep; rep->count++; } + +#ifdef HEAVYWEIGHT_INDEXING + max_indices = 1; + idx_count = 0; + idx = 0; +#endif + return *this; } @@ -190,8 +196,6 @@ rep = new ArrayRep<T> (n); rep->count = 1; - SET_MAX_INDICES (1); - if (old_data && old_len > 0) { int min_len = old_len < n ? old_len : n; @@ -224,8 +228,6 @@ rep = new ArrayRep<T> (n); rep->count = 1; - SET_MAX_INDICES (1); - int min_len = old_len < n ? old_len : n; if (old_data && old_len > 0) @@ -327,8 +329,6 @@ rep = new ArrayRep<T> (r*c); rep->count = 1; - SET_MAX_INDICES (2); - d1 = r; d2 = c; @@ -368,8 +368,6 @@ rep = new ArrayRep<T> (r*c); rep->count = 1; - SET_MAX_INDICES (2); - d1 = r; d2 = c; @@ -583,8 +581,6 @@ rep = new ArrayRep<T> (new_len); rep->count = 1; - SET_MAX_INDICES (2); - nr = r; nc = c; @@ -622,8 +618,6 @@ rep = new ArrayRep<T> (new_len); rep->count = 1; - SET_MAX_INDICES (2); - nr = r; nc = c;
--- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -47,12 +47,6 @@ template <class T> class DiagArray; #endif -#ifdef HEAVYWEIGHT_INDEXING -#define SET_MAX_INDICES(n) set_max_indices (n) -#else -#define SET_MAX_INDICES(n) -#endif - // The real representation of all arrays. template <class T> @@ -74,24 +68,12 @@ int count; int len; -#ifdef HEAVYWEIGHT_INDEXING - idx_vector *idx; - int max_indices; - int idx_count; -#endif - protected: ArrayRep (T *d, int l) { data = d; len = l; - -#ifdef HEAVYWEIGHT_INDEXING - idx = 0; - max_indices = 0; - idx_count = 0; -#endif } public: @@ -100,12 +82,6 @@ { data = 0; len = 0; - -#ifdef HEAVYWEIGHT_INDEXING - idx = 0; - max_indices = 0; - idx_count = 0; -#endif } ArrayRep (int n); @@ -119,18 +95,6 @@ T& elem (int n); T elem (int n) const; - -#ifdef HEAVYWEIGHT_INDEXING - void set_max_indices (int mi) { max_indices = mi; } - - void clear_index (void); - - void set_index (const idx_vector& i); - - int index_count (void) const { return idx_count; } - - idx_vector *get_idx (void) const { return idx; } -#endif }; // One dimensional array class. Handles the reference counting for @@ -139,6 +103,14 @@ template <class T> class Array { +private: + +#ifdef HEAVYWEIGHT_INDEXING + idx_vector *idx; + int max_indices; + int idx_count; +#endif + protected: ArrayRep<T> *rep; @@ -147,7 +119,12 @@ { rep = new ArrayRep<T> (d, l); rep->count = 1; - set_max_indices (1); + +#ifdef HEAVYWEIGHT_INDEXING + idx = 0; + max_indices = 1; + idx_count = 0; +#endif } public: @@ -156,14 +133,24 @@ { rep = new ArrayRep<T> (); rep->count = 1; - set_max_indices (1); + +#ifdef HEAVYWEIGHT_INDEXING + idx = 0; + max_indices = 1; + idx_count = 0; +#endif } Array (int n) { rep = new ArrayRep<T> (n); rep->count = 1; - set_max_indices (1); + +#ifdef HEAVYWEIGHT_INDEXING + idx = 0; + max_indices = 1; + idx_count = 0; +#endif } Array (int n, const T& val); @@ -172,13 +159,15 @@ { rep = a.rep; rep->count++; + +#ifdef HEAVYWEIGHT_INDEXING + max_indices = a.max_indices; + idx_count = 0; + idx = 0; +#endif } - ~Array (void) - { - if (--rep->count <= 0) - delete rep; - } + ~Array (void); Array<T>& operator = (const Array<T>& a); @@ -215,15 +204,15 @@ T *fortran_vec (void); #ifdef HEAVYWEIGHT_INDEXING - void set_max_indices (int mi) { rep->set_max_indices (mi); } + void set_max_indices (int mi) { max_indices = mi; } - void clear_index (void) { rep->clear_index (); } + void clear_index (void); - void set_index (const idx_vector& i) { rep->set_index (i); } + void set_index (const idx_vector& i); - int index_count (void) const { return rep->index_count (); } + int index_count (void) const { return idx_count; } - idx_vector *get_idx (void) const { return rep->get_idx (); } + idx_vector *get_idx (void) const { return idx; } void maybe_delete_elements (idx_vector& i);