ArrayIter.h

Classes

ArrayIterator -- Iterate an Array cursor through another Array. (full description)
ReadOnlyArrayIterator -- Iterate a const Array cursor through a const Array. (full description)

template<class T> class ArrayIterator : public ArrayPositionIterator

Interface

Public Members
explicit ArrayIterator(Array<T> &arr, uInt byDim=1)
ArrayIterator(Array<T> &arr, const IPosition &axes, Bool axesAreCursor = True)
virtual ~ArrayIterator()
virtual void next()
virtual void reset()
Array<T> &array()
Private Members
void init(Array<T> &)
void apSetPointer(Int stepDim)
ArrayIterator(const ArrayIterator<T> &)
ArrayIterator<T> &operator=(const ArrayIterator<T> &)

Description

Review Status

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

ArrayIterator steps an array section (the "cursor") through an array. The cursor "refers" to storage in the array, so that changing the values in the cursor changes values in the original array. Like with ArrayPositionIterator, the cursor presently only moves through the array from bottom to top in the obvious way; however one may of course iterate through a slice ("array section"). This class is derived from ArrayPositionIterator since it also has a position (the blc of the cursor) which moves through the array volume.

Tip The origin of the cursor, i.e. the subarray that moves through the larger array, is always zero.
    Array<Float> to, from;
    //... set to and from, check that they are conformant
    ArrayIterator toiter(to,1);
    ArrayIterator fromiter(from,1);
    while (! toiter.pastEnd() ) {
        toiter.array() = fromiter.array();  // copy vector by vector
        toiter.next(); fromiter.next();
    }
    
    

Member Description

explicit ArrayIterator(Array<T> &arr, uInt byDim=1)

Step through array "arr" over the first byDim axes (using a cursor of dimensionality "byDim").

ArrayIterator(Array<T> &arr, const IPosition &axes, Bool axesAreCursor = True)

Step through an array using the given axes. The axes can be given in two ways:

  1. axesAreCursor=True means that the axes form the cursor axes. The remaining axes will form the iteration axes. This is the default.
  2. axesAreCursor=False means the opposite. In this case the iteration axes can be given in any order.
E.g. when using iteration axes 2,0 for an array with shape [5,3,7], each iteration step returns a cursor (containing the data of axis 1). During the iteration axis 2 will vary most rapidly (as it was given first).

virtual ~ArrayIterator()

virtual void next()

Move the cursor to the next position.

virtual void reset()

Reset the cursor to the beginning.

Array<T> &array()

Return the cursor. (Perhaps we should have a fn() that returns a reference to the original array as well?)

void init(Array<T> &)

helper function to centralize construction work

void apSetPointer(Int stepDim)

helper function to set the pointer to the new data position in ap after a step in the given dimension. -1 resets it to the beginning.

ArrayIterator(const ArrayIterator<T> &)

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


template<class T> class ReadOnlyArrayIterator

Interface

Public Members
explicit ReadOnlyArrayIterator(const Array<T> &arr, uInt byDim=1) : ai(const_cast<Array<T>&>(arr),byDim)
ReadOnlyArrayIterator(const Array<T> &arr, const arr &axes, Bool axesAreCursor = True) : ai(const_cast<Array<T>&>(arr),axes,axesAreCursor)
void next()
void reset()
void origin()
const Array<T> &array()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
IPosition endPos() const
uInt ndim() const
Private Members
ReadOnlyArrayIterator (const ReadOnlyArrayIterator<T> &)
ReadOnlyArrayIterator<T> &operator=(const ReadOnlyArrayIterator<T> &)

Description

Review Status

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

This class behaves exactly like an ArrayIterator, only it iterates through const Arrays.

    void CopyArray(Array<Float> &to, const Array<Float> &from)
    {
        //... check that they are conformant
        ArrayIterator toiter(to,1);
        ReadOnlyArrayIterator fromiter(from,1);
        while (! toiter.pastEnd() ) {
            toiter.array() = fromiter.array();  // copy vector by vector
            toiter.next(); fromiter.next();
        }
    }
    
Tip This class is not derived from ArrayPositionIterator. For simplicity it merely contains an ArrayIterator to which it forwards requests and returns (const) results. The iterator classes should be rethought and reimplemented.

Member Description

explicit ReadOnlyArrayIterator(const Array<T> &arr, uInt byDim=1) : ai(const_cast<Array<T>&>(arr),byDim)

Step through array "arr" using a cursor of dimensionality "byDim".

ReadOnlyArrayIterator(const Array<T> &arr, const arr &axes, Bool axesAreCursor = True) : ai(const_cast<Array<T>&>(arr),axes,axesAreCursor)

Step through an array for the given iteration axes.

void next()

Move the cursor to the next position.

void reset()
void origin()

Reset the cursor to the beginning.

const Array<T> &array()

Return the cursor. (Perhaps we should have a fn() that returns a reference to the original array as well?)

Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
IPosition endPos() const
uInt ndim() const

The same as the functions in ArrayPositionIterator.

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

Not implemented.