MercuryDataFile Class Reference

#include <MercuryData.h>

Classes

class  IteratorProxy
 

Public Member Functions

 MercuryDataFile (std::string name)
 
 operator bool () const
 Gives the status of the backing std::ifstream Returns true is no error has occurred. In any other case (EOF, FailBit, ErrorBit), it returns false. For more information, see std::ifstream::operator bool(). More...
 
template<std::size_t NDIMS>
bool isMercuryDataFile ()
 Checks if this file is a valid Mercury 3D data file. This function jumps to the start of the file, reads the first line and restores the readpointer. It then checks if that line can be succesfully parsed as a time step header. This does however not check if the file is consistent or the particle entries are valid. It can however serve as a first sanity check. More...
 
template<std::size_t NDIMS>
IteratorProxy< NDIMS > as ()
 
template<std::size_t NDIMS>
MercuryTimeStepIterator< NDIMS > begin ()
 Returns a forwarditerator to the time steps Returns a forwarditerator to the time steps, invalidating any other valid iterators in the process (since this is a lazy loader and does not actually load the entire file in memory). End iterators do not get invalidated. This function makes no guarantee for the validity of the file-state. More...
 
template<std::size_t NDIMS>
MercuryTimeStepIterator< NDIMS > end () const
 Returns a forwarditerator one past the last time step. More...
 

Private Attributes

std::ifstream file_
 

Friends

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

Detailed Description

Lazy loader for .data files. This class allows you to iterate over all the particles in it.

Author
dducks

Constructor & Destructor Documentation

◆ MercuryDataFile()

MercuryDataFile::MercuryDataFile ( std::string  name)
inline

Opens the Mercury 3D .data file with filename file.

Parameters
[in]nameThe filename
449  : file_(name)
450  { }
std::ifstream file_
Definition: MercuryData.h:564
std::string name
Definition: MercuryProb.h:48

Member Function Documentation

◆ as()

template<std::size_t NDIMS>
IteratorProxy<NDIMS> MercuryDataFile::as ( )
inline
532  {
533  return {this};
534  };

Referenced by transformMercuryToVTK().

◆ begin()

template<std::size_t NDIMS>
MercuryTimeStepIterator<NDIMS> MercuryDataFile::begin ( )
inline

Returns a forwarditerator to the time steps Returns a forwarditerator to the time steps, invalidating any other valid iterators in the process (since this is a lazy loader and does not actually load the entire file in memory). End iterators do not get invalidated. This function makes no guarantee for the validity of the file-state.

547  {
548  file_.seekg(0);
549  return {this};
550  }

References file_.

Referenced by MercuryDataFile::IteratorProxy< NDIMS >::begin().

◆ end()

template<std::size_t NDIMS>
MercuryTimeStepIterator<NDIMS> MercuryDataFile::end ( ) const
inline

Returns a forwarditerator one past the last time step.

557  {
558  return {};
559  }

Referenced by MercuryDataFile::IteratorProxy< NDIMS >::end().

◆ isMercuryDataFile()

template<std::size_t NDIMS>
bool MercuryDataFile::isMercuryDataFile ( )
inline

Checks if this file is a valid Mercury 3D data file. This function jumps to the start of the file, reads the first line and restores the readpointer. It then checks if that line can be succesfully parsed as a time step header. This does however not check if the file is consistent or the particle entries are valid. It can however serve as a first sanity check.

Returns
true if the file appears to be a valid Mercury 3D .data file.
See also
MercuryDataFile::isMercury2DDataFile()
477  {
478  //Store the position, so we can jump back at the end of the function..
479  std::ios::pos_type currentPosition = file_.tellg();
480  //and jump to the start
481  file_.seekg(0);
482  //get the first line
483  std::string line;
484  std::getline(file_, line);
485  file_.seekg(currentPosition); //and pretend nothing has happened
486 
487  std::istringstream lineStream(line);
488 
489  //We'll try to find out if there were exactly enough arguments.
491  lineStream >> step;
492 
493  //Did we reach the end yet?
494  bool isValid = lineStream.good() || (lineStream.eof() && !lineStream.fail());
495  double dummy;
496  lineStream >> dummy;
497 
498  //now we should have reached it.
499  isValid = isValid && !lineStream.good();
500  return isValid;
501  }
Definition: MercuryData.h:178

References file_.

Referenced by main().

◆ operator bool()

MercuryDataFile::operator bool ( ) const
inline

Gives the status of the backing std::ifstream Returns true is no error has occurred. In any other case (EOF, FailBit, ErrorBit), it returns false. For more information, see std::ifstream::operator bool().

Returns
true if the underlying file is readable, false otherwise.
460  {
461  return file_.good();
462  }

References file_.

Friends And Related Function Documentation

◆ MercuryTimeStep

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

◆ MercuryTimeStepIterator

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

Member Data Documentation

◆ file_

std::ifstream MercuryDataFile::file_
private

The backing file stream used to represent the data file.

Referenced by begin(), isMercuryDataFile(), operator bool(), and MercuryTimeStepIterator< NDIMS >::operator++().


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