Mercurial > hg > octave-lojdl
changeset 14630:9e4ad3f1f291
maint: periodic merge of stable to default
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 12 May 2012 12:39:09 -0400 |
parents | bb5ecda3b975 (current diff) 9a610b0e8c4b (diff) |
children | 57e4ff70b7c1 3513df68d580 |
files | .hgtags configure.ac libcruft/Makefile.am liboctave/DiagArray2.h liboctave/Makefile.am src/Makefile.am |
diffstat | 3 files changed, 42 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- a/.hgtags +++ b/.hgtags @@ -64,3 +64,4 @@ e320928eeb3aa2370b792e83dafc3e0ddecdc871 release-3-2-4 ba4d6343524b406b0d15aee34579f80783581c54 release-3-6-1 704f7895eef03008dd79848eb9da4bfb40787d73 release-3-6-0 +f947d2922febf12dcd1fb6e21b356756ecb54e55 rc-3-6-2-0
--- a/liboctave/DiagArray2.cc +++ b/liboctave/DiagArray2.cc @@ -82,16 +82,6 @@ // A two-dimensional array with diagonal elements only. -template <typename T> -void -DiagArray2<T>::check_idx (octave_idx_type r, octave_idx_type c) const -{ - if (r < 0 || r >= dim1 ()) - gripe_index_out_of_range (2, 1, r+1, dim1 ()); - if (c < 0 || c >= dim2 ()) - gripe_index_out_of_range (2, 2, c+1, dim2 ()); -} - template <class T> void DiagArray2<T>::resize (octave_idx_type r, octave_idx_type c, @@ -121,3 +111,24 @@ return result; } + +template <typename T> +bool +DiagArray2<T>::check_idx (octave_idx_type r, octave_idx_type c) const +{ + bool ok = true; + + if (r < 0 || r >= dim1 ()) + { + gripe_index_out_of_range (2, 1, r+1, dim1 ()); + ok = false; + } + + if (c < 0 || c >= dim2 ()) + { + gripe_index_out_of_range (2, 2, c+1, dim2 ()); + ok = false; + } + + return ok; +}
--- a/liboctave/DiagArray2.h +++ b/liboctave/DiagArray2.h @@ -119,22 +119,33 @@ T& dgelem (octave_idx_type i) { return Array<T>::elem (i); } - void check_idx (octave_idx_type r, octave_idx_type c) const; + T checkelem (octave_idx_type r, octave_idx_type c) const + { + return check_idx (r, c) ? elem (r, c) : T (0); + } T operator () (octave_idx_type r, octave_idx_type c) const { #if defined (BOUNDS_CHECKING) - check_idx (r, c); + checkelem (r, c); +#else + return elem (r, c); #endif - return elem (r, c); + } + + T& checkelem (octave_idx_type r, octave_idx_type c) + { + static T zero (0); + return check_idx (r, c) ? elem (r, c) : zero; } T& operator () (octave_idx_type r, octave_idx_type c) { #if defined (BOUNDS_CHECKING) - check_idx (r, c); + return checkelem (r, c); +#else + return elem (r, c); #endif - return elem (r, c); } // No checking. @@ -169,6 +180,10 @@ void print_info (std::ostream& os, const std::string& prefix) const { Array<T>::print_info (os, prefix); } + +private: + + bool check_idx (octave_idx_type r, octave_idx_type c) const; }; #endif