Mercurial > hg > octave-nkf
changeset 14628:63ae976ac2e7 stable
preserve DiagArray2 interface for stable release series
* DiagArray2.h (DiagArray2::checkelem): Restore function. Provide
non-const version.
(DiagArray2::check_idx): Return bool status.
(DiagArray2::operator ()): Call checkelem, not check_idx.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Sat, 12 May 2012 12:31:34 -0400 |
parents | a7be1e7e5831 |
children | 9a610b0e8c4b |
files | liboctave/DiagArray2.cc liboctave/DiagArray2.h |
diffstat | 2 files changed, 41 insertions(+), 15 deletions(-) [+] |
line wrap: on
line diff
--- 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. @@ -166,6 +177,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