revision: v0.14
MercuryTimeStepIterator< NDIMS > Class Template Reference

#include <MercuryData.h>

Public Member Functions

bool operator!= (MercuryTimeStepIterator< NDIMS > other) const
 Not-equals operator, as defined for ForwardIterators. More...
 
MercuryTimeStep< NDIMS > & operator* ()
 Dereference operator, as defined for ForwardIterators. More...
 
const MercuryTimeStep< NDIMS > & operator* () const
 Const dereference operator, as defined for constant ForwardIterators. More...
 
void operator++ ()
 Pre-increment operator, as defined for ForwardIterators This method populates the time step, including all the particles in there. It also resizes the backing storage mechanism. More...
 

Private Member Functions

 MercuryTimeStepIterator ()
 
 MercuryTimeStepIterator (MercuryDataFile *pData)
 

Private Attributes

MercuryTimeStep< NDIMS > lastReadTimeStep_
 
bool isEOFTimeStep_
 
MercuryDataFiledataFile_
 

Friends

class MercuryDataFile
 

Detailed Description

template<std::size_t NDIMS>
class MercuryTimeStepIterator< NDIMS >

Lazy time step iterator Only loads the current time step and discards this as soon as it is incremented. This is a ForwardIterator as described by the C++11 standard This iterator invalidates any references to its dereferenced value when incremented.

Author
dducks

Constructor & Destructor Documentation

◆ MercuryTimeStepIterator() [1/2]

template<std::size_t NDIMS>
MercuryTimeStepIterator< NDIMS >::MercuryTimeStepIterator ( )
inlineprivate

EOF TimeStepIterator constructor, as used by MercuryDataFile::end()

403  : isEOFTimeStep_(true), dataFile_(nullptr)
404  {
405  }

◆ MercuryTimeStepIterator() [2/2]

template<std::size_t NDIMS>
MercuryTimeStepIterator< NDIMS >::MercuryTimeStepIterator ( MercuryDataFile pData)
inlineprivate

Beginning-of-file TimeStepIterator constructor, as used by MercuryDataFile::begin()

Parameters
[in]pDataPointer to the MercuryDataFile, which is required for the backing std::ifstream
412  : lastReadTimeStep_(0,pData), isEOFTimeStep_(false), dataFile_(pData)
413  {
414  ++(*this);
415  lastReadTimeStep_.ID_ = 0;
416  }

References MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_.

Member Function Documentation

◆ operator!=()

template<std::size_t NDIMS>
bool MercuryTimeStepIterator< NDIMS >::operator!= ( MercuryTimeStepIterator< NDIMS >  other) const
inline

Not-equals operator, as defined for ForwardIterators.

371  {
372  return (isEOFTimeStep_ != other.isEOFTimeStep_);
373  }

References MercuryTimeStepIterator< NDIMS >::isEOFTimeStep_.

◆ operator*() [1/2]

template<std::size_t NDIMS>
MercuryTimeStep<NDIMS>& MercuryTimeStepIterator< NDIMS >::operator* ( )
inline

Dereference operator, as defined for ForwardIterators.

379  {
380  return lastReadTimeStep_;
381  }

References MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_.

◆ operator*() [2/2]

template<std::size_t NDIMS>
const MercuryTimeStep<NDIMS>& MercuryTimeStepIterator< NDIMS >::operator* ( ) const
inline

Const dereference operator, as defined for constant ForwardIterators.

387  {
388  return lastReadTimeStep_;
389  }

References MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_.

◆ operator++()

template<std::size_t NDIMS>
void MercuryTimeStepIterator< NDIMS >::operator++

Pre-increment operator, as defined for ForwardIterators This method populates the time step, including all the particles in there. It also resizes the backing storage mechanism.

575 {
576  lastReadTimeStep_.ID_++;
577 
578  std::string line;
579  std::getline(dataFile_->file_, line);
580 
581  std::istringstream lineStream(line);
582 
583  lineStream >> lastReadTimeStep_;
584 
585  //I hope we didn't went beyond end of file...
586  if (lineStream.eof())
587  {
588 // logger(WARN, "The time step header detected an EOF.. Usually this"
589 // " means that the format was not what it appeared to be."
590 // "\nproceed with caution!");
591  }
592  //Resize the backing storage container to make sure we can actually
593  //fit all the particles in there.
594  lastReadTimeStep_.storage_.resize(lastReadTimeStep_.numParticles_);
595  //Well, now that we're set up, read all the particles
597  {
598  //line by line, because no data format can be trusted.
599  std::getline(dataFile_->file_, line);
600  lineStream.clear();
601  lineStream.str(line);
602 
603  lineStream >> part;
604  }
605 
606  if (dataFile_->file_.eof())
607  isEOFTimeStep_ = true;
608 }

References MercuryTimeStepIterator< NDIMS >::dataFile_, MercuryDataFile::file_, MercuryTimeStepIterator< NDIMS >::isEOFTimeStep_, and MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_.

Friends And Related Function Documentation

◆ MercuryDataFile

template<std::size_t NDIMS>
friend class MercuryDataFile
friend

Member Data Documentation

◆ dataFile_

template<std::size_t NDIMS>
MercuryDataFile* MercuryTimeStepIterator< NDIMS >::dataFile_
private

Pointer to the MercuryDataFile and the backing std::ifstream, which is required for reading

Referenced by MercuryTimeStepIterator< NDIMS >::operator++().

◆ isEOFTimeStep_

template<std::size_t NDIMS>
bool MercuryTimeStepIterator< NDIMS >::isEOFTimeStep_
private

◆ lastReadTimeStep_

template<std::size_t NDIMS>
MercuryTimeStep<NDIMS> MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_
private

The documentation for this class was generated from the following file:
MercuryParticle
Definition: MercuryData.h:42
MercuryTimeStepIterator::lastReadTimeStep_
MercuryTimeStep< NDIMS > lastReadTimeStep_
Definition: MercuryData.h:421
MercuryTimeStepIterator::dataFile_
MercuryDataFile * dataFile_
Definition: MercuryData.h:429
MercuryTimeStepIterator::isEOFTimeStep_
bool isEOFTimeStep_
Definition: MercuryData.h:425
MercuryDataFile::file_
std::ifstream file_
Definition: MercuryData.h:565