Mercurial > octave-nkf
comparison liboctave/Array.h @ 2109:356f70c8fcbd
[project @ 1996-04-30 12:31:30 by jwe]
author | jwe |
---|---|
date | Tue, 30 Apr 1996 12:31:30 +0000 |
parents | 2b67abb63030 |
children | 2fbf9bb1cd7a |
comparison
equal
deleted
inserted
replaced
2108:2b67abb63030 | 2109:356f70c8fcbd |
---|---|
28 #pragma interface | 28 #pragma interface |
29 #endif | 29 #endif |
30 | 30 |
31 #include <cassert> | 31 #include <cassert> |
32 #include <cstdlib> | 32 #include <cstdlib> |
33 | |
34 #include "lo-error.h" | |
35 | 33 |
36 class idx_vector; | 34 class idx_vector; |
37 | 35 |
38 // For now, define this here if it is not already defined. Not doing | 36 // For now, define this here if it is not already defined. Not doing |
39 // this can result in bugs that are very hard to find. | 37 // this can result in bugs that are very hard to find. |
174 // clean way to do it. | 172 // clean way to do it. |
175 | 173 |
176 T& Array<T>::checkelem (int n) | 174 T& Array<T>::checkelem (int n) |
177 { | 175 { |
178 if (n < 0 || n >= rep->length ()) | 176 if (n < 0 || n >= rep->length ()) |
179 { | 177 return range_error ("T& Array<T>::checkelem", n); |
180 (*current_liboctave_error_handler) ("range error"); | |
181 static T foo; | |
182 return foo; | |
183 } | |
184 else | 178 else |
185 { | 179 { |
186 make_unique (); | 180 make_unique (); |
187 return xelem (n); | 181 return xelem (n); |
188 } | 182 } |
192 T& elem (int n) { return checkelem (n); } | 186 T& elem (int n) { return checkelem (n); } |
193 #else | 187 #else |
194 T& elem (int n) | 188 T& elem (int n) |
195 { | 189 { |
196 make_unique (); | 190 make_unique (); |
197 return xelem (); | 191 return xelem (n); |
198 } | 192 } |
199 #endif | 193 #endif |
200 | 194 |
201 T& operator () (int n) { return elem (n); } | 195 T& operator () (int n) { return elem (n); } |
202 | 196 |
203 T Array<T>::checkelem (int n) const | 197 T Array<T>::checkelem (int n) const |
204 { | 198 { |
205 if (n < 0 || n >= rep->length ()) | 199 if (n < 0 || n >= rep->length ()) |
206 return range_error (); | 200 return range_error ("T Array<T>::checkelem", n); |
207 else | 201 else |
208 return xelem (n); | 202 return xelem (n); |
209 } | 203 } |
210 | 204 |
211 #if defined (BOUNDS_CHECKING) | 205 #if defined (BOUNDS_CHECKING) |
234 rep->qsort (compare); | 228 rep->qsort (compare); |
235 | 229 |
236 return *this; | 230 return *this; |
237 } | 231 } |
238 | 232 |
239 T range_error (void) const; | 233 T range_error (const char *fcn, int n) const; |
240 T& range_error (void); | 234 T& range_error (const char *fcn, int n); |
241 | 235 |
242 #ifdef HEAVYWEIGHT_INDEXING | 236 #ifdef HEAVYWEIGHT_INDEXING |
243 void set_max_indices (int mi) { max_indices = mi; } | 237 void set_max_indices (int mi) { max_indices = mi; } |
244 | 238 |
245 void clear_index (void); | 239 void clear_index (void); |