Mercurial > hg > octave-lyh
changeset 16186:b4a6895a9863
Use proper OO-class for __rangeidx_helper().
* liboctave/array/Range.cc(__rangeidx_helper): Make __rangeidx_helper
a class, instead of a struct, for better visibility into what it does.
author | Rik <rik@octave.org> |
---|---|
date | Sun, 03 Mar 2013 16:22:21 -0800 |
parents | e810e7d941a1 |
children | 490625211945 |
files | liboctave/array/Range.cc |
diffstat | 1 files changed, 16 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/array/Range.cc +++ b/liboctave/array/Range.cc @@ -123,13 +123,11 @@ #endif } -// Pseudo-class used for idx_vector.loop () function call -struct _rangeidx_helper +// Helper class used solely for idx_vector.loop () function call +class __rangeidx_helper { - double *array, base, inc, limit; - octave_idx_type nmax; - - _rangeidx_helper (double *a, double b, double i, double l, octave_idx_type n) + public: + __rangeidx_helper (double *a, double b, double i, double l, octave_idx_type n) : array (a), base (b), inc (i), limit (l), nmax (n-1) { } void operator () (octave_idx_type i) @@ -141,13 +139,18 @@ else { double end = base + i * inc; - if ((inc > 0 && end >= limit) - || (inc < 0 && end <= limit)) + if ((inc > 0 && end >= limit) || (inc < 0 && end <= limit)) *array++ = limit; else *array++ = end; } } + + private: + + double *array, base, inc, limit; + octave_idx_type nmax; + }; Array<double> @@ -175,15 +178,17 @@ retval.clear (rd); - // idx_vector loop across all values in i, executing _rangeidx_helper (i) foreach i - i.loop (n, _rangeidx_helper (retval.fortran_vec (), - rng_base, rng_inc, rng_limit, rng_nelem)); + // idx_vector loop across all values in i, + // executing __rangeidx_helper (i) for each i + i.loop (n, __rangeidx_helper (retval.fortran_vec (), + rng_base, rng_inc, rng_limit, rng_nelem)); } return retval; } // NOTE: max and min only return useful values if nelem > 0. +// do_minmax_body() in max.cc avoids calling Range::min/max if nelem == 0. double Range::min (void) const