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()

402  : isEOFTimeStep_(true), dataFile_(nullptr)
403  {
404  }
MercuryDataFile * dataFile_
Definition: MercuryData.h:428
bool isEOFTimeStep_
Definition: MercuryData.h:424

◆ 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
411  : lastReadTimeStep_(0,pData), isEOFTimeStep_(false), dataFile_(pData)
412  {
413  ++(*this);
414  lastReadTimeStep_.ID_ = 0;
415  }
MercuryTimeStep< NDIMS > lastReadTimeStep_
Definition: MercuryData.h:420

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.

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

References MercuryTimeStepIterator< NDIMS >::isEOFTimeStep_.

◆ operator*() [1/2]

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

Dereference operator, as defined for ForwardIterators.

378  {
379  return lastReadTimeStep_;
380  }

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.

386  {
387  return lastReadTimeStep_;
388  }

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.

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

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: