Gromacs  2024.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions | Static Public Member Functions
gmx::TextOutputFile Class Reference

#include <gromacs/utility/include/gromacs/utility/filestream.h>

+ Inheritance diagram for gmx::TextOutputFile:
+ Collaboration diagram for gmx::TextOutputFile:

Description

Text output stream implementation for writing to a file.

Implementations for the TextOutputStream methods throw FileIOError on any I/O error.

Public Member Functions

 TextOutputFile (const std::filesystem::path &filename)
 
 TextOutputFile (FILE *fp)
 Initializes file object from an existing file handle. More...
 
void write (const char *text) override
 Writes a given string to the stream.
 
void close () override
 Closes the stream. More...
 

Static Public Member Functions

static TextOutputFilestandardOutput ()
 Returns a stream for accessing stdout. More...
 
static TextOutputFilestandardError ()
 Returns a stream for accessing stderr. More...
 

Constructor & Destructor Documentation

gmx::TextOutputFile::TextOutputFile ( const std::filesystem::path &  filename)
explicit

gmx::TextOutputFile::TextOutputFile ( FILE *  fp)
explicit

Initializes file object from an existing file handle.

Parameters
[in]fpFile handle to use.
Exceptions
std::bad_allocif out of memory.

The caller is responsible of closing the file; close() does nothing for an object constructed this way.

Member Function Documentation

void gmx::TextOutputFile::close ( )
overridevirtual

Closes the stream.

It is not allowed to write to a stream after it has been closed. A method separate from the destructor is provided such that errors that occur while closing the stream (e.g., when closing the file) can be handled using exceptions. The destructor is not allowed to throw, so code that wants to observe such errors needs to call close() after it has finished writing to the stream.

Implements gmx::TextOutputStream.

TextOutputFile & gmx::TextOutputFile::standardError ( )
static

Returns a stream for accessing stderr.

Exceptions
std::bad_allocif out of memory (only on first call).
TextOutputFile & gmx::TextOutputFile::standardOutput ( )
static

Returns a stream for accessing stdout.

Exceptions
std::bad_allocif out of memory (only on first call).

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