casacore
Public Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
casacore::ArrayIterator< T, Alloc > Class Template Reference

More...

#include <ArrayIter.h>

Public Member Functions

 ArrayIterator (const Array< T, Alloc > &arr, size_t byDim=1)
 Step through array "arr" over the first byDim axes (using a cursor of dimensionality "byDim"). More...
 
 ArrayIterator (const Array< T, Alloc > &arr, const IPosition &axes, bool axesAreCursor=true)
 Step through an array using the given axes. More...
 
virtual void next () override
 Move the cursor to the next position. More...
 
virtual void set (const IPosition &cursorPos) override
 Set the cursor to the given position. More...
 
virtual void reset () override
 Reset the cursor to the beginning. More...
 
Array< T, Alloc > & array ()
 Return the cursor. More...
 
virtual ArrayBasegetArray () override
 Get the array in the cursor. More...
 
- Public Member Functions inherited from casacore::ArrayPositionIterator
 ArrayPositionIterator (const IPosition &shape, const IPosition &origin, size_t byDim)
 Define the shape and origin of the volume the cursor will step through. More...
 
 ArrayPositionIterator (const IPosition &shape, size_t byDim)
 
 ArrayPositionIterator (const IPosition &shape, const IPosition &axes, bool axesAreCursor=true)
 Step through an array using the given axes. More...
 
virtual ~ArrayPositionIterator ()
 
void origin ()
 
bool atStart () const
 Returns true of the cursor is at the origin. More...
 
bool pastEnd () const
 Returns true if the cursor has moved past the end of its volume. More...
 
const IPositionpos () const
 Return the position of the cursor. More...
 
IPosition endPos () const
 Return the end position of the cursor. More...
 
size_t ndim () const
 What is the dimensionality of the volume we are iterating through? More...
 
const IPositioniterAxes () const
 Return the iteration axes. More...
 
const IPositioncursorAxes () const
 Return the cursor axes. More...
 

Protected Attributes

std::unique_ptr< Array< T, Alloc > > ap_p
 The cursor. More...
 

Private Member Functions

void init (const Array< T, Alloc > &)
 helper function to centralize construction work More...
 
void apSetPointer (int stepDim)
 helper function to set the pointer to the new data position in ap after a step in the given dimension. More...
 
 ArrayIterator (const ArrayIterator< T, Alloc > &)
 
ArrayIterator< T, Alloc > & operator= (const ArrayIterator< T, Alloc > &)
 

Private Attributes

Array< T, Alloc > pOriginalArray_p
 
IPosition offset_p
 
T * dataPtr_p
 

Additional Inherited Members

- Protected Member Functions inherited from casacore::ArrayPositionIterator
size_t nextStep ()
 Advance cursor to its next position and tell which dimension stepped. More...
 
size_t dimIter () const
 What is the dimensionality of the "step" the cursor takes, i.e. More...
 

Detailed Description

template<typename T, typename Alloc>
class casacore::ArrayIterator< T, Alloc >

Iterate an Array cursor through another Array.

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();
}
ArrayIterator(const Array< T, Alloc > &arr, size_t byDim=1)
Step through array "arr" over the first byDim axes (using a cursor of dimensionality "byDim").

Definition at line 71 of file ArrayIter.h.

Constructor & Destructor Documentation

◆ ArrayIterator() [1/3]

template<typename T , typename Alloc >
casacore::ArrayIterator< T, Alloc >::ArrayIterator ( const Array< T, Alloc > &  arr,
size_t  byDim = 1 
)
explicit

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

◆ ArrayIterator() [2/3]

template<typename T , typename Alloc >
casacore::ArrayIterator< T, Alloc >::ArrayIterator ( const Array< T, Alloc > &  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).

◆ ArrayIterator() [3/3]

template<typename T , typename Alloc >
casacore::ArrayIterator< T, Alloc >::ArrayIterator ( const ArrayIterator< T, Alloc > &  )
private

Member Function Documentation

◆ apSetPointer()

template<typename T , typename Alloc >
void casacore::ArrayIterator< T, Alloc >::apSetPointer ( int  stepDim)
private

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.

◆ array()

template<typename T , typename Alloc >
Array<T, Alloc>& casacore::ArrayIterator< T, Alloc >::array ( )
inline

Return the cursor.

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

Definition at line 115 of file ArrayIter.h.

References casacore::ArrayIterator< T, Alloc >::ap_p.

Referenced by casacore::TableExprGroupAggr::getArray(), casacore::TableProxy::record2Array(), and casacore::TableExprNodeSet::toArray().

◆ getArray()

template<typename T , typename Alloc >
virtual ArrayBase& casacore::ArrayIterator< T, Alloc >::getArray ( )
overridevirtual

Get the array in the cursor.

This is only implemented in the derived ArrayIterator class. By default it throws an exception.

Reimplemented from casacore::ArrayPositionIterator.

◆ init()

template<typename T , typename Alloc >
void casacore::ArrayIterator< T, Alloc >::init ( const Array< T, Alloc > &  )
private

helper function to centralize construction work

◆ next()

template<typename T , typename Alloc >
virtual void casacore::ArrayIterator< T, Alloc >::next ( )
overridevirtual

◆ operator=()

template<typename T , typename Alloc >
ArrayIterator<T, Alloc>& casacore::ArrayIterator< T, Alloc >::operator= ( const ArrayIterator< T, Alloc > &  )
private

◆ reset()

template<typename T , typename Alloc >
virtual void casacore::ArrayIterator< T, Alloc >::reset ( )
overridevirtual

Reset the cursor to the beginning.

Reimplemented from casacore::ArrayPositionIterator.

◆ set()

template<typename T , typename Alloc >
virtual void casacore::ArrayIterator< T, Alloc >::set ( const IPosition cursorPos)
overridevirtual

Set the cursor to the given position.

The position can only contain the iteration axes or it can be the full position.
In the first case the position must to be given in the order of the iteration axes as given in the constructor. In the latter case the position must be given in natural order (as given by function pos and only the cursor axes are taken into account.

Reimplemented from casacore::ArrayPositionIterator.

Member Data Documentation

◆ ap_p

template<typename T , typename Alloc >
std::unique_ptr<Array<T, Alloc> > casacore::ArrayIterator< T, Alloc >::ap_p
protected

The cursor.

Definition at line 122 of file ArrayIter.h.

Referenced by casacore::ArrayIterator< T, Alloc >::array().

◆ dataPtr_p

template<typename T , typename Alloc >
T* casacore::ArrayIterator< T, Alloc >::dataPtr_p
private

Definition at line 133 of file ArrayIter.h.

◆ offset_p

template<typename T , typename Alloc >
IPosition casacore::ArrayIterator< T, Alloc >::offset_p
private

Definition at line 132 of file ArrayIter.h.

◆ pOriginalArray_p

template<typename T , typename Alloc >
Array<T, Alloc> casacore::ArrayIterator< T, Alloc >::pOriginalArray_p
private

Definition at line 131 of file ArrayIter.h.


The documentation for this class was generated from the following files: