SSAGES  0.1
A MetaDynamics Package
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Groups Pages
Public Types | Public Member Functions | Private Attributes | List of all members
SSAGES::Grid< T >::GridIterator< R > Class Template Reference

Custom Iterator. More...

#include <Grid.h>

Public Types

typedef GridIterator self_type
 Type name of the iterator.
 
typedef int difference_type
 Difference type is an int.
 
typedef R value_type
 Either T or const T for iterator and const_iterator, respectively.
 
typedef R * pointer
 Either T* or T const* for iterator and const_iterator, respectively.
 
typedef R & reference
 Either T& or T const& for iterator and const_iterator, respectively.
 
typedef
std::bidirectional_iterator_tag 
iterator_category
 HistIterator is a bidirectional iterator.
 

Public Member Functions

 GridIterator ()=default
 Use default constructor.
 
 GridIterator (const std::vector< int > &indices, Grid< T > *grid)
 Constructor. More...
 
 GridIterator (const std::vector< int > &indices, const Grid< T > *grid)
 Const constructor. More...
 
 GridIterator (const GridIterator &other)
 Copy constructor. More...
 
reference operator* ()
 Dereference operator. More...
 
self_typeoperator++ ()
 Pre-increment operator. More...
 
self_type operator++ (int)
 Post-increment operator. More...
 
self_typeoperator+= (std::vector< int > shift)
 Addition assignment operator.
 
const self_type operator+ (std::vector< int > shift)
 Addition operator. More...
 
self_typeoperator-- ()
 Pre-decrement operator. More...
 
self_type operator-- (int)
 Post-decrement operator. More...
 
self_typeoperator-= (std::vector< int > shift)
 Subtraction assignment operator. More...
 
const self_type operator- (std::vector< int > shift)
 Subtraction iterator. More...
 
bool operator== (const self_type &rhs) const
 Equality operator. More...
 
bool operator!= (const self_type &rhs) const
 Non-equality operator. More...
 
std::vector< int > & indices ()
 Access indices. More...
 
int & index (size_t d)
 Access a specific index. More...
 
std::vector< double > coordinates () const
 Access coordinates. More...
 
double coordinate (size_t d) const
 Access specific coordinate dimension. More...
 

Private Attributes

std::vector< int > indices_
 Indices of current grid point.
 
Grid< T > * grid_
 Pointer to grid to iterate over.
 

Detailed Description

template<typename T>
template<typename R>
class SSAGES::Grid< T >::GridIterator< R >

Custom Iterator.

This iterator is designed of travesing through a grid. The starting point is at grid index 0 for each dimension. The last valid grid point has the num_points in each dimension, where num_points is the number of grid points in the respective dimension.

The iterator can be used as a standard iterator with operator* accessing the grid point at which the iterator currently is.

Additionally, the functions GridIterator::indices() and GridIterator::coordinates() are provided. These functions return the indices of the current grid point and the center of the grid point interval in real space, respectively.

The iterator can be moved to an arbitrary position. As indices() returns a reference (and not a const reference), it can be used to move the iterator. For example:

HistIterator it = hist->begin();
it.indices() = {1,1,1};

moves the iterator to the grid point [1, 1, 1].

The iterator can be traversed in a standard fashion with the increment and decrement operators operator++ and operator--. When the increment operator is invoked, the bin index for the lowest dimension is increased by 1. If it moves beyond the valid range in this dimension, the index is reset to 0 and the index of the next higher dimension is increased by 1. The decrement operator traveses the grid in the same fashion but opposite direction.

Additionaly, the iterator can be shifted by adding or subtracting a vector of ints. The vector needs to have the same dimension as the histogram.

Definition at line 244 of file Grid.h.

Constructor & Destructor Documentation

template<typename T>
template<typename R >
SSAGES::Grid< T >::GridIterator< R >::GridIterator ( const std::vector< int > &  indices,
Grid< T > *  grid 
)
inline

Constructor.

Parameters
indicesBin indices specifying the current position of the iterator.
histPointer to the grid to iterate over.

Definition at line 273 of file Grid.h.

274  : indices_(indices), grid_(grid)
275  {
276  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505
template<typename T>
template<typename R >
SSAGES::Grid< T >::GridIterator< R >::GridIterator ( const std::vector< int > &  indices,
const Grid< T > *  grid 
)
inline

Const constructor.

Parameters
indicesBin indices specifying the current position of the iterator.
histPointer to the grid to iterate over.

Definition at line 284 of file Grid.h.

285  : indices_(indices), grid_(grid)
286  {
287  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505
template<typename T>
template<typename R >
SSAGES::Grid< T >::GridIterator< R >::GridIterator ( const GridIterator< R > &  other)
inline

Copy constructor.

Parameters
otherGridIterator to be copied.

Definition at line 293 of file Grid.h.

294  : indices_(other.indices_), grid_(other.grid_)
295  {
296  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505

Member Function Documentation

template<typename T>
template<typename R >
double SSAGES::Grid< T >::GridIterator< R >::coordinate ( size_t  d) const
inline

Access specific coordinate dimension.

Parameters
dDimension of the coordinate.
Returns
Center of the current grid point in the specified dimension.

Definition at line 498 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::coordinates().

499  {
500  return coordinates()[d];
501  }
std::vector< double > coordinates() const
Access coordinates.
Definition: Grid.h:488

Here is the call graph for this function:

template<typename T>
template<typename R >
std::vector<double> SSAGES::Grid< T >::GridIterator< R >::coordinates ( ) const
inline

Access coordinates.

Returns
Center point of the current grid point.

Definition at line 488 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::grid_, and SSAGES::Grid< T >::GridIterator< R >::indices_.

Referenced by SSAGES::Grid< T >::GridIterator< R >::coordinate().

489  {
490  return grid_->GetCoordinates(indices_);
491  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505

Here is the caller graph for this function:

template<typename T>
template<typename R >
int& SSAGES::Grid< T >::GridIterator< R >::index ( size_t  d)
inline

Access a specific index.

Parameters
dDimension of the index.
Returns
Index of the current grid point in the specified dimension.

Definition at line 479 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::indices().

480  {
481  return indices()[d];
482  }
std::vector< int > & indices()
Access indices.
Definition: Grid.h:468

Here is the call graph for this function:

template<typename T>
template<typename R >
std::vector<int>& SSAGES::Grid< T >::GridIterator< R >::indices ( )
inline

Access indices.

Returns
Indices of current grid point.
Note
This function returns a reference and can be used to move the current grid point.

Definition at line 468 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::indices_.

Referenced by SSAGES::Grid< T >::GridIterator< R >::index().

469  {
470  return indices_;
471  }
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505

Here is the caller graph for this function:

template<typename T>
template<typename R >
bool SSAGES::Grid< T >::GridIterator< R >::operator!= ( const self_type rhs) const
inline

Non-equality operator.

Parameters
rhsIterator to which this iterator is compared.
Returns
False if both iterators access the same grid point on the same grid. Else return True.

Definition at line 456 of file Grid.h.

457  {
458  return !( (*this) == rhs );
459  }
template<typename T>
template<typename R >
reference SSAGES::Grid< T >::GridIterator< R >::operator* ( )
inline

Dereference operator.

Returns
Reference to the value at the current grid position.

Definition at line 302 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::grid_, and SSAGES::Grid< T >::GridIterator< R >::indices_.

302 { return grid_->at(indices_); }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505
template<typename T>
template<typename R >
const self_type SSAGES::Grid< T >::GridIterator< R >::operator+ ( std::vector< int >  shift)
inline

Addition operator.

Parameters
shiftAmount of shift in each dimension.
Returns
Copy of iterator after shift.

Shift the iterator by a given vector.

Definition at line 374 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::GridIterator().

375  {
376  return GridIterator(*this) += shift;
377  }
GridIterator()=default
Use default constructor.

Here is the call graph for this function:

template<typename T>
template<typename R >
self_type& SSAGES::Grid< T >::GridIterator< R >::operator++ ( )
inline

Pre-increment operator.

Returns
Reference to iterator.

Increments the bin index of lowest dimension. If an index moves beyond the maximum value (num_points-1), it is reset to 0 and the index of the next higher dimension is increased by 1.

Definition at line 312 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::grid_, and SSAGES::Grid< T >::GridIterator< R >::indices_.

313  {
314  indices_.at(0) += 1;
315  for (size_t i = 0; i < grid_->GetDimension() - 1; ++i) {
316  if (indices_.at(i) >= grid_->GetNumPoints(i)) {
317  indices_.at(i) = 0;
318  indices_.at(i+1) += 1;
319  }
320  }
321 
322  return *this;
323  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505
template<typename T>
template<typename R >
self_type SSAGES::Grid< T >::GridIterator< R >::operator++ ( int  )
inline

Post-increment operator.

Returns
Copy of iterator before incrementing.

Definition at line 329 of file Grid.h.

330  {
331  GridIterator it(*this);
332  ++(*this);
333  return it;
334  }
GridIterator()=default
Use default constructor.
template<typename T>
template<typename R >
const self_type SSAGES::Grid< T >::GridIterator< R >::operator- ( std::vector< int >  shift)
inline

Subtraction iterator.

Parameters
shiftVector to be subtracted from the current grid indices.
Returns
Copy of iterator after shift.

Definition at line 434 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::GridIterator().

435  {
436  return GridIterator(*this) -= shift;
437  }
GridIterator()=default
Use default constructor.

Here is the call graph for this function:

template<typename T>
template<typename R >
self_type& SSAGES::Grid< T >::GridIterator< R >::operator-- ( )
inline

Pre-decrement operator.

Returns
Reference to iterator after decrementing.

Traveses the histogram in the opposite direction to the increment operator.

Definition at line 386 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::grid_, and SSAGES::Grid< T >::GridIterator< R >::indices_.

387  {
388  indices_.at(0) -= 1;
389  for (size_t i = 0; i < grid_->GetDimension() - 1; ++i) {
390  if (indices_.at(i) < 0) {
391  indices_.at(i) = grid_->GetNumPoints(i)-1;
392  indices_.at(i+1) -= 1;
393  }
394  }
395 
396  return *this;
397  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505
template<typename T>
template<typename R >
self_type SSAGES::Grid< T >::GridIterator< R >::operator-- ( int  )
inline

Post-decrement operator.

Returns
Copy of iterator before decrementing.

Definition at line 403 of file Grid.h.

404  {
405  GridIterator it(*this);
406  --(*this);
407  return it;
408  }
GridIterator()=default
Use default constructor.
template<typename T>
template<typename R >
self_type& SSAGES::Grid< T >::GridIterator< R >::operator-= ( std::vector< int >  shift)
inline

Subtraction assignment operator.

Parameters
shiftVector to be subtracted from the current grid indices.
Returns
Reference to iterator.

Definition at line 415 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::grid_, and SSAGES::Grid< T >::GridIterator< R >::indices_.

416  {
417  if (shift.size() != grid_->GetDimension()) {
418  throw std::invalid_argument("Vector to shift iterator does not "
419  "match histogram dimension.");
420  }
421 
422  for (size_t i = 0; i < grid_->GetDimension(); ++i) {
423  indices_.at(i) -= shift.at(i);
424  }
425 
426  return *this;
427  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505
template<typename T>
template<typename R >
bool SSAGES::Grid< T >::GridIterator< R >::operator== ( const self_type rhs) const
inline

Equality operator.

Parameters
rhsIterator to which this iterator is compared.
Returns
True if both iterators access the same grid point on the same grid. Else return False.

Definition at line 445 of file Grid.h.

References SSAGES::Grid< T >::GridIterator< R >::grid_, and SSAGES::Grid< T >::GridIterator< R >::indices_.

446  {
447  return indices_ == rhs.indices_ && grid_ == rhs.grid_;
448  }
Grid< T > * grid_
Pointer to grid to iterate over.
Definition: Grid.h:508
std::vector< int > indices_
Indices of current grid point.
Definition: Grid.h:505

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