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
ArrayIterator(Array<T> &arr, uInt byDim)
ArrayIterator(Array<T> &arr)
virtual ~ArrayIterator()
void next()
void origin()
Array<T> &array()
Private Members
void init(Array<T> &)
void apSetPointer(Int stepDim)
ArrayIterator(const ArrayIterator<T> &)
ArrayIterator<T> &operator=(const ArrayIterator<T> &)

Description

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

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

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

ArrayIterator(Array<T> &arr)

Step through "arr" with a cursor of dimensionality 1.

virtual ~ArrayIterator()

void next()

Move the cursor to the next position.

void origin()

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
ReadOnlyArrayIterator(const Array<T> &arr, uInt byDim=1) : ai((Array<T> &)arr,byDim)
ReadOnlyArrayIterator<T> &operator=(const ReadOnlyArrayIterator<T> &)
void next()
void origin()
const Array<T> &array()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
uInt ndim() const
uInt dimIter() const
uInt nSteps() const

Description

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

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

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

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

Not implemented.

void next()

Move the cursor to the next position.

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
uInt ndim() const
uInt dimIter() const
uInt nSteps() const

The same as the function in ArrayPositionIterator.