ArrayPosIter.h

Classes

ArrayPositionIterator -- Iterate an IPosition through the shape of an Array (full description)

class ArrayPositionIterator

Interface

Public Members
ArrayPositionIterator(const IPosition &shape, const IPosition &origin, uInt byDim)
ArrayPositionIterator(const IPosition &shape, uInt byDim)
virtual ~ArrayPositionIterator()
virtual void origin()
Bool atStart() const
Bool pastEnd() const
const IPosition &pos() const
virtual void next()
uInt ndim() const
uInt dimIter() const
uInt nSteps() const
Protected Members
uInt nextStep()
Private Members
void setup()

Description

ArrayPositionIterator manipulates an IPosition "cursor" through some volume defined by an origin and shape. This position can in turn be used to index into, or otherwise define a position in, an Array. Normally users won't use this class directly, rather they will use an ArrayIterator, VectorIterator or MatrixIterator object, which in turn uses this class. ArrayPositionIterator is also used in the implementation of Array.

    template<class T> void verySlowArrayCopy(Array<T> &to, const Array<T> &from)
    {
        if (! to.conform(from)) {
           // throw some error
        }
        ArrayPositionIterator toiter(to.shape(), to.origin(),0);
        ArrayPositionIterator fromiter(from.shape(), from.origin(),0);
        // If to.origin() == from.origin() we only need one iterator
        // or we could offset positions by the difference in origins.
        // The "0" means we are stepping by scalars.
        while (! toiter.pastEnd()) {    // we know arrays conform
            to(toiter.pos()) = fromiter(fromiter.pos());
            toiter.next(); fromiter.next();
        }
    }
    

At the moment this only iterates by the simplest "bottom to top" order, and the iteration step always "fills up" its dimensionality. e.g., if we are stepping through a cube by matrices, the matrix completely fills up the plane. These restrictions should be removed eventually.

Tip All the array iterator classes should probably be reimplemented; their implementation is a bit ugly.

Member Description

ArrayPositionIterator(const IPosition &shape, const IPosition &origin, uInt byDim)
ArrayPositionIterator(const IPosition &shape, uInt byDim)

Define the shape and origin of the volume the cursor will step through. Also define the dimensionality of the step. byDim==0 implies we are stepping by scalars (i.e. every element), byDim==1 implies that we are stepping by vector, ==2 by matrices, and so on.

virtual ~ArrayPositionIterator()

virtual void origin()

Reset the cursor to the beginning of the volume.

Bool atStart() const

Returns true of the cursor is at the origin.

Bool pastEnd() const

Returns true if the cursor has moved past the end of its volume.

const IPosition &pos() const

Return the position of the cursor.

virtual void next()

Advance the cursor to its next position.

uInt ndim() const

What is the dimensionality of the volume we are iterating through?

uInt dimIter() const

What is the dimensionality of the "step" the cursor takes, i.e. 0 for scalars, 1 for vector, ....

uInt nSteps() const

How many steps have we taken from the beginning?

uInt nextStep()

Advance cursor to its next position and tell which dimension stepped.

void setup()

Setup the object for the constructor.