comparison liboctave/Array.h @ 2006:95e952f72d66

[project @ 1996-03-04 00:33:32 by jwe]
author jwe
date Mon, 04 Mar 1996 00:40:14 +0000
parents c1ffef39e94a
children 91c6c05e4c06
comparison
equal deleted inserted replaced
2005:c1ffef39e94a 2006:95e952f72d66
80 { 80 {
81 ::qsort (data, len, sizeof (T), compare); 81 ::qsort (data, len, sizeof (T), compare);
82 } 82 }
83 }; 83 };
84 84
85 void make_unique (void)
86 {
87 if (rep->count > 1)
88 {
89 --rep->count;
90 rep = new ArrayRep (*rep);
91 }
92 }
93
85 #ifdef HEAVYWEIGHT_INDEXING 94 #ifdef HEAVYWEIGHT_INDEXING
86 idx_vector *idx; 95 idx_vector *idx;
87 int max_indices; 96 int max_indices;
88 int idx_count; 97 int idx_count;
89 #endif 98 #endif
146 Array<T>& operator = (const Array<T>& a); 155 Array<T>& operator = (const Array<T>& a);
147 156
148 int capacity (void) const { return rep->length (); } 157 int capacity (void) const { return rep->length (); }
149 int length (void) const { return rep->length (); } 158 int length (void) const { return rep->length (); }
150 159
160 // XXX FIXME XXX -- would be nice to fix this so that we don't
161 // unnecessarily force a copy, but that is not so easy, and I see no
162 // clean way to do it.
163
151 T& elem (int n) 164 T& elem (int n)
152 { 165 {
153 if (rep->count > 1) 166 make_unique ();
154 {
155 --rep->count;
156 rep = new ArrayRep (*rep);
157 }
158 return rep->elem (n); 167 return rep->elem (n);
159 } 168 }
160 169
161 T& checkelem (int n); 170 T& Array<T>::checkelem (int n)
171 {
172 if (n < 0 || n >= rep->length ())
173 {
174 (*current_liboctave_error_handler) ("range error");
175 static T foo;
176 return foo;
177 }
178 else
179 return elem (n);
180 }
181
182 #if defined (NO_BOUNDS_CHECKING)
183 T& operator () (int n) { return elem (n); }
184 #else
162 T& operator () (int n) { return checkelem (n); } 185 T& operator () (int n) { return checkelem (n); }
163 186 #endif
164 T elem (int n) const; 187
165 T checkelem (int n) const; 188 T Array<T>::elem (int n) const { return rep->elem (n); }
166 T operator () (int n) const; 189
167 190 T Array<T>::checkelem (int n) const
168 // No checking. 191 {
192 if (n < 0 || n >= rep->length ())
193 {
194 (*current_liboctave_error_handler) ("range error");
195 T foo;
196 static T *bar = &foo;
197 return foo;
198 }
199 return elem (n);
200 }
201
202 #if defined (NO_BOUNDS_CHECKING)
203 T Array<T>::operator () (int n) const { return elem (n); }
204 #else
205 T Array<T>::operator () (int n) const { return checkelem (n); }
206 #endif
207
208 // No checking, even for multiple references, ever.
169 209
170 T& xelem (int n) { return rep->elem (n); } 210 T& xelem (int n) { return rep->elem (n); }
171 T xelem (int n) const { return rep->elem (n); } 211 T xelem (int n) const { return rep->elem (n); }
172 212
173 void resize (int n); 213 void resize (int n);