VectorIter.h

Classes

VectorIterator -- Iterate an Vector cursor through another Array. (full description)
ReadOnlyVectorIterator -- Iterate a Vector cursor through another Array. (full description)

template<class T> class VectorIterator : public ArrayIterator<T>

Interface

Public Members
explicit VectorIterator(Array<T> &a, uInt axis=0)
Vector<T> &vector()
Private Members
VectorIterator(const VectorIterator<T> &)
VectorIterator<T> &operator=(const VectorIterator<T> &)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

VectorIterator steps a Vector (the "cursor") through an array for the given axis. The cursor "refers" to storage in the array, so that changing the values in the cursor changes values in the original array.

This class is derived from ArrayIterator; basically it only adds the vector() member function which allows you to access the cursor as a Vector.

Tip The origin of the cursor, i.e. the subarray that moves through the larger array, is always zero.

In this example we sum all the elements of an array; of course we already have the "sum" function in ArrayMath.h that we should use instead.

    Array<Float> af;
    // set af
    VectorIterator vi(af);
    Float sum = 0.0;
    uInt n = vi.vector().nelements();
    while (! vi.pastEnd()) {
        for (Int i=0; i < n; i++) {   // N.B.; cursor always 0 based.
            sum += vi.vector()(i);
        }
        vi.next();
    }
    

Member Description

explicit VectorIterator(Array<T> &a, uInt axis=0)

Iterate by vector cursors through array "a". The vector cursor is taken for the given axis.

Vector<T> &vector()

Return a Vector at the current position.

VectorIterator(const VectorIterator<T> &)

Not implemented.

VectorIterator<T> &operator=(const VectorIterator<T> &)

Not implemented.

template<class T> class ReadOnlyVectorIterator

Interface

Public Members
explicit ReadOnlyVectorIterator(const Array<T> &a, uInt axis=0) : vi(const_cast<Array<T>&>(a), axis)
void next()
void reset()
void origin()
const Array<T> &array()
const Vector<T> &vector()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
IPosition endPos() const
uInt ndim() const
Private Members
ReadOnlyVectorIterator(const ReadOnlyVectorIterator<T> &)
ReadOnlyVectorIterator<T> &operator=(const ReadOnlyVectorIterator<T> &)

Description

Review Status

Reviewed By:
UNKNOWN
Date Reviewed:
before2004/08/25

ReadOnlyVectorIterator behaves exactly like VectorIterator (cf.) only it should be used on const Arrays.

Tip Note that the R/O VectorIterator is not derived from R/O ArrayIterator.

Member Description

explicit ReadOnlyVectorIterator(const Array<T> &a, uInt axis=0) : vi(const_cast<Array<T>&>(a), axis)
void next()
void reset()
void origin()
const Array<T> &array()
const Vector<T> &vector()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
IPosition endPos() const
uInt ndim() const

ReadOnlyVectorIterator(const ReadOnlyVectorIterator<T> &)

Not implemented.

ReadOnlyVectorIterator<T> &operator=(const ReadOnlyVectorIterator<T> &)

Not implemented.