MDA_Access< MDA_TYPE, MDA_DIM, OrderType > Class Template Reference

Non-const multidimensional array access. More...

#include <source/patchdata/array/array_access/MDA_Access.h>

Inheritance diagram for MDA_Access< MDA_TYPE, MDA_DIM, OrderType >:

Inheritance graph
[legend]
List of all members.

Public Types

typedef MDA_TYPE value_t
 Type of data.
typedef MDA_IndexRange< MDA_DIM > range_t
typedef range_t::dim_t dim_t
typedef range_t::index_t index_t
typedef OrderType order_t
typedef OrderType::reduced_order_t reduced_order_t

Public Member Functions

 MDA_Access (value_t *p=((value_t *) 0), const size_t *sz=((size_t *) 0), const index_t *st=((index_t *) 0))
 Constructor for setting all data, with default values.
 MDA_Access (value_t *p, const index_t *si, const index_t *sf)
 Constructor for setting all data, with default values.
 MDA_Access (value_t *p, const order_t &r)
 Constructor for specifying pointer and ordering object.
 MDA_Access (const MDA_Access &r)
 Copy constructor.
virtual ~MDA_Access ()
 Virtual destructor to support inheritance.
 operator bool () const
 Conversion into boolean.
 operator value_t * () const
 Conversion into pointer.
void setPointer (value_t *p)
 Set the data pointer.
void setSizeAndStart (const size_t *sz=((size_t *) 0), const index_t *st=((index_t *) 0))
void setInclusiveRange (const index_t first[MDA_DIM], const index_t final[MDA_DIM])
const range_tadjustDim (dim_t d, index_t first, index_t final)
 Adjust the dimensions.
Equivalence comparison
bool operator== (const MDA_Access &r) const
Inequivalence comparison
bool operator!= (const MDA_Access &r) const
Inequivalence comparison
const range_trange () const
const index_tbeg (size_t i) const
const index_tend (size_t i) const
const size_t & size (size_t i) const
value_toperator() (const index_t i[MDA_DIM]) const
 Grant general access to item in an arbitrary dimensional array.
value_toperator() (index_t i0) const
 Grant general access to item in a 1D array.
value_toperator() (index_t i0, index_t i1) const
 Grant general access to item in a 2D array.
value_toperator() (index_t i0, index_t i1, index_t i2) const
 Grant general access to item in a 3D array.
value_toperator() (index_t i0, index_t i1, index_t i2, index_t i3) const
 Grant general access to item in a 4D array.
value_toperator[] (index_t i0) const
 Special case for 1D arrays, identical to operator(index_t), using pre-added fixed offsets.
MDA_Access< MDA_TYPE, OrderType::MDA_Reduced_DIM,
typename OrderType::reduced_order_t > 
reduce (index_t i) const
 Fix the index of the slowest dimension and return the corresponding sub-array.

Detailed Description

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
class MDA_Access< MDA_TYPE, MDA_DIM, OrderType >

Non-const multidimensional array access.

This class never allocates or deallocates data. It takes pointers to preallocated data and provides an interface to that data. Member functions are used to give that interface.

This class provides functions for explicit index checking, but it does NO implicit error checking on either the dimensionality of the array or it size. Such may be done through subclassing.

The member functions should all be inlined for better performance.

This template class is set up to work with either row-major or column-major data, depending on the third template argument, which should be one of

  1. MDA_OrderRowMajor (default if omitted)
  2. MDA_OrderColMajor

The reduce() function return a new array of smaller dimensional that require less integer arithmetic to access individual array members. This should help in optimizing code. (My preliminary performance tests using gcc and gprof on i686 Linux showed that the MDA_Access functions run at half to slightly faster than the speed of Fortran, depending on use of reduced arrays. However, note that gcc is not great at optimizing Fortran.)


Member Typedef Documentation

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
typedef MDA_TYPE MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::value_t

Type of data.

Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
typedef MDA_IndexRange<MDA_DIM> MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::range_t

Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
typedef range_t::dim_t MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::dim_t

Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
typedef range_t::index_t MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::index_t

Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
typedef OrderType MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::order_t

Reimplemented in MDA_AccessConst< MDA_TYPE, MDA_DIM, OrderType >.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
typedef OrderType::reduced_order_t MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::reduced_order_t


Constructor & Destructor Documentation

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access ( value_t p = ((value_t*)0),
const size_t *  sz = ((size_t*)0),
const index_t st = ((index_t*)0) 
) [inline]

Constructor for setting all data, with default values.

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

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:
p  Pointer to data
sz  Array sizes
st  Array starting indices

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access ( value_t p,
const index_t si,
const index_t sf 
) [inline]

Constructor for setting all data, with default values.

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

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:
p  Pointer to data
si  Array of initial indices
sf  Array of final indices

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access ( value_t p,
const order_t r 
) [inline]

Constructor for specifying pointer and ordering object.

Parameters:
p  Pointer to data
r  Array index object

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::MDA_Access ( const MDA_Access< MDA_TYPE, MDA_DIM, OrderType > &  r  )  [inline]

Copy constructor.

Parameters:
r  Copyee object

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
virtual MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::~MDA_Access (  )  [inline, virtual]

Virtual destructor to support inheritance.


Member Function Documentation

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator bool (  )  const [inline]

Conversion into boolean.

Returns:
true iff data pointer is not NULL.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator value_t * (  )  const [inline]

Conversion into pointer.

Returns:
the data pointer.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
void MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::setPointer ( value_t p  )  [inline]

Set the data pointer.

Parameters:
p  Pointer value

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
void MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::setSizeAndStart ( const size_t *  sz = ((size_t*)0),
const index_t st = ((index_t*)0) 
) [inline]

Set size and starting indices.

See also:
MDA_IndexRange
Parameters:
sz  Array sizes (NULL for no change)
st  Starting indices (NULL for no change)

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
void MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::setInclusiveRange ( const index_t  first[MDA_DIM],
const index_t  final[MDA_DIM] 
) [inline]

Set first and final indices (inclusive).

See also:
MDA_IndexRange
Parameters:
first  First valid indices (NULL for no change)
final  Final valid indices (NULL for no change)

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
const range_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::adjustDim ( dim_t  d,
index_t  first,
index_t  final 
) [inline]

Adjust the dimensions.

See also:
MDA_IndexRange::adjustDim.
Parameters:
d  Dimension to adjust
first  Increment to first index
final  Increment to final index

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
bool MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator== ( const MDA_Access< MDA_TYPE, MDA_DIM, OrderType > &  r  )  const [inline]

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
bool MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator!= ( const MDA_Access< MDA_TYPE, MDA_DIM, OrderType > &  r  )  const [inline]

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
const range_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::range (  )  const [inline]

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
const index_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::beg ( size_t  i  )  const [inline]

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
const index_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::end ( size_t  i  )  const [inline]

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
const size_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::size ( size_t  i  )  const [inline]

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() ( const index_t  i[MDA_DIM]  )  const [inline]

Grant general access to item in an arbitrary dimensional array.

This is flexible but not efficient! You should use dimension-specific accesses whenever possible.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() ( index_t  i0  )  const [inline]

Grant general access to item in a 1D array.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() ( index_t  i0,
index_t  i1 
) const [inline]

Grant general access to item in a 2D array.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() ( index_t  i0,
index_t  i1,
index_t  i2 
) const [inline]

Grant general access to item in a 3D array.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator() ( index_t  i0,
index_t  i1,
index_t  i2,
index_t  i3 
) const [inline]

Grant general access to item in a 4D array.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
value_t& MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::operator[] ( index_t  i0  )  const [inline]

Special case for 1D arrays, identical to operator(index_t), using pre-added fixed offsets.

This may be more efficient than (i) but it only works in 1D. It is not guaranteed to work if the fixed offset is negative and has greater value than the pointer address, since the addition of the two gives a negative address, which the C standard leaves as undefined behavior.

template<class MDA_TYPE, unsigned short MDA_DIM, class OrderType = MDA_OrderRowMajor<MDA_DIM>>
MDA_Access<MDA_TYPE,OrderType::MDA_Reduced_DIM,typename OrderType::reduced_order_t> MDA_Access< MDA_TYPE, MDA_DIM, OrderType >::reduce ( index_t  i  )  const [inline]

Fix the index of the slowest dimension and return the corresponding sub-array.

This function is meant to facilitate optimization when using this class. In nested loops, the inner loops executes many times with the indices corresponding to outer loops remaining constants. This leads to many many repeated integer arithmetics operations that could be removed from the inner loop (but may not be removed automatically by the compiler optimization). To do this, reduce the array dimensionality one dimension at a time, by fixing index corresponding to the slowest varying dimension. (If you code is written to maximize cache data, this will NOT be the index of the innermost loop.)

To reduce multiple dimensions, string these calls together, i.e. array.reduce(i).reduce(j). However, since reduction contains loops that cost O(MDA_DIM) and may be difficult for compilers to optimize, you may want to save array.reduce(i) and reuse it.

Parameters:
i Index in slowest dimension, which is the first dimension in a row-major array and the last dimension in a column-major array.
Returns:
The sub-array of dimension MDA_DIM-1, corresponding to the index given.


The documentation for this class was generated from the following file:
Generated on Thu Jun 18 11:28:18 2009 for SAMRAI by  doxygen 1.5.1