Mercurial > hg > octave-nkf
diff liboctave/array/idx-vector.h @ 17769:49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
* liboctave/array/Array-C.cc, liboctave/array/Array-b.cc,
liboctave/array/Array-ch.cc, liboctave/array/Array-d.cc,
liboctave/array/Array-f.cc, liboctave/array/Array-fC.cc,
liboctave/array/Array-util.cc, liboctave/array/Array-util.h,
liboctave/array/Array.cc, liboctave/array/Array.h, liboctave/array/Array3.h,
liboctave/array/CColVector.cc, liboctave/array/CColVector.h,
liboctave/array/CDiagMatrix.cc, liboctave/array/CDiagMatrix.h,
liboctave/array/CMatrix.cc, liboctave/array/CMatrix.h,
liboctave/array/CNDArray.cc, liboctave/array/CNDArray.h,
liboctave/array/CRowVector.cc, liboctave/array/CRowVector.h,
liboctave/array/CSparse.cc, liboctave/array/CSparse.h,
liboctave/array/DiagArray2.h, liboctave/array/MArray.cc,
liboctave/array/MArray.h, liboctave/array/MDiagArray2.cc,
liboctave/array/MDiagArray2.h, liboctave/array/MSparse.cc,
liboctave/array/MSparse.h, liboctave/array/MatrixType.cc,
liboctave/array/MatrixType.h, liboctave/array/PermMatrix.h,
liboctave/array/Range.cc, liboctave/array/Range.h, liboctave/array/Sparse.cc,
liboctave/array/Sparse.h, liboctave/array/boolMatrix.cc,
liboctave/array/boolMatrix.h, liboctave/array/boolNDArray.cc,
liboctave/array/boolNDArray.h, liboctave/array/boolSparse.cc,
liboctave/array/boolSparse.h, liboctave/array/chMatrix.cc,
liboctave/array/chMatrix.h, liboctave/array/chNDArray.cc,
liboctave/array/chNDArray.h, liboctave/array/dColVector.h,
liboctave/array/dDiagMatrix.cc, liboctave/array/dDiagMatrix.h,
liboctave/array/dMatrix.cc, liboctave/array/dMatrix.h,
liboctave/array/dNDArray.cc, liboctave/array/dNDArray.h,
liboctave/array/dRowVector.h, liboctave/array/dSparse.cc,
liboctave/array/dSparse.h, liboctave/array/dim-vector.cc,
liboctave/array/dim-vector.h, liboctave/array/fCColVector.cc,
liboctave/array/fCColVector.h, liboctave/array/fCDiagMatrix.cc,
liboctave/array/fCDiagMatrix.h, liboctave/array/fCMatrix.cc,
liboctave/array/fCMatrix.h, liboctave/array/fCNDArray.cc,
liboctave/array/fCNDArray.h, liboctave/array/fCRowVector.cc,
liboctave/array/fCRowVector.h, liboctave/array/fColVector.h,
liboctave/array/fDiagMatrix.cc, liboctave/array/fDiagMatrix.h,
liboctave/array/fMatrix.cc, liboctave/array/fMatrix.h,
liboctave/array/fNDArray.cc, liboctave/array/fNDArray.h,
liboctave/array/fRowVector.h, liboctave/array/idx-vector.cc,
liboctave/array/idx-vector.h, liboctave/array/intNDArray.cc,
liboctave/array/intNDArray.h, liboctave/cruft/misc/blaswrap.c,
liboctave/cruft/misc/quit.cc, liboctave/numeric/CmplxCHOL.cc,
liboctave/numeric/CmplxCHOL.h, liboctave/numeric/CmplxGEPBAL.cc,
liboctave/numeric/CmplxGEPBAL.h, liboctave/numeric/CmplxHESS.h,
liboctave/numeric/CmplxLU.cc, liboctave/numeric/CmplxLU.h,
liboctave/numeric/CmplxQR.cc, liboctave/numeric/CmplxQRP.cc,
liboctave/numeric/CmplxQRP.h, liboctave/numeric/CmplxSCHUR.h,
liboctave/numeric/CmplxSVD.cc, liboctave/numeric/CmplxSVD.h,
liboctave/numeric/CollocWt.h, liboctave/numeric/DAE.h,
liboctave/numeric/DAEFunc.h, liboctave/numeric/DAERT.h,
liboctave/numeric/DAERTFunc.h, liboctave/numeric/DASPK.cc,
liboctave/numeric/DASRT.cc, liboctave/numeric/DASRT.h,
liboctave/numeric/DASSL.cc, liboctave/numeric/DET.h, liboctave/numeric/EIG.cc,
liboctave/numeric/EIG.h, liboctave/numeric/LSODE.cc, liboctave/numeric/ODE.h,
liboctave/numeric/ODEFunc.h, liboctave/numeric/ODES.h,
liboctave/numeric/ODESFunc.h, liboctave/numeric/Quad.cc,
liboctave/numeric/Quad.h, liboctave/numeric/SparseCmplxCHOL.h,
liboctave/numeric/SparseCmplxLU.cc, liboctave/numeric/SparseCmplxLU.h,
liboctave/numeric/SparseCmplxQR.cc, liboctave/numeric/SparseCmplxQR.h,
liboctave/numeric/SparseQR.cc, liboctave/numeric/SparseQR.h,
liboctave/numeric/SparsedbleCHOL.h, liboctave/numeric/SparsedbleLU.cc,
liboctave/numeric/SparsedbleLU.h, liboctave/numeric/base-aepbal.h,
liboctave/numeric/base-dae.h, liboctave/numeric/base-de.h,
liboctave/numeric/base-lu.cc, liboctave/numeric/base-lu.h,
liboctave/numeric/base-min.h, liboctave/numeric/base-qr.h,
liboctave/numeric/bsxfun.h, liboctave/numeric/dbleCHOL.cc,
liboctave/numeric/dbleCHOL.h, liboctave/numeric/dbleGEPBAL.h,
liboctave/numeric/dbleHESS.h, liboctave/numeric/dbleLU.cc,
liboctave/numeric/dbleLU.h, liboctave/numeric/dbleQR.cc,
liboctave/numeric/dbleQRP.cc, liboctave/numeric/dbleQRP.h,
liboctave/numeric/dbleSCHUR.cc, liboctave/numeric/dbleSCHUR.h,
liboctave/numeric/dbleSVD.cc, liboctave/numeric/dbleSVD.h,
liboctave/numeric/eigs-base.cc, liboctave/numeric/fCmplxAEPBAL.cc,
liboctave/numeric/fCmplxAEPBAL.h, liboctave/numeric/fCmplxCHOL.cc,
liboctave/numeric/fCmplxCHOL.h, liboctave/numeric/fCmplxGEPBAL.cc,
liboctave/numeric/fCmplxGEPBAL.h, liboctave/numeric/fCmplxHESS.h,
liboctave/numeric/fCmplxLU.cc, liboctave/numeric/fCmplxLU.h,
liboctave/numeric/fCmplxQR.cc, liboctave/numeric/fCmplxQR.h,
liboctave/numeric/fCmplxQRP.cc, liboctave/numeric/fCmplxQRP.h,
liboctave/numeric/fCmplxSCHUR.cc, liboctave/numeric/fCmplxSCHUR.h,
liboctave/numeric/fCmplxSVD.h, liboctave/numeric/fEIG.cc,
liboctave/numeric/fEIG.h, liboctave/numeric/floatCHOL.cc,
liboctave/numeric/floatCHOL.h, liboctave/numeric/floatGEPBAL.cc,
liboctave/numeric/floatGEPBAL.h, liboctave/numeric/floatHESS.h,
liboctave/numeric/floatLU.cc, liboctave/numeric/floatLU.h,
liboctave/numeric/floatQR.cc, liboctave/numeric/floatQRP.cc,
liboctave/numeric/floatQRP.h, liboctave/numeric/floatSCHUR.cc,
liboctave/numeric/floatSCHUR.h, liboctave/numeric/floatSVD.cc,
liboctave/numeric/floatSVD.h, liboctave/numeric/lo-mappers.cc,
liboctave/numeric/lo-mappers.h, liboctave/numeric/lo-specfun.cc,
liboctave/numeric/lo-specfun.h, liboctave/numeric/oct-convn.cc,
liboctave/numeric/oct-fftw.cc, liboctave/numeric/oct-fftw.h,
liboctave/numeric/oct-norm.cc, liboctave/numeric/oct-rand.cc,
liboctave/numeric/oct-rand.h, liboctave/numeric/randgamma.c,
liboctave/numeric/randgamma.h, liboctave/numeric/randmtzig.c,
liboctave/numeric/randpoisson.c, liboctave/numeric/randpoisson.h,
liboctave/numeric/sparse-base-chol.h, liboctave/numeric/sparse-base-lu.h,
liboctave/numeric/sparse-dmsolve.cc, liboctave/operators/Sparse-diag-op-defs.h,
liboctave/operators/Sparse-op-defs.h, liboctave/operators/mx-inlines.cc,
liboctave/system/dir-ops.h, liboctave/system/file-ops.cc,
liboctave/system/file-stat.cc, liboctave/system/file-stat.h,
liboctave/system/lo-sysdep.cc, liboctave/system/lo-sysdep.h,
liboctave/system/mach-info.cc, liboctave/system/mach-info.h,
liboctave/system/oct-env.cc, liboctave/system/oct-group.cc,
liboctave/system/oct-syscalls.cc, liboctave/system/oct-syscalls.h,
liboctave/system/oct-time.h, liboctave/system/tempname.c,
liboctave/util/action-container.h, liboctave/util/base-list.h,
liboctave/util/cmd-edit.cc, liboctave/util/cmd-edit.h,
liboctave/util/cmd-hist.cc, liboctave/util/cmd-hist.h,
liboctave/util/data-conv.cc, liboctave/util/data-conv.h,
liboctave/util/kpse.cc, liboctave/util/lo-array-gripes.cc,
liboctave/util/lo-cieee.c, liboctave/util/lo-regexp.cc,
liboctave/util/lo-utils.cc, liboctave/util/oct-alloc.cc,
liboctave/util/oct-base64.cc, liboctave/util/oct-binmap.h,
liboctave/util/oct-cmplx.h, liboctave/util/oct-glob.cc,
liboctave/util/oct-inttypes.cc, liboctave/util/oct-inttypes.h,
liboctave/util/oct-locbuf.cc, liboctave/util/oct-locbuf.h,
liboctave/util/oct-mem.h, liboctave/util/oct-mutex.cc,
liboctave/util/oct-refcount.h, liboctave/util/oct-shlib.cc,
liboctave/util/oct-shlib.h, liboctave/util/oct-sort.cc,
liboctave/util/oct-sort.h, liboctave/util/pathsearch.cc,
liboctave/util/pathsearch.h, liboctave/util/sparse-util.cc,
liboctave/util/str-vec.cc, liboctave/util/str-vec.h,
liboctave/util/unwind-prot.h, liboctave/util/url-transfer.cc,
liboctave/util/url-transfer.h: Use GNU style coding conventions.
author | Rik <rik@octave.org> |
---|---|
date | Sat, 26 Oct 2013 18:57:05 -0700 |
parents | d63878346099 |
children | 8e056300994b |
line wrap: on
line diff
--- a/liboctave/array/idx-vector.h +++ b/liboctave/array/idx-vector.h @@ -55,14 +55,14 @@ public: enum idx_class_type - { - class_invalid = -1, - class_colon = 0, - class_range, - class_scalar, - class_vector, - class_mask - }; + { + class_invalid = -1, + class_colon = 0, + class_range, + class_scalar, + class_vector, + class_mask + }; template<class T> friend class std::auto_ptr; @@ -98,7 +98,7 @@ // Checks whether the index is colon or a range equivalent to colon. virtual bool is_colon_equiv (octave_idx_type) const { return false; } - // The original dimensions of this object (used when subscribing by matrices). + // The original dimensions of object (used when subscribing by matrices). virtual dim_vector orig_dimensions (void) const { return dim_vector (); } // i/o @@ -136,7 +136,7 @@ idx_class_type idx_class (void) const { return class_colon; } idx_base_rep *sort_uniq_clone (bool = false) - { count++; return this; } + { count++; return this; } idx_base_rep *sort_idx (Array<octave_idx_type>&); @@ -174,14 +174,15 @@ idx_range_rep (const Range&); octave_idx_type xelem (octave_idx_type i) const - { return start + i * step; } + { return start + i * step; } octave_idx_type checkelem (octave_idx_type i) const; octave_idx_type length (octave_idx_type) const { return len; } octave_idx_type extent (octave_idx_type n) const - { return len ? std::max (n, (start + 1 + (step < 0 ? 0 : step * (len - 1)))) : n; } + { return len ? std::max (n, (start + 1 + (step < 0 ? 0 : step * (len - 1)))) + : n; } idx_class_type idx_class (void) const { return class_range; } @@ -190,10 +191,10 @@ idx_base_rep *sort_idx (Array<octave_idx_type>&); bool is_colon_equiv (octave_idx_type n) const - { return start == 0 && step == 1 && len == n; } + { return start == 0 && step == 1 && len == n; } dim_vector orig_dimensions (void) const - { return dim_vector (1, len); } + { return dim_vector (1, len); } octave_idx_type get_start (void) const { return start; } @@ -240,17 +241,17 @@ octave_idx_type length (octave_idx_type) const { return 1; } octave_idx_type extent (octave_idx_type n) const - { return std::max (n, data + 1); } + { return std::max (n, data + 1); } idx_class_type idx_class (void) const { return class_scalar; } idx_base_rep *sort_uniq_clone (bool = false) - { count++; return this; } + { count++; return this; } idx_base_rep *sort_idx (Array<octave_idx_type>&); bool is_colon_equiv (octave_idx_type n) const - { return n == 1 && data == 0; } + { return n == 1 && data == 0; } dim_vector orig_dimensions (void) const { return dim_vector (1, 1); } @@ -285,7 +286,7 @@ idx_vector_rep (void) : data (0), len (0), ext (0), aowner (0), orig_dims () - { } + { } // Zero-based constructor. idx_vector_rep (const Array<octave_idx_type>& inda); @@ -311,7 +312,7 @@ octave_idx_type length (octave_idx_type) const { return len; } octave_idx_type extent (octave_idx_type n) const - { return std::max (n, ext); } + { return std::max (n, ext); } idx_class_type idx_class (void) const { return class_vector; } @@ -366,7 +367,7 @@ idx_mask_rep (void) : data (0), len (0), ext (0), lsti (-1), lste (-1), aowner (0), orig_dims () - { } + { } idx_mask_rep (bool); @@ -381,19 +382,19 @@ octave_idx_type length (octave_idx_type) const { return len; } octave_idx_type extent (octave_idx_type n) const - { return std::max (n, ext); } + { return std::max (n, ext); } idx_class_type idx_class (void) const { return class_mask; } idx_base_rep *sort_uniq_clone (bool = false) - { count++; return this; } + { count++; return this; } idx_base_rep *sort_idx (Array<octave_idx_type>&); dim_vector orig_dimensions (void) const { return orig_dims; } bool is_colon_equiv (octave_idx_type n) const - { return len == n && ext == n; } + { return len == n && ext == n; } const bool *get_data (void) const { return data; } @@ -437,31 +438,31 @@ // The shared empty vector representation (for fast default // constructor). static idx_vector_rep *nil_rep (void) - { - static idx_vector_rep ivr; - return &ivr; - } + { + static idx_vector_rep ivr; + return &ivr; + } // The shared empty vector representation with the error flag set. static idx_vector_rep *err_rep (void) - { - static idx_vector_rep ivr; - ivr.err = true; - return &ivr; - } + { + static idx_vector_rep ivr; + ivr.err = true; + return &ivr; + } // If there was an error in constructing the rep, replace it with // empty vector for safety. void chkerr (void) - { - if (rep->err) - { - if (--rep->count == 0) - delete rep; - rep = err_rep (); - rep->count++; - } - } + { + if (rep->err) + { + if (--rep->count == 0) + delete rep; + rep = err_rep (); + rep->count++; + } + } public: @@ -470,28 +471,28 @@ // Zero-based constructors (for use from C++). idx_vector (octave_idx_type i) : rep (new idx_scalar_rep (i)) - { chkerr (); } + { chkerr (); } idx_vector (octave_idx_type start, octave_idx_type limit, octave_idx_type step = 1) : rep (new idx_range_rep (start, limit, step)) - { chkerr (); } + { chkerr (); } static idx_vector - make_range (octave_idx_type start, octave_idx_type step, - octave_idx_type len) - { - return idx_vector (new idx_range_rep (start, len, step, DIRECT)); - } + make_range (octave_idx_type start, octave_idx_type step, + octave_idx_type len) + { + return idx_vector (new idx_range_rep (start, len, step, DIRECT)); + } idx_vector (const Array<octave_idx_type>& inda) : rep (new idx_vector_rep (inda)) - { chkerr (); } + { chkerr (); } // Directly pass extent, no checking. idx_vector (const Array<octave_idx_type>& inda, octave_idx_type ext) : rep (new idx_vector_rep (inda, ext, DIRECT)) - { } + { } // Colon is best constructed by simply copying (or referencing) this member. static const idx_vector colon; @@ -513,105 +514,105 @@ template <class T> idx_vector (const Array<octave_int<T> >& nda) : rep (new idx_vector_rep (nda)) - { chkerr (); } + { chkerr (); } idx_vector (const Array<double>& nda) : rep (new idx_vector_rep (nda)) - { chkerr (); } + { chkerr (); } idx_vector (const Array<float>& nda) : rep (new idx_vector_rep (nda)) - { chkerr (); } + { chkerr (); } idx_vector (const Array<bool>& nda); idx_vector (const Range& r) : rep (new idx_range_rep (r)) - { chkerr (); } + { chkerr (); } idx_vector (const Sparse<bool>& nda) : rep (new idx_vector_rep (nda)) - { chkerr (); } + { chkerr (); } idx_vector (const idx_vector& a) : rep (a.rep) { rep->count++; } ~idx_vector (void) - { - if (--rep->count == 0) - delete rep; - } + { + if (--rep->count == 0) + delete rep; + } idx_vector& operator = (const idx_vector& a) - { - if (this != &a) - { - if (--rep->count == 0) - delete rep; + { + if (this != &a) + { + if (--rep->count == 0) + delete rep; - rep = a.rep; - rep->count++; - } - return *this; - } + rep = a.rep; + rep->count++; + } + return *this; + } idx_class_type idx_class (void) const { return rep->idx_class (); } octave_idx_type length (octave_idx_type n = 0) const - { return rep->length (n); } + { return rep->length (n); } octave_idx_type extent (octave_idx_type n) const - { return rep->extent (n); } + { return rep->extent (n); } octave_idx_type xelem (octave_idx_type n) const - { return rep->xelem (n); } + { return rep->xelem (n); } octave_idx_type checkelem (octave_idx_type n) const - { return rep->checkelem (n); } + { return rep->checkelem (n); } octave_idx_type operator () (octave_idx_type n) const - { + { #if defined (BOUNDS_CHECKING) - return rep->checkelem (n); + return rep->checkelem (n); #else - return rep->xelem (n); + return rep->xelem (n); #endif - } + } operator bool (void) const - { return ! rep->err; } + { return ! rep->err; } bool is_colon (void) const - { return rep->idx_class () == class_colon; } + { return rep->idx_class () == class_colon; } bool is_scalar (void) const - { return rep->idx_class () == class_scalar; } + { return rep->idx_class () == class_scalar; } bool is_range (void) const - { return rep->idx_class () == class_range; } + { return rep->idx_class () == class_range; } bool is_colon_equiv (octave_idx_type n) const - { return rep->is_colon_equiv (n); } + { return rep->is_colon_equiv (n); } idx_vector sorted (bool uniq = false) const - { return idx_vector (rep->sort_uniq_clone (uniq)); } + { return idx_vector (rep->sort_uniq_clone (uniq)); } idx_vector sorted (Array<octave_idx_type>& sidx) const - { return idx_vector (rep->sort_idx (sidx)); } + { return idx_vector (rep->sort_idx (sidx)); } dim_vector orig_dimensions (void) const { return rep->orig_dimensions (); } octave_idx_type orig_rows (void) const - { return orig_dimensions () (0); } + { return orig_dimensions () (0); } octave_idx_type orig_columns (void) const - { return orig_dimensions () (1); } + { return orig_dimensions () (1); } int orig_empty (void) const - { return (! is_colon () && orig_dimensions ().any_zero ()); } + { return (! is_colon () && orig_dimensions ().any_zero ()); } // i/o std::ostream& print (std::ostream& os) const { return rep->print (os); } friend std::ostream& operator << (std::ostream& os, const idx_vector& a) - { return a.print (os); } + { return a.print (os); } // Slice with specializations. No checking of bounds! // @@ -624,67 +625,67 @@ template <class T> octave_idx_type index (const T *src, octave_idx_type n, T *dest) const - { - octave_idx_type len = rep->length (n); + { + octave_idx_type len = rep->length (n); - switch (rep->idx_class ()) - { - case class_colon: - copy_or_memcpy (len, src, dest); - break; + switch (rep->idx_class ()) + { + case class_colon: + copy_or_memcpy (len, src, dest); + break; - case class_range: - { - idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); - octave_idx_type start = r->get_start (), step = r->get_step (); - const T *ssrc = src + start; - if (step == 1) - copy_or_memcpy (len, ssrc, dest); - else if (step == -1) - std::reverse_copy (ssrc - len + 1, ssrc + 1, dest); - else if (step == 0) - std::fill_n (dest, len, *ssrc); - else - { - for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) - dest[i] = ssrc[j]; - } - } - break; + case class_range: + { + idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); + octave_idx_type start = r->get_start (), step = r->get_step (); + const T *ssrc = src + start; + if (step == 1) + copy_or_memcpy (len, ssrc, dest); + else if (step == -1) + std::reverse_copy (ssrc - len + 1, ssrc + 1, dest); + else if (step == 0) + std::fill_n (dest, len, *ssrc); + else + { + for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) + dest[i] = ssrc[j]; + } + } + break; - case class_scalar: - { - idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); - dest[0] = src[r->get_data ()]; - } - break; + case class_scalar: + { + idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); + dest[0] = src[r->get_data ()]; + } + break; - case class_vector: - { - idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); - const octave_idx_type *data = r->get_data (); - for (octave_idx_type i = 0; i < len; i++) - dest[i] = src[data[i]]; - } - break; + case class_vector: + { + idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); + const octave_idx_type *data = r->get_data (); + for (octave_idx_type i = 0; i < len; i++) + dest[i] = src[data[i]]; + } + break; - case class_mask: - { - idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); - const bool *data = r->get_data (); - octave_idx_type ext = r->extent (0); - for (octave_idx_type i = 0; i < ext; i++) - if (data[i]) *dest++ = src[i]; - } - break; + case class_mask: + { + idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); + const bool *data = r->get_data (); + octave_idx_type ext = r->extent (0); + for (octave_idx_type i = 0; i < ext; i++) + if (data[i]) *dest++ = src[i]; + } + break; - default: - assert (false); - break; - } + default: + assert (false); + break; + } - return len; - } + return len; + } // Slice assignment with specializations. No checking of bounds! // @@ -697,65 +698,65 @@ template <class T> octave_idx_type assign (const T *src, octave_idx_type n, T *dest) const - { - octave_idx_type len = rep->length (n); + { + octave_idx_type len = rep->length (n); - switch (rep->idx_class ()) - { - case class_colon: - copy_or_memcpy (len, src, dest); - break; + switch (rep->idx_class ()) + { + case class_colon: + copy_or_memcpy (len, src, dest); + break; - case class_range: - { - idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); - octave_idx_type start = r->get_start (), step = r->get_step (); - T *sdest = dest + start; - if (step == 1) - copy_or_memcpy (len, src, sdest); - else if (step == -1) - std::reverse_copy (src, src + len, sdest - len + 1); - else - { - for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) - sdest[j] = src[i]; - } - } - break; + case class_range: + { + idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); + octave_idx_type start = r->get_start (), step = r->get_step (); + T *sdest = dest + start; + if (step == 1) + copy_or_memcpy (len, src, sdest); + else if (step == -1) + std::reverse_copy (src, src + len, sdest - len + 1); + else + { + for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) + sdest[j] = src[i]; + } + } + break; - case class_scalar: - { - idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); - dest[r->get_data ()] = src[0]; - } - break; + case class_scalar: + { + idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); + dest[r->get_data ()] = src[0]; + } + break; - case class_vector: - { - idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); - const octave_idx_type *data = r->get_data (); - for (octave_idx_type i = 0; i < len; i++) - dest[data[i]] = src[i]; - } - break; + case class_vector: + { + idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); + const octave_idx_type *data = r->get_data (); + for (octave_idx_type i = 0; i < len; i++) + dest[data[i]] = src[i]; + } + break; - case class_mask: - { - idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); - const bool *data = r->get_data (); - octave_idx_type ext = r->extent (0); - for (octave_idx_type i = 0; i < ext; i++) - if (data[i]) dest[i] = *src++; - } - break; + case class_mask: + { + idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); + const bool *data = r->get_data (); + octave_idx_type ext = r->extent (0); + for (octave_idx_type i = 0; i < ext; i++) + if (data[i]) dest[i] = *src++; + } + break; - default: - assert (false); - break; - } + default: + assert (false); + break; + } - return len; - } + return len; + } // Slice fill with specializations. No checking of bounds! // @@ -768,65 +769,65 @@ template <class T> octave_idx_type fill (const T& val, octave_idx_type n, T *dest) const - { - octave_idx_type len = rep->length (n); + { + octave_idx_type len = rep->length (n); - switch (rep->idx_class ()) - { - case class_colon: - std::fill (dest, dest + len, val); - break; + switch (rep->idx_class ()) + { + case class_colon: + std::fill (dest, dest + len, val); + break; - case class_range: - { - idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); - octave_idx_type start = r->get_start (), step = r->get_step (); - T *sdest = dest + start; - if (step == 1) - std::fill (sdest, sdest + len, val); - else if (step == -1) - std::fill (sdest - len + 1, sdest + 1, val); - else - { - for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) - sdest[j] = val; - } - } - break; + case class_range: + { + idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); + octave_idx_type start = r->get_start (), step = r->get_step (); + T *sdest = dest + start; + if (step == 1) + std::fill (sdest, sdest + len, val); + else if (step == -1) + std::fill (sdest - len + 1, sdest + 1, val); + else + { + for (octave_idx_type i = 0, j = 0; i < len; i++, j += step) + sdest[j] = val; + } + } + break; - case class_scalar: - { - idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); - dest[r->get_data ()] = val; - } - break; + case class_scalar: + { + idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); + dest[r->get_data ()] = val; + } + break; - case class_vector: - { - idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); - const octave_idx_type *data = r->get_data (); - for (octave_idx_type i = 0; i < len; i++) - dest[data[i]] = val; - } - break; + case class_vector: + { + idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); + const octave_idx_type *data = r->get_data (); + for (octave_idx_type i = 0; i < len; i++) + dest[data[i]] = val; + } + break; - case class_mask: - { - idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); - const bool *data = r->get_data (); - octave_idx_type ext = r->extent (0); - for (octave_idx_type i = 0; i < ext; i++) - if (data[i]) dest[i] = val; - } - break; + case class_mask: + { + idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); + const bool *data = r->get_data (); + octave_idx_type ext = r->extent (0); + for (octave_idx_type i = 0; i < ext; i++) + if (data[i]) dest[i] = val; + } + break; - default: - assert (false); - break; - } + default: + assert (false); + break; + } - return len; - } + return len; + } // Generic non-breakable indexed loop. The loop body should be // encapsulated in a single functor body. This is equivalent to the @@ -837,60 +838,60 @@ template <class Functor> void loop (octave_idx_type n, Functor body) const - { - octave_idx_type len = rep->length (n); + { + octave_idx_type len = rep->length (n); - switch (rep->idx_class ()) - { - case class_colon: - for (octave_idx_type i = 0; i < len; i++) body (i); - break; + switch (rep->idx_class ()) + { + case class_colon: + for (octave_idx_type i = 0; i < len; i++) body (i); + break; - case class_range: - { - idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); - octave_idx_type start = r->get_start (), step = r->get_step (); - octave_idx_type i, j; - if (step == 1) - for (i = start, j = start + len; i < j; i++) body (i); - else if (step == -1) - for (i = start, j = start - len; i > j; i--) body (i); - else - for (i = 0, j = start; i < len; i++, j += step) body (j); - } - break; + case class_range: + { + idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); + octave_idx_type start = r->get_start (), step = r->get_step (); + octave_idx_type i, j; + if (step == 1) + for (i = start, j = start + len; i < j; i++) body (i); + else if (step == -1) + for (i = start, j = start - len; i > j; i--) body (i); + else + for (i = 0, j = start; i < len; i++, j += step) body (j); + } + break; - case class_scalar: - { - idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); - body (r->get_data ()); - } - break; + case class_scalar: + { + idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); + body (r->get_data ()); + } + break; - case class_vector: - { - idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); - const octave_idx_type *data = r->get_data (); - for (octave_idx_type i = 0; i < len; i++) body (data[i]); - } - break; + case class_vector: + { + idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); + const octave_idx_type *data = r->get_data (); + for (octave_idx_type i = 0; i < len; i++) body (data[i]); + } + break; - case class_mask: - { - idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); - const bool *data = r->get_data (); - octave_idx_type ext = r->extent (0); - for (octave_idx_type i = 0; i < ext; i++) - if (data[i]) body (i); - } - break; + case class_mask: + { + idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); + const bool *data = r->get_data (); + octave_idx_type ext = r->extent (0); + for (octave_idx_type i = 0; i < ext; i++) + if (data[i]) body (i); + } + break; - default: - assert (false); - break; - } + default: + assert (false); + break; + } - } + } // Generic breakable indexed loop. The loop body should be // encapsulated in a single functor body. This is equivalent to the @@ -904,78 +905,78 @@ template <class Functor> octave_idx_type bloop (octave_idx_type n, Functor body) const - { - octave_idx_type len = rep->length (n), ret; + { + octave_idx_type len = rep->length (n), ret; - switch (rep->idx_class ()) + switch (rep->idx_class ()) + { + case class_colon: { - case class_colon: - { - octave_idx_type i; - for (i = 0; i < len && body (i); i++) ; - ret = i; - } - break; + octave_idx_type i; + for (i = 0; i < len && body (i); i++) ; + ret = i; + } + break; - case class_range: - { - idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); - octave_idx_type start = r->get_start (), step = r->get_step (); - octave_idx_type i, j; - if (step == 1) - for (i = start, j = start + len; i < j && body (i); i++) ; - else if (step == -1) - for (i = start, j = start - len; i > j && body (i); i--) ; - else - for (i = 0, j = start; i < len && body (j); i++, j += step) ; - ret = i; - } - break; + case class_range: + { + idx_range_rep * r = dynamic_cast<idx_range_rep *> (rep); + octave_idx_type start = r->get_start (), step = r->get_step (); + octave_idx_type i, j; + if (step == 1) + for (i = start, j = start + len; i < j && body (i); i++) ; + else if (step == -1) + for (i = start, j = start - len; i > j && body (i); i--) ; + else + for (i = 0, j = start; i < len && body (j); i++, j += step) ; + ret = i; + } + break; - case class_scalar: - { - idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); - ret = body (r->get_data ()) ? 1 : 0; - } - break; + case class_scalar: + { + idx_scalar_rep * r = dynamic_cast<idx_scalar_rep *> (rep); + ret = body (r->get_data ()) ? 1 : 0; + } + break; - case class_vector: - { - idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); - const octave_idx_type *data = r->get_data (); - octave_idx_type i; - for (i = 0; i < len && body (data[i]); i++) ; - ret = i; - } - break; + case class_vector: + { + idx_vector_rep * r = dynamic_cast<idx_vector_rep *> (rep); + const octave_idx_type *data = r->get_data (); + octave_idx_type i; + for (i = 0; i < len && body (data[i]); i++) ; + ret = i; + } + break; - case class_mask: - { - idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); - const bool *data = r->get_data (); - octave_idx_type ext = r->extent (0), j = 0; - for (octave_idx_type i = 0; i < ext; i++) - { - if (data[i]) - { - if (body (i)) - break; - else - j++; - } - } + case class_mask: + { + idx_mask_rep * r = dynamic_cast<idx_mask_rep *> (rep); + const bool *data = r->get_data (); + octave_idx_type ext = r->extent (0), j = 0; + for (octave_idx_type i = 0; i < ext; i++) + { + if (data[i]) + { + if (body (i)) + break; + else + j++; + } + } - ret = j; - } - break; + ret = j; + } + break; - default: - assert (false); - break; - } + default: + assert (false); + break; + } - return ret; - } + return ret; + } // Rationale: // This method is the key to "smart indexing". When indexing cartesian @@ -1022,20 +1023,20 @@ bool is_vector (void) const; - // FIXME -- these are here for compatibility. They should be removed + // FIXME: these are here for compatibility. They should be removed // when no longer in use. octave_idx_type elem (octave_idx_type n) const - { return (*this) (n); } + { return (*this) (n); } bool is_colon_equiv (octave_idx_type n, int) const - { return is_colon_equiv (n); } + { return is_colon_equiv (n); } octave_idx_type freeze (octave_idx_type z_len, const char *tag, bool resize_ok = false); void sort (bool uniq = false) - { *this = sorted (uniq); } + { *this = sorted (uniq); } octave_idx_type ones_count (void) const;