#include <gromacs/utility/include/gromacs/utility/filestream.h>
Text input stream implementation for reading from a file.
Implementations for the TextInputStream methods throw FileIOError on any I/O error.
gmx::TextInputFile::TextInputFile |
( |
const std::filesystem::path & |
filename | ) |
|
|
explicit |
Opens a text file as a stream.
- Parameters
-
[in] | filename | Path to the file to open. |
- Exceptions
-
std::bad_alloc | if out of memory. |
FileIOError | on any I/O error. |
gmx::TextInputFile::TextInputFile |
( |
FILE * |
fp | ) |
|
|
explicit |
Initializes file object from an existing file handle.
- Parameters
-
[in] | fp | File handle to use. |
- Exceptions
-
std::bad_alloc | if out of memory. |
The caller is responsible of closing the file; close() does nothing for an object constructed this way.
void gmx::TextInputFile::close |
( |
| ) |
|
|
overridevirtual |
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.
FilePtr gmx::TextInputFile::openRawHandle |
( |
const std::filesystem::path & |
filename | ) |
|
|
static |
Opens a file and returns an RAII-style FILE
handle.
- Parameters
-
[in] | filename | Path of the file to open. |
- Exceptions
-
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 | ) |
|
|
overridevirtual |
Reads a line (with newline included) from the stream.
- Parameters
-
[out] | line | String 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: