Gromacs
2022.2
|
#include <gromacs/utility/textstream.h>
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... | |
|
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.
|
pure virtual |
Reads a line (with newline included) from the stream.
[out] | line | String to receive the line. |
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.