npstat is hosted by Hepforge, IPPP Durham
NPStat  5.10.0
npstat::ArrayNDScanner Class Reference

#include <ArrayNDScanner.hh>

Public Member Functions

 ArrayNDScanner (const unsigned *shape, const unsigned lenShape)
 
 ArrayNDScanner (const std::vector< unsigned > &shape)
 
unsigned dim () const
 
unsigned long state () const
 
unsigned long maxState () const
 
bool isValid () const
 
void getIndex (unsigned *index, unsigned indexBufferLen) const
 
void reset ()
 
ArrayNDScanneroperator++ ()
 
void operator++ (int)
 
void setState (const unsigned long state)
 

Detailed Description

This class can be used to iterate over array indices without actually building the array or requesting any memory from the heap. Typical use:

for (ArrayNDScanner scanner(shape); scanner.isValid(); ++scanner)
{
scanner.getIndex(indexArray, indexArrayLen);
.... Do what is necessary with multidimensional index ....
.... Extract linear index: ...............................
scanner.state();
}

This can be useful, for example, in case one needs to iterate over slices of some array (so that the array itself can not be used to obtain similar information easily).

Constructor & Destructor Documentation

◆ ArrayNDScanner()

npstat::ArrayNDScanner::ArrayNDScanner ( const unsigned *  shape,
const unsigned  lenShape 
)
inline

Constructor from a multidimensional array shape

Member Function Documentation

◆ dim()

unsigned npstat::ArrayNDScanner::dim ( ) const
inline

Dimensionality of the scan

◆ getIndex()

void npstat::ArrayNDScanner::getIndex ( unsigned *  index,
unsigned  indexBufferLen 
) const

Retrieve current multidimensional index

◆ isValid()

bool npstat::ArrayNDScanner::isValid ( ) const
inline

Returns false when iteration is complete

◆ maxState()

unsigned long npstat::ArrayNDScanner::maxState ( ) const
inline

Maximum possible state (i.e., linear index of the scan)

◆ operator++() [1/2]

ArrayNDScanner& npstat::ArrayNDScanner::operator++ ( )
inline

Prefix increment

◆ operator++() [2/2]

void npstat::ArrayNDScanner::operator++ ( int  )
inline

Postfix increment (distinguished by the dummy "int" parameter)

◆ reset()

void npstat::ArrayNDScanner::reset ( )
inline

Reset the state (as if the object has just been constructed)

◆ setState()

void npstat::ArrayNDScanner::setState ( const unsigned long  state)
inline

Set the state directly

◆ state()

unsigned long npstat::ArrayNDScanner::state ( ) const
inline

Retrieve current state (i.e., linear index of the scan)


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