Domi
Multi-dimensional, distributed data structures
 All Classes Files Functions Variables Typedefs Friends
Public Member Functions | Friends | List of all members
Domi::MDIterator< MDARRAY > Class Template Reference

Iterator class suitable for multi-dimensional arrays. More...

#include <Domi_MDIterator.hpp>

+ Inheritance diagram for Domi::MDIterator< MDARRAY >:

Public Types

MDARRAY typedefs
typedef MDARRAY::value_type value_type
 Value type.
 
typedef MDARRAY::pointer pointer
 Pointer type.
 

Public Member Functions

dim_type index (int axis) const
 Return the current index value along the given axis. More...
 
Constructors and Destructor
 MDIterator (const MDARRAY &mdarray, bool end_index=false)
 MDIterator constructor. More...
 
 MDIterator (const MDARRAY &mdarray, const Teuchos::ArrayView< dim_type > &index)
 Index constructor. More...
 
 MDIterator (const MDIterator< MDARRAY > &source)
 Copy constructor. More...
 
 ~MDIterator ()
 Destructor.
 
Standard Operators
MDIterator< MDARRAY > & operator= (const MDIterator< MDARRAY > &source)
 Assignment operator. More...
 
bool operator== (const MDIterator< MDARRAY > &other) const
 Equality operator. More...
 
bool operator!= (const MDIterator< MDARRAY > &other) const
 Inequality operator. More...
 
value_typeoperator* ()
 Dereferencing operator.
 
pointer operator-> () const
 Dereferencing arrow operator.
 
MDIterator< MDARRAY > & operator++ ()
 Prefix increment operator.
 
MDIterator< MDARRAY > operator++ (int)
 Postfix increment operator.
 
MDIterator< MDARRAY > & operator-- ()
 Prefix decrement operator.
 
MDIterator< MDARRAY > operator-- (int)
 Postfix decrement operator.
 

Friends

template<typename T2 >
std::ostream & operator<< (std::ostream &os, const MDIterator< T2 > &a)
 Stream output operator.
 

Detailed Description

template<class MDARRAY>
class Domi::MDIterator< MDARRAY >

Iterator class suitable for multi-dimensional arrays.

This iterator is specialized for multi-dimensional arrays. It can be used like a standard iterator, without knowledge of the number of dimensions of the array. It is designed to iterate only over valid elements of the array. It is possible, especially with sliced views into a parent array, for the data buffer to have stride gaps that do not belong to the array. This iterator avoids those stride gaps by keeping an internal record of the multi- dimensional index, and only iterating over valid indexes.

To apply MDIterator to all three multi-dimensional array types (MDArray, MDArrayView and MDArrayRCP), the class is templated on parameter class MDARRAY, which is intended to be any one of the three MDArray types. The MDARRAY class is expected to support the the typedefs size_type, dim_type, and value_type, the numDims() method and the _ptr, _strides, _dimensions, and _layout attributes.

It is intended that the array class that will use the MDIterator will declare the MDIterator to be a friend and to typedef the fully qualified class. For example, within the MDArray< T > class:

friend class MDIterator< MDArray< T > >;
friend class MDIterator< MDArray< const T > >;
typedef MDIterator< MDArray< T > > iterator;
typedef MDIterator< MDArray< const T > > const_iterator;

and declare begin(), end() and cbegin(), cend() methods:

iterator begin() { return iterator(*this ); }
iterator end() { return iterator(*this, true); }
const_iterator begin() const { return const_iterator(*this ); }
const_iterator end() const { return const_iterator(*this, true); }
const_iterator cbegin() const { return const_iterator(*this ); }
const_iterator cend() const { return const_iterator(*this, true); }

Constructor & Destructor Documentation

template<class MDARRAY>
Domi::MDIterator< MDARRAY >::MDIterator ( const MDARRAY &  mdarray,
bool  end_index = false 
)

MDIterator constructor.

Parameters
mdarray[in] The multi-dimensional array object on which the iterator will act upon
end_index[in] If true, set the internal index to the MDARRAY end() index. If false, set the internal index to the MDARRAY begin() index. Default false.

Produces an iterator with index corresponding to either the MDARRAY begin() or end() methods, depending on the value of the end_index argument.

template<class MDARRAY>
Domi::MDIterator< MDARRAY >::MDIterator ( const MDARRAY &  mdarray,
const Teuchos::ArrayView< dim_type > &  index 
)

Index constructor.

Parameters
mdarray[in] The multi-dimensional array object on which the iterator will act upon
index[in] A Teuchos::ArrayView that specifies where the internal index of the iterator should start.

Produces an iterator with index corresponding to the given index.

template<class MDARRAY>
Domi::MDIterator< MDARRAY >::MDIterator ( const MDIterator< MDARRAY > &  source)

Copy constructor.

Parameters
source[in] The source MDIterator to be copied

Member Function Documentation

template<class MDARRAY >
dim_type Domi::MDIterator< MDARRAY >::index ( int  axis) const
inline

Return the current index value along the given axis.

Parameters
axis[in] Requested axis for index value
template<class MDARRAY>
bool Domi::MDIterator< MDARRAY >::operator!= ( const MDIterator< MDARRAY > &  other) const

Inequality operator.

Parameters
other[in] Iterator to be compared to
template<class MDARRAY>
MDIterator< MDARRAY > & Domi::MDIterator< MDARRAY >::operator= ( const MDIterator< MDARRAY > &  source)

Assignment operator.

Parameters
source[in] Source iterator for assignment
template<class MDARRAY>
bool Domi::MDIterator< MDARRAY >::operator== ( const MDIterator< MDARRAY > &  other) const

Equality operator.

Parameters
other[in] Iterator to be compared to

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

Generated on Fri Dec 20 2024 09:28:21 for Domi by doxygen 1.8.5