Main Page   Class Hierarchy   Compound List   File List   Compound Members   File Members   Related Pages  

MultiDimArrayIndexRange Class Template Reference

Handles index ranges for multidimensional arrays. More...

#include <MultiDimArrayAccess.h>

List of all members.

Public Methods

 MultiDimArrayIndexRange (const size_t *sz=((size_t *) 0), const int *st=((int *) 0), bool reverse=false)
 Constructor for setting index data using size and initial values. More...

 MultiDimArrayIndexRange (const int *si, const int *sf, bool reverse=false)
 Constructor for setting index data to a range. More...

 MultiDimArrayIndexRange (const size_t *sz=((size_t *) 0), const int *st=((int *) 0), bool reverse=false)
 Constructor for setting index data using size and initial values. More...

 MultiDimArrayIndexRange (const int *si, const int *sf, bool reverse=false)
 Constructor for setting index data to a range. More...

Functions to set indices
void setSizeAndStart (const size_t *sz=((size_t *) 0), const int *st=((int *) 0), bool reverse=false)
void setInclusiveRange (const int first[DIM], const int final[DIM], bool reverse=false)
void reverseDim ()
 Reverse the ordering of the dimensions. More...

const MultiDimArrayIndexRange & adjustDim (int d, int first, int final)
 Adjust the dimensions. More...

Functions to facilitate looping
int beg (size_t i) const
 Give starting index. More...

int end (size_t i) const
 Give ending index (one more than the last valid index). More...

size_t size (size_t i) const
 Give size. More...

Functions computing offsets
int offset (int i0) const
 Offset for a 1D array (not for use with any other type arrays). More...

int offset (int i0, int i1) const
 Offset for a 2D array (not for use with any other type arrays). More...

int offset (int i0, int i1, int i2) const
 Offset for a 3D array (not for use with any other type arrays). More...

int offset (int i0, int i1, int i2, int i3) const
 Offset for a 4D array (not for use with any other type arrays). More...

Functions to set indices
void setSizeAndStart (const size_t *sz=((size_t *) 0), const int *st=((int *) 0), bool reverse=false)
void setInclusiveRange (const int first[DIM], const int final[DIM], bool reverse=false)
void reverseDim ()
 Reverse the ordering of the dimensions. More...

const MultiDimArrayIndexRange & adjustDim (int d, int first, int final)
 Adjust the dimensions. More...

Functions to facilitate looping
int beg (size_t i) const
 Give starting index. More...

int end (size_t i) const
 Give ending index (one more than the last valid index). More...

size_t size (size_t i) const
 Give size. More...

Functions computing offsets
int offset (int i0) const
 Offset for a 1D array (not for use with any other type arrays). More...

int offset (int i0, int i1) const
 Offset for a 2D array (not for use with any other type arrays). More...

int offset (int i0, int i1, int i2) const
 Offset for a 3D array (not for use with any other type arrays). More...

int offset (int i0, int i1, int i2, int i3) const
 Offset for a 4D array (not for use with any other type arrays). More...


Protected Attributes

int d_start [DIM]
 Array of starting indices. More...

size_t d_size [DIM]
 Array of sizes. More...


Friends

IO functions
ostream & operator<< (ostream &os, const MultiDimArrayIndexRange< DIM > &r)
 Output to ostream. More...

istream & operator<< (istream &is, MultiDimArrayIndexRange< DIM > &r)
 Input from istream. More...

IO functions
ostream & operator<< (ostream &os, const MultiDimArrayIndexRange< DIM > &r)
 Output to ostream. More...

istream & operator<< (istream &is, MultiDimArrayIndexRange< DIM > &r)
 Input from istream. More...


Detailed Description

template<int DIM>
class MultiDimArrayIndexRange< DIM >

Handles index ranges for multidimensional arrays.

The member functions should all be inlined for better performance.

Definition at line 15 of file MultiDimArrayAccess.h.


Constructor & Destructor Documentation

template<int DIM>
MultiDimArrayIndexRange< DIM >::MultiDimArrayIndexRange const size_t *    sz = ((size_t*)0),
const int *    st = ((int*)0),
bool    reverse = false
[inline]
 

Constructor for setting index data using size and initial values.

Any pointers that are NULL are not used. The resulting default settings are:

  • Array sizes are 0
  • Array starting indices are 0
  • Dimension indices are not reversed
There is another constructor which accepts the first and final indices instead of the sizes and first indices. NOTE: the place of the initial indices is different than it is for the constructor taking final indices instead of sizes.
Parameters:
sz  Array sizes
st  Array starting indices
reverse  Reverse indices flag

Definition at line 38 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().

template<int DIM>
MultiDimArrayIndexRange< DIM >::MultiDimArrayIndexRange const int *    si,
const int *    sf,
bool    reverse = false
[inline]
 

Constructor for setting index data to a range.

Any pointers that are NULL are not used. The resulting default settings are:

  • Array sizes are 0
  • Array starting indices are 0
  • Dimension indices are not reversed
This version takes two int* arguments, for the initial and final indices. It does not support default arguments until after the indices argument. NOTE: the place of the initial indices is different than it is for the constructor taking sizes instead of final indices.

If si is NULL, starting indices are set to 0. If sf is NULL, sizes are set to zero.

Parameters:
si  Array of initial indices
sf  Array of final indices
reverse  Reverse indices flag

Definition at line 68 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().

template<int DIM>
MultiDimArrayIndexRange< DIM >::MultiDimArrayIndexRange const size_t *    sz = ((size_t*)0),
const int *    st = ((int*)0),
bool    reverse = false
[inline]
 

Constructor for setting index data using size and initial values.

Any pointers that are NULL are not used. The resulting default settings are:

  • Array sizes are 0
  • Array starting indices are 0
  • Dimension indices are not reversed
There is another constructor which accepts the first and final indices instead of the sizes and first indices. NOTE: the place of the initial indices is different than it is for the constructor taking final indices instead of sizes.
Parameters:
sz  Array sizes
st  Array starting indices
reverse  Reverse indices flag

Definition at line 38 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().

template<int DIM>
MultiDimArrayIndexRange< DIM >::MultiDimArrayIndexRange const int *    si,
const int *    sf,
bool    reverse = false
[inline]
 

Constructor for setting index data to a range.

Any pointers that are NULL are not used. The resulting default settings are:

  • Array sizes are 0
  • Array starting indices are 0
  • Dimension indices are not reversed
This version takes two int* arguments, for the initial and final indices. It does not support default arguments until after the indices argument. NOTE: the place of the initial indices is different than it is for the constructor taking sizes instead of final indices.

If si is NULL, starting indices are set to 0. If sf is NULL, sizes are set to zero.

Parameters:
si  Array of initial indices
sf  Array of final indices
reverse  Reverse indices flag

Definition at line 68 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().


Member Function Documentation

template<int DIM>
const MultiDimArrayIndexRange& MultiDimArrayIndexRange< DIM >::adjustDim int    d,
int    first,
int    final
[inline]
 

Adjust the dimensions.

Adjust the first and final indices. Set the dimension to adjust to < 0 or >= DIM to adjust all dimensions. Note: The third argument is the increment to the final index and not the size.

Note: No error checking is done, for example, to make sure that the resulting size is non-negative.

Returns:
Adjusted MultiDimArrayIndexRange object
Parameters:
d  Dimension to adjust
first  Increment to first index
final  Increment to final index

Definition at line 153 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
const MultiDimArrayIndexRange& MultiDimArrayIndexRange< DIM >::adjustDim int    d,
int    first,
int    final
[inline]
 

Adjust the dimensions.

Adjust the first and final indices. Set the dimension to adjust to < 0 or >= DIM to adjust all dimensions. Note: The third argument is the increment to the final index and not the size.

Note: No error checking is done, for example, to make sure that the resulting size is non-negative.

Returns:
Adjusted MultiDimArrayIndexRange object
Parameters:
d  Dimension to adjust
first  Increment to first index
final  Increment to final index

Definition at line 153 of file MultiDimArrayAccess.h.

References d_size, and d_start.

Referenced by ConstMultiDimArrayAccess::adjustDim(), MultiDimArrayAccess::adjustDim(), and reverseDim().

template<int DIM>
int MultiDimArrayIndexRange< DIM >::beg size_t    i const [inline]
 

Give starting index.

Parameters:
i  index of dimension

Definition at line 203 of file MultiDimArrayAccess.h.

References d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::beg size_t    i const [inline]
 

Give starting index.

Parameters:
i  index of dimension

Definition at line 203 of file MultiDimArrayAccess.h.

References d_start.

Referenced by ConstMultiDimArrayAccess::beg(), and MultiDimArrayAccess::beg().

template<int DIM>
int MultiDimArrayIndexRange< DIM >::end size_t    i const [inline]
 

Give ending index (one more than the last valid index).

Parameters:
i  index of dimension

Definition at line 208 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::end size_t    i const [inline]
 

Give ending index (one more than the last valid index).

Parameters:
i  index of dimension

Definition at line 208 of file MultiDimArrayAccess.h.

References d_size, and d_start.

Referenced by ConstMultiDimArrayAccess::end(), and MultiDimArrayAccess::end().

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0,
int    i1,
int    i2,
int    i3
const [inline]
 

Offset for a 4D array (not for use with any other type arrays).

Parameters:
i0  First index of item
i1  Second index of item
i2  Third index of item
i3  Fourth index of item

Definition at line 248 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0,
int    i1,
int    i2
const [inline]
 

Offset for a 3D array (not for use with any other type arrays).

Parameters:
i0  First index of item
i1  Second index of item
i2  Third index of item

Definition at line 239 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0,
int    i1
const [inline]
 

Offset for a 2D array (not for use with any other type arrays).

Parameters:
i0  First index of item
i1  Second index of item

Definition at line 231 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0 const [inline]
 

Offset for a 1D array (not for use with any other type arrays).

Parameters:
i0  Index of item

Definition at line 224 of file MultiDimArrayAccess.h.

References d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0,
int    i1,
int    i2,
int    i3
const [inline]
 

Offset for a 4D array (not for use with any other type arrays).

Parameters:
i0  First index of item
i1  Second index of item
i2  Third index of item
i3  Fourth index of item

Definition at line 248 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0,
int    i1,
int    i2
const [inline]
 

Offset for a 3D array (not for use with any other type arrays).

Parameters:
i0  First index of item
i1  Second index of item
i2  Third index of item

Definition at line 239 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0,
int    i1
const [inline]
 

Offset for a 2D array (not for use with any other type arrays).

Parameters:
i0  First index of item
i1  Second index of item

Definition at line 231 of file MultiDimArrayAccess.h.

References d_size, and d_start.

template<int DIM>
int MultiDimArrayIndexRange< DIM >::offset int    i0 const [inline]
 

Offset for a 1D array (not for use with any other type arrays).

Parameters:
i0  Index of item

Definition at line 224 of file MultiDimArrayAccess.h.

References d_start.

Referenced by ConstMultiDimArrayAccess::operator()(), and MultiDimArrayAccess::operator()().

template<int DIM>
void MultiDimArrayIndexRange< DIM >::reverseDim   [inline]
 

Reverse the ordering of the dimensions.

This tells the object that the indices you have set If you do this, you should also reverse your indices to the offset functions.

Use this to accomodate Fortran ordering.

Example, the 2x3 arrays declared in C with ca[2][3] and FORTRAN with fa(2,3) have different memory arangements. But because you think of them as 2x3 arrays, you pass in {2,3} for their dimensions. In this case, dereferencing the C array with this class works, but dereferencing the FORTRAN array will not work. To use with FORTRAN-declared arrays, you should use reverseDim() to tell the object that the array is really a 3x2 array. Then don't forget to reverse the order of the arguments to offset also.

Definition at line 131 of file MultiDimArrayAccess.h.

References adjustDim(), d_size, and d_start.

template<int DIM>
void MultiDimArrayIndexRange< DIM >::reverseDim   [inline]
 

Reverse the ordering of the dimensions.

This tells the object that the indices you have set If you do this, you should also reverse your indices to the offset functions.

Use this to accomodate Fortran ordering.

Example, the 2x3 arrays declared in C with ca[2][3] and FORTRAN with fa(2,3) have different memory arangements. But because you think of them as 2x3 arrays, you pass in {2,3} for their dimensions. In this case, dereferencing the C array with this class works, but dereferencing the FORTRAN array will not work. To use with FORTRAN-declared arrays, you should use reverseDim() to tell the object that the array is really a 3x2 array. Then don't forget to reverse the order of the arguments to offset also.

Definition at line 131 of file MultiDimArrayAccess.h.

References adjustDim(), d_size, and d_start.

Referenced by MultiDimArrayIndexRange(), ConstMultiDimArrayAccess::reverseDim(), MultiDimArrayAccess::reverseDim(), setInclusiveRange(), and setSizeAndStart().

template<int DIM>
void MultiDimArrayIndexRange< DIM >::setInclusiveRange const int    first[DIM],
const int    final[DIM],
bool    reverse = false
[inline]
 

Set first and final indices (inclusive).

Parameters:
first  First valid indices (NULL for no change)
final  Final valid indices (NULL for no change)
reverse  Reverse indices flag

Definition at line 100 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().

template<int DIM>
void MultiDimArrayIndexRange< DIM >::setInclusiveRange const int    first[DIM],
const int    final[DIM],
bool    reverse = false
[inline]
 

Set first and final indices (inclusive).

Parameters:
first  First valid indices (NULL for no change)
final  Final valid indices (NULL for no change)
reverse  Reverse indices flag

Definition at line 100 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().

template<int DIM>
void MultiDimArrayIndexRange< DIM >::setSizeAndStart const size_t *    sz = ((size_t*)0),
const int *    st = ((int*)0),
bool    reverse = false
[inline]
 

Set size and starting indices.

Parameters:
sz  Array sizes (NULL for no change)
st  Starting indices (NULL for no change)
reverse  Reverse indices flag

Definition at line 86 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().

template<int DIM>
void MultiDimArrayIndexRange< DIM >::setSizeAndStart const size_t *    sz = ((size_t*)0),
const int *    st = ((int*)0),
bool    reverse = false
[inline]
 

Set size and starting indices.

Parameters:
sz  Array sizes (NULL for no change)
st  Starting indices (NULL for no change)
reverse  Reverse indices flag

Definition at line 86 of file MultiDimArrayAccess.h.

References d_size, d_start, and reverseDim().

Referenced by ConstMultiDimArrayAccess::ConstMultiDimArrayAccess().

template<int DIM>
size_t MultiDimArrayIndexRange< DIM >::size size_t    i const [inline]
 

Give size.

Parameters:
i  index of dimension

Definition at line 213 of file MultiDimArrayAccess.h.

References d_size.

template<int DIM>
size_t MultiDimArrayIndexRange< DIM >::size size_t    i const [inline]
 

Give size.

Parameters:
i  index of dimension

Definition at line 213 of file MultiDimArrayAccess.h.

References d_size.

Referenced by ConstMultiDimArrayAccess::size(), and MultiDimArrayAccess::size().


Friends And Related Function Documentation

template<int DIM>
istream& operator<< istream &    is,
MultiDimArrayIndexRange< DIM > &    r
[friend]
 

Input from istream.

Definition at line 188 of file MultiDimArrayAccess.h.

template<int DIM>
ostream& operator<< ostream &    os,
const MultiDimArrayIndexRange< DIM > &    r
[friend]
 

Output to ostream.

Definition at line 179 of file MultiDimArrayAccess.h.

template<int DIM>
istream& operator<< istream &    is,
MultiDimArrayIndexRange< DIM > &    r
[friend]
 

Input from istream.

Definition at line 188 of file MultiDimArrayAccess.h.

template<int DIM>
ostream& operator<< ostream &    os,
const MultiDimArrayIndexRange< DIM > &    r
[friend]
 

Output to ostream.

Definition at line 179 of file MultiDimArrayAccess.h.


Member Data Documentation

template<int DIM>
size_t MultiDimArrayIndexRange< DIM >::d_size [protected]
 

Array of sizes.

Definition at line 20 of file MultiDimArrayAccess.h.

Referenced by adjustDim(), end(), MultiDimArrayIndexRange(), offset(), reverseDim(), setInclusiveRange(), setSizeAndStart(), and size().

template<int DIM>
int MultiDimArrayIndexRange< DIM >::d_start [protected]
 

Array of starting indices.

Definition at line 18 of file MultiDimArrayAccess.h.

Referenced by adjustDim(), beg(), end(), MultiDimArrayIndexRange(), offset(), reverseDim(), setInclusiveRange(), and setSizeAndStart().


The documentation for this class was generated from the following files:
Generated on Wed Apr 17 12:51:48 2002 for samtut by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001