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::Histogram< T >::HistIterator< R > Class Template Reference

Custom Iterator. More...

#include <Histogram.h>

Public Types

typedef HistIterator 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

 HistIterator ()=default
 Use default constructor.
 
 HistIterator (const std::vector< int > &indices, Histogram< T > *hist)
 Constructor. More...
 
 HistIterator (const HistIterator &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...
 
bool isUnderOverflowBin () const
 Check if current iterator position is under- or overflow bin. 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 bin.
 
Histogram< T > * hist_
 Pointer to histogram to iterate over.
 

Detailed Description

template<typename T>
template<typename R>
class SSAGES::Histogram< T >::HistIterator< R >

Custom Iterator.

This iterator is designed of travesing through a histogram. The starting point is at grid index 0 (-1) for each periodic (non-periodic) 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 HistIterator::indices() and HistIterator::coordinates() are provided. These functions return the indices of the current bin and the bin center 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 bin with indices [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 is beyond the histogram size in this dimension, the index is reset to its smallest value (0 for periodic, -1 for non-periodic dimensions) 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 256 of file Histogram.h.

Constructor & Destructor Documentation

template<typename T>
template<typename R >
SSAGES::Histogram< T >::HistIterator< R >::HistIterator ( const std::vector< int > &  indices,
Histogram< T > *  hist 
)
inline

Constructor.

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

Definition at line 285 of file Histogram.h.

286  : indices_(indices), hist_(hist)
287  {
288  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530
template<typename T>
template<typename R >
SSAGES::Histogram< T >::HistIterator< R >::HistIterator ( const HistIterator< R > &  other)
inline

Copy constructor.

Parameters
otherHistIterator to be copied.

Definition at line 294 of file Histogram.h.

295  : indices_(other.indices_), hist_(other.hist_)
296  {
297  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530

Member Function Documentation

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

Access specific coordinate dimension.

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

Definition at line 523 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::coordinates().

524  {
525  return coordinates()[d];
526  }
std::vector< double > coordinates() const
Access coordinates.
Definition: Histogram.h:513

Here is the call graph for this function:

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

Access coordinates.

Returns
Center point of the current bin.

Definition at line 513 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::hist_, and SSAGES::Histogram< T >::HistIterator< R >::indices_.

Referenced by SSAGES::Histogram< T >::HistIterator< R >::coordinate().

514  {
515  return hist_->GetCoordinates(indices_);
516  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530

Here is the caller graph for this function:

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

Access a specific index.

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

Definition at line 490 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::indices().

491  {
492  return indices()[d];
493  }
std::vector< int > & indices()
Access indices.
Definition: Histogram.h:479

Here is the call graph for this function:

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

Access indices.

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

Definition at line 479 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::indices_.

Referenced by SSAGES::Histogram< T >::HistIterator< R >::index().

480  {
481  return indices_;
482  }
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530

Here is the caller graph for this function:

template<typename T>
template<typename R >
bool SSAGES::Histogram< T >::HistIterator< R >::isUnderOverflowBin ( ) const
inline

Check if current iterator position is under- or overflow bin.

Returns
True if current bin is an underflow or an overflow bin.

Definition at line 499 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::hist_, and SSAGES::Histogram< T >::HistIterator< R >::indices_.

500  {
501  for (size_t i = 0; i < indices_.size(); ++i) {
502  if (indices_.at(i) == -1 || indices_.at(i) == hist_->GetNumPoints(i)) {
503  return true;
504  }
505  }
506  return false;
507  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530
template<typename T>
template<typename R >
bool SSAGES::Histogram< T >::HistIterator< 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 467 of file Histogram.h.

468  {
469  return !( (*this) == rhs );
470  }
template<typename T>
template<typename R >
reference SSAGES::Histogram< T >::HistIterator< R >::operator* ( )
inline

Dereference operator.

Returns
Reference to the value at the current grid position.

Definition at line 303 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::hist_, and SSAGES::Histogram< T >::HistIterator< R >::indices_.

303 { return hist_->at(indices_); }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530
template<typename T>
template<typename R >
const self_type SSAGES::Histogram< T >::HistIterator< 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 382 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::HistIterator().

383  {
384  return HistIterator(*this) += shift;
385  }
HistIterator()=default
Use default constructor.

Here is the call graph for this function:

template<typename T>
template<typename R >
self_type& SSAGES::Histogram< T >::HistIterator< R >::operator++ ( )
inline

Pre-increment operator.

Returns
Reference to iterator.

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

Definition at line 315 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::hist_, and SSAGES::Histogram< T >::HistIterator< R >::indices_.

316  {
317  indices_.at(0) += 1;
318  for (size_t i = 0; i < hist_->GetDimension() - 1; ++i) {
319  if (hist_->GetPeriodic(i) &&
320  indices_.at(i) >= hist_->GetNumPoints(i)) {
321 
322  indices_.at(i) = 0;
323  indices_.at(i+1) += 1;
324  } else if (!hist_->GetPeriodic(i) &&
325  indices_.at(i) > hist_->GetNumPoints(i)) {
326 
327  indices_.at(i) = -1;
328  indices_.at(i+1) += 1;
329  }
330  }
331 
332  return *this;
333  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530
template<typename T>
template<typename R >
self_type SSAGES::Histogram< T >::HistIterator< R >::operator++ ( int  )
inline

Post-increment operator.

Returns
Copy of iterator before incrementing.

Definition at line 339 of file Histogram.h.

340  {
341  HistIterator it(*this);
342  ++(*this);
343  return it;
344  }
HistIterator()=default
Use default constructor.
template<typename T>
template<typename R >
const self_type SSAGES::Histogram< T >::HistIterator< 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 445 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::HistIterator().

446  {
447  return HistIterator(*this) -= shift;
448  }
HistIterator()=default
Use default constructor.

Here is the call graph for this function:

template<typename T>
template<typename R >
self_type& SSAGES::Histogram< T >::HistIterator< 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 394 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::hist_, and SSAGES::Histogram< T >::HistIterator< R >::indices_.

395  {
396  indices_.at(0) -= 1;
397  for (size_t i = 0; i < hist_->GetDimension() - 1; ++i) {
398  if (hist_->GetPeriodic(i) && indices_.at(i) < 0) {
399  indices_.at(i) = hist_->GetNumPoints(i)-1;
400  indices_.at(i+1) -= 1;
401  } else if (!hist_->GetPeriodic(i) && indices_.at(i) < -1) {
402  indices_.at(i) = hist_->GetNumPoints(i);
403  indices_.at(i+1) -= 1;
404  }
405  }
406 
407  return *this;
408  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530
template<typename T>
template<typename R >
self_type SSAGES::Histogram< T >::HistIterator< R >::operator-- ( int  )
inline

Post-decrement operator.

Returns
Copy of iterator before decrementing.

Definition at line 414 of file Histogram.h.

415  {
416  HistIterator it(*this);
417  --(*this);
418  return it;
419  }
HistIterator()=default
Use default constructor.
template<typename T>
template<typename R >
self_type& SSAGES::Histogram< T >::HistIterator< 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 426 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::hist_, and SSAGES::Histogram< T >::HistIterator< R >::indices_.

427  {
428  if (shift.size() != hist_->GetDimension()) {
429  throw std::invalid_argument("Vector to shift iterator does not "
430  "match histogram dimension.");
431  }
432 
433  for (size_t i = 0; i < hist_->GetDimension(); ++i) {
434  indices_.at(i) -= shift.at(i);
435  }
436 
437  return *this;
438  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530
template<typename T>
template<typename R >
bool SSAGES::Histogram< T >::HistIterator< 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 456 of file Histogram.h.

References SSAGES::Histogram< T >::HistIterator< R >::hist_, and SSAGES::Histogram< T >::HistIterator< R >::indices_.

457  {
458  return indices_ == rhs.indices_ && hist_ == rhs.hist_;
459  }
Histogram< T > * hist_
Pointer to histogram to iterate over.
Definition: Histogram.h:533
std::vector< int > indices_
Indices of current bin.
Definition: Histogram.h:530

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