MolSim
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
FileWriter Class Referenceabstract

Superclass which implements functionality to output data to a file on disk. More...

#include <FileWriter.h>

Inheritance diagram for FileWriter:
NullWriter VTKWriter XYZWriter

Public Member Functions

 FileWriter ()
 Creates a new FileWriter with no file initialized.
 
 FileWriter (const std::string &filename)
 Creates a new FileWriter and opens the file with the given name.
 
virtual ~FileWriter ()
 Closes the opened file and destroys the FileWriter object.
 
void openFile (const std::string &filename)
 Opens / creates the file with the given name.
 
void closeFile ()
 Closes the opened file if it exists, otherwise does nothing.
 
void writeFile (const std::string &content, const std::string &filename="", int iteration=-1, int total=-1)
 Overwrites the contents of the file opened in m_file with a given string. On error, the program will terminate.
 
virtual void writeParticles (const ParticleContainer &particles, int iteration, int total)=0
 Interface function for writing the type, mass, position, velocity and force of a ParticleContainer to a file. Terminates program execution on error.
 

Static Public Member Functions

static void initializeFolder (const std::string &dirname)
 (Re)initializes the output directory.
 

Protected Attributes

std::ofstream m_file
 Output stream containing the file to write contents to.
 

Detailed Description

Superclass which implements functionality to output data to a file on disk.

Constructor & Destructor Documentation

◆ FileWriter() [1/2]

FileWriter::FileWriter ( )

Creates a new FileWriter with no file initialized.

◆ FileWriter() [2/2]

FileWriter::FileWriter ( const std::string &  filename)
explicit

Creates a new FileWriter and opens the file with the given name.

Parameters
filenameThe name of the file to load into the output stream m_file.

◆ ~FileWriter()

virtual FileWriter::~FileWriter ( )
virtual

Closes the opened file and destroys the FileWriter object.

Member Function Documentation

◆ closeFile()

void FileWriter::closeFile ( )

Closes the opened file if it exists, otherwise does nothing.

◆ initializeFolder()

static void FileWriter::initializeFolder ( const std::string &  dirname)
static

(Re)initializes the output directory.

First, the function checks if the output directory exists. If it doesn't, it creates it. Otherwise, it deletes everything inside it.

Parameters
dirnameThe name of the output directory.

◆ openFile()

void FileWriter::openFile ( const std::string &  filename)

Opens / creates the file with the given name.

Parameters
filenameThe name of the file to load into the output stream m_file.

◆ writeFile()

void FileWriter::writeFile ( const std::string &  content,
const std::string &  filename = "",
int  iteration = -1,
int  total = -1 
)

Overwrites the contents of the file opened in m_file with a given string. On error, the program will terminate.

Parameters
contentThe string to be written inside of the file.
filenameAn optional filename to be used with spdlog to display the name of the file currently being written to.
iterationThe optional current iteration of the simulation.
totalThe optional total number of iterations, used to display the current percentage.

◆ writeParticles()

virtual void FileWriter::writeParticles ( const ParticleContainer particles,
int  iteration,
int  total 
)
pure virtual

Interface function for writing the type, mass, position, velocity and force of a ParticleContainer to a file. Terminates program execution on error.

Parameters
particlesThe ParticleContainer.
iterationThe number of the current iteration, used to generate a unique filename.
totalThe total number of iterations, used to display the current percentage.

Implemented in NullWriter, VTKWriter, and XYZWriter.

Member Data Documentation

◆ m_file

std::ofstream FileWriter::m_file
protected

Output stream containing the file to write contents to.


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