MercuryDPM  Trunk
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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

Definition at line 441 of file MercuryData.h.

Constructor & Destructor Documentation

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

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

Parameters
[in]nameThe filename

Definition at line 449 of file MercuryData.h.

450  : file_(name)
451  { }
std::ifstream file_
Definition: MercuryData.h:565

Member Function Documentation

template<std::size_t NDIMS>
IteratorProxy<NDIMS> MercuryDataFile::as ( )
inline

Definition at line 532 of file MercuryData.h.

Referenced by transformMercuryToVTK().

533  {
534  return {this};
535  };
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.

Definition at line 547 of file MercuryData.h.

References file_.

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

548  {
549  file_.seekg(0);
550  return {this};
551  }
std::ifstream file_
Definition: MercuryData.h:565
template<std::size_t NDIMS>
MercuryTimeStepIterator<NDIMS> MercuryDataFile::end ( ) const
inline

Returns a forwarditerator one past the last time step.

Definition at line 557 of file MercuryData.h.

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

558  {
559  return {};
560  }
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()

Definition at line 477 of file MercuryData.h.

References file_.

Referenced by main().

478  {
479  //Store the position, so we can jump back at the end of the function..
480  std::ios::pos_type currentPosition = file_.tellg();
481  //and jump to the start
482  file_.seekg(0);
483  //get the first line
484  std::string line;
485  std::getline(file_, line);
486  file_.seekg(currentPosition); //and pretend nothing has happened
487 
488  std::istringstream lineStream(line);
489 
490  //We'll try to find out if there were exactly enough arguments.
492  lineStream >> step;
493 
494  //Did we reach the end yet?
495  bool isValid = lineStream.good();
496  double dummy;
497  lineStream >> dummy;
498 
499  //now we should have reached it.
500  isValid = isValid && !lineStream.good();
501  return isValid;
502  }
std::ifstream file_
Definition: MercuryData.h:565
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.

Definition at line 460 of file MercuryData.h.

References file_.

461  {
462  return file_.good();
463  }
std::ifstream file_
Definition: MercuryData.h:565

Friends And Related Function Documentation

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

Definition at line 568 of file MercuryData.h.

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

Definition at line 570 of file MercuryData.h.

Member Data Documentation

std::ifstream MercuryDataFile::file_
private

The backing file stream used to represent the data file.

Definition at line 565 of file MercuryData.h.

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


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