Gromacs  2018.8
 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/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::string &filename)
 Opens a text file as a stream. More...
 
 TextOutputFile (FILE *fp)
 Initializes file object from an existing file handle. More...
 
virtual void write (const char *text)
 Writes a given string to the stream.
 
virtual void close ()
 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::string &  filename)
explicit

Opens a text file as a stream.

Parameters
[in]filenamePath to the file to open.
Exceptions
std::bad_allocif out of memory.
FileIOErroron any I/O error.
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 ( )
virtual

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: