cartobase 6.0.6
carto::NDIterator< T > Class Template Reference

N-dimensional array iterator. More...

#include <cartobase/containers/nditerator.h>

Inheritance diagram for carto::NDIterator< T >:
Collaboration diagram for carto::NDIterator< T >:

Public Member Functions

 NDIterator (T *buffer, const std::vector< int > &dims)
 
 NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< int > &strides)
 
 NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< std::size_t > &strides)
 
 NDIterator (T *buffer, const std::vector< int > &dims, const std::vector< std::ptrdiff_t > &strides)
 
T & operator* () const
 
T * operator-> () const
 
- Public Member Functions inherited from carto::NDIterator_base
 NDIterator_base (const std::vector< int > &dims)
 
 NDIterator_base (const std::vector< int > &dims, const std::vector< int > &strides)
 
 NDIterator_base (const std::vector< int > &dims, const std::vector< std::size_t > &strides)
 
 NDIterator_base (const std::vector< int > &dims, const std::vector< std::ptrdiff_t > &strides)
 
const std::vector< int > & position () const
 
std::ptrdiff_t offset () const
 
NDIterator_baseoperator++ ()
 
bool ended () const
 
void reset ()
 

Protected Attributes

T * _buffer
 
- Protected Attributes inherited from carto::NDIterator_base
std::vector< int > _dims
 
std::vector< std::ptrdiff_t > _strides
 
std::vector< int > _position
 
std::ptrdiff_t _offset
 
bool _ended
 

Additional Inherited Members

- Static Protected Member Functions inherited from carto::NDIterator_base
template<typename T>
static std::vector< std::ptrdiff_t > to_ptrdiff_v (const std::vector< T > &v)
 

Detailed Description

template<typename T>
class carto::NDIterator< T >

N-dimensional array iterator.

Iterates over every element of a N-D array, using strides. The iterator is used more or less like a pointer:

float *data; // fill it...
std::vector<int> dimensions;
std::vector<std::ptrdiff_t> strdes;
// fill dimensions and strides...
float sum = 0.;
NDIterator<float> it( data, dimensions, strides );
for( ; !it.ended(); ++it )
sum += *it;
NDIterator(T *buffer, const std::vector< int > &dims)
Definition nditerator.h:491

Note that the NDIterator is somewhat sub-optimal since it has to test, at each increment, the bounds of each dimension. In many cases it is possible to lowerage the overhead by implementing an ad-hoc loop for the smallest dimension, and using a line_NDIterator on higher dimensions.

Definition at line 134 of file nditerator.h.

Constructor & Destructor Documentation

◆ NDIterator() [1/4]

template<typename T>
carto::NDIterator< T >::NDIterator ( T * buffer,
const std::vector< int > & dims )
inline

Definition at line 491 of file nditerator.h.

References _buffer, and carto::NDIterator_base::NDIterator_base().

◆ NDIterator() [2/4]

template<typename T>
carto::NDIterator< T >::NDIterator ( T * buffer,
const std::vector< int > & dims,
const std::vector< int > & strides )
inline

Definition at line 498 of file nditerator.h.

References _buffer, and carto::NDIterator_base::NDIterator_base().

◆ NDIterator() [3/4]

template<typename T>
carto::NDIterator< T >::NDIterator ( T * buffer,
const std::vector< int > & dims,
const std::vector< std::size_t > & strides )
inline

Definition at line 506 of file nditerator.h.

References _buffer, and carto::NDIterator_base::NDIterator_base().

◆ NDIterator() [4/4]

template<typename T>
carto::NDIterator< T >::NDIterator ( T * buffer,
const std::vector< int > & dims,
const std::vector< std::ptrdiff_t > & strides )
inline

Definition at line 514 of file nditerator.h.

References _buffer, and carto::NDIterator_base::NDIterator_base().

Member Function Documentation

◆ operator*()

template<typename T>
T & carto::NDIterator< T >::operator* ( ) const
inline

Definition at line 521 of file nditerator.h.

References _buffer, and carto::NDIterator_base::_offset.

◆ operator->()

template<typename T>
T * carto::NDIterator< T >::operator-> ( ) const
inline

Definition at line 526 of file nditerator.h.

References _buffer, and carto::NDIterator_base::_offset.

Member Data Documentation

◆ _buffer

template<typename T>
T* carto::NDIterator< T >::_buffer
protected

Definition at line 150 of file nditerator.h.

Referenced by NDIterator(), NDIterator(), NDIterator(), NDIterator(), operator*(), and operator->().


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