MercuryDPM  Beta
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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 timestep, 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 timestep iterator Only loads the current timestep 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

Definition at line 165 of file MercuryData.h.

Constructor & Destructor Documentation

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

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

Definition at line 395 of file MercuryData.h.

396  : isEOFTimeStep_(true), dataFile_(nullptr)
397  {
398  }
MercuryDataFile * dataFile_
Definition: MercuryData.h:422
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

Definition at line 404 of file MercuryData.h.

References MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_.

405  : lastReadTimeStep_(0,pData), isEOFTimeStep_(false), dataFile_(pData)
406  {
407  ++(*this);
408  lastReadTimeStep_.ID_ = 0;
409  }
MercuryTimeStep< NDIMS > lastReadTimeStep_
Definition: MercuryData.h:414
MercuryDataFile * dataFile_
Definition: MercuryData.h:422

Member Function Documentation

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

Not-equals operator, as defined for ForwardIterators.

Definition at line 363 of file MercuryData.h.

References MercuryTimeStepIterator< NDIMS >::isEOFTimeStep_.

364  {
365  return (isEOFTimeStep_ != other.isEOFTimeStep_);
366  }
template<std::size_t NDIMS>
MercuryTimeStep<NDIMS>& MercuryTimeStepIterator< NDIMS >::operator* ( )
inline

Dereference operator, as defined for ForwardIterators.

Definition at line 371 of file MercuryData.h.

References MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_.

372  {
373  return lastReadTimeStep_;
374  }
MercuryTimeStep< NDIMS > lastReadTimeStep_
Definition: MercuryData.h:414
template<std::size_t NDIMS>
const MercuryTimeStep<NDIMS>& MercuryTimeStepIterator< NDIMS >::operator* ( ) const
inline

Const dereference operator, as defined for constant ForwardIterators.

Definition at line 379 of file MercuryData.h.

References MercuryTimeStepIterator< NDIMS >::lastReadTimeStep_.

380  {
381  return lastReadTimeStep_;
382  }
MercuryTimeStep< NDIMS > lastReadTimeStep_
Definition: MercuryData.h:414
template<std::size_t NDIMS>
void MercuryTimeStepIterator< NDIMS >::operator++ ( )

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

Definition at line 567 of file MercuryData.h.

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

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

Friends And Related Function Documentation

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

Definition at line 424 of file MercuryData.h.

Member Data Documentation

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

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

Definition at line 422 of file MercuryData.h.

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

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

Status flag for EOF checking

Definition at line 418 of file MercuryData.h.

Referenced by MercuryTimeStepIterator< NDIMS >::operator!=(), and MercuryTimeStepIterator< NDIMS >::operator++().

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

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