Gromacs  2016.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
List of all members | Public Member Functions
gmx::TextInputStream Class Referenceabstract

#include <gromacs/utility/textstream.h>

+ Inheritance diagram for gmx::TextInputStream:

Description

Interface for reading text.

Concrete implementations can read the text from, e.g., a file or an in-memory string. The main use is to allow unit tests to inject in-memory buffers instead of writing files to be read by the code under test, but there are also use cases outside the tests where it is useful to abstract out whether the input is from a real file or something else.

To use more advanced formatting than reading raw lines, use TextReader.

Both methods in the interface can throw std::bad_alloc or other exceptions that indicate failures to read from the stream.

Public Member Functions

virtual bool readLine (std::string *line)=0
 Reads a line (with newline included) from the stream. More...
 
virtual void close ()=0
 Closes the stream. More...
 

Member Function Documentation

virtual void gmx::TextInputStream::close ( )
pure 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.

Implemented in gmx::TextInputFile, gmx::StringInputStream, and gmx::StandardInputStream.

virtual bool gmx::TextInputStream::readLine ( std::string *  line)
pure 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.

Implemented in gmx::TextInputFile, gmx::StringInputStream, and gmx::StandardInputStream.


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