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::TextInputFile Class Reference

#include <gromacs/utility/filestream.h>

+ Inheritance diagram for gmx::TextInputFile:
+ Collaboration diagram for gmx::TextInputFile:

Description

Text input stream implementation for reading from a file.

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

Public Member Functions

 TextInputFile (const std::string &filename)
 Opens a text file as a stream. More...
 
 TextInputFile (FILE *fp)
 Initializes file object from an existing file handle. More...
 
FILE * handle ()
 Returns a raw handle to the input file. More...
 
virtual bool readLine (std::string *line)
 Reads a line (with newline included) from the stream. More...
 
virtual void close ()
 Closes the stream. More...
 

Static Public Member Functions

static FILE * openRawHandle (const char *filename)
 Opens a file and returns a FILE handle. More...
 
static FILE * openRawHandle (const std::string &filename)
 Opens a file and returns a FILE handle. More...
 

Constructor & Destructor Documentation

gmx::TextInputFile::TextInputFile ( 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::TextInputFile::TextInputFile ( 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::TextInputFile::close ( )
virtual

Closes the stream.

It is not allowed to read from a stream after it has been closed. See TextOutputStream::close() for rationale for a close() method separate from the destructor. For input, failures during close should be rare, but it is clearer to keep the interface symmetric.

Implements gmx::TextInputStream.

FILE * gmx::TextInputFile::handle ( )

Returns a raw handle to the input file.

This is provided for interoperability with older C-like code.

FILE * gmx::TextInputFile::openRawHandle ( const char *  filename)
static

Opens a file and returns a FILE handle.

Parameters
[in]filenamePath of the file to open.
Exceptions
FileIOErroron any I/O error.

Instead of returning NULL on errors, throws an exception with additional details (including the file name and errno).

FILE * gmx::TextInputFile::openRawHandle ( const std::string &  filename)
static

Opens a file and returns a FILE handle.

Parameters
[in]filenamePath of the file to open.
Exceptions
FileIOErroron any I/O error.

Instead of returning NULL on errors, throws an exception with additional details (including the file name and errno).

bool gmx::TextInputFile::readLine ( std::string *  line)
virtual

Reads a line (with newline included) from the stream.

Parameters
[out]lineString to receive the line.
Returns
false if nothing was read because the stream ended.

On error or when false is returned, line will be empty.

Implements gmx::TextInputStream.


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