Qx v0.5.8
Qt Extensions Library
|
The FileStreamReader class is a specialized wrapper for QDataStream that narrows and simplifies its usage for reading files. More...
#include <qx/io/qx-filestreamreader.h>
Public Member Functions | |
FileStreamReader () | |
FileStreamReader (const QString &filePath) | |
~FileStreamReader () | |
bool | atEnd () const |
QDataStream::ByteOrder | byteOrder () const |
void | closeFile () |
const QFile * | file () const |
bool | fileIsOpen () const |
QString | filePath () const |
QDataStream::FloatingPointPrecision | floatingPointPrecision () const |
bool | hasError () const |
IoOpReport | openFile () |
template<typename T > requires defines_right_shift_for<QDataStream, T&> | |
FileStreamReader & | operator>> (T &d) |
IoOpReport | readRawData (QByteArray &data, int len) |
void | resetStatus () |
void | setByteOrder (QDataStream::ByteOrder bo) |
void | setFilePath (const QString &filePath) |
void | setFloatingPointPrecision (QDataStream::FloatingPointPrecision precision) |
IoOpReport | skipRawData (int len) |
IoOpReport | status () const |
Most member functions are the same or slightly modified versions of those from QDataStream.
The file on which to operate is specified as a path and the underlying handle is managed by the stream.
Qx::FileStreamReader::FileStreamReader | ( | ) |
Constructs a file stream reader with no file set.
Qx::FileStreamReader::FileStreamReader | ( | const QString & | filePath | ) |
Constructs a file stream reader that is linked to the file at filePath.
Qx::FileStreamReader::~FileStreamReader | ( | ) |
Destroys the file stream reader, along with closing and deleting the underlying file, if present.
bool Qx::FileStreamReader::atEnd | ( | ) | const |
Returns true
if the reader has reached the end of the file; otherwise returns false
QDataStream::ByteOrder Qx::FileStreamReader::byteOrder | ( | ) | const |
Returns the current byte order setting.
void Qx::FileStreamReader::closeFile | ( | ) |
Closes the file associated with the file stream reader, if present.
const QFile * Qx::FileStreamReader::file | ( | ) | const |
Returns an immutable pointer to the file managed by the stream.
bool Qx::FileStreamReader::fileIsOpen | ( | ) | const |
Returns true
if the file managed by the stream is open; otherwise, returns false
.
QString Qx::FileStreamReader::filePath | ( | ) | const |
Returns the path of the file associated with the stream, if present.
If no file is assigned the path will be null.
QDataStream::FloatingPointPrecision Qx::FileStreamReader::floatingPointPrecision | ( | ) | const |
Returns the floating point precision of the file stream reader.
bool Qx::FileStreamReader::hasError | ( | ) | const |
Returns true
if the stream's current status indicates that an error has occurred; otherwise, returns false
.
Equivalent to status().isFailure()
.
IoOpReport Qx::FileStreamReader::openFile | ( | ) |
Opens the file associated with the file stream reader and returns an operation report.
This function must be called before any data is read after a file is assigned to the stream.
|
inline |
Reads the data type T
into d, and returns a reference to the stream.
This template is constrained such that effectively, the extraction operator for this class is available for all data types that QDataStream defines an extraction operator for.
IoOpReport Qx::FileStreamReader::readRawData | ( | QByteArray & | data, |
int | len ) |
Reads len bytes from the stream into data and returns an operation report.
data is automatically allocated. The data is not decoded.
void Qx::FileStreamReader::resetStatus | ( | ) |
Resets the status of the file stream reader.
void Qx::FileStreamReader::setByteOrder | ( | QDataStream::ByteOrder | bo | ) |
Sets the serialization byte order to bo.
The bo parameter can be QDataStream::BigEndian or QDataStream::LittleEndian.
The default setting is big endian.
void Qx::FileStreamReader::setFilePath | ( | const QString & | filePath | ) |
Links the stream to the file at filePath, which can be a null QString to unset the current file. If a file was already set to the stream, it will be closed as it is replaced.
The file must be opened through the stream before it can be used.
void Qx::FileStreamReader::setFloatingPointPrecision | ( | QDataStream::FloatingPointPrecision | precision | ) |
Sets the floating point precision of the file stream reader to precision.
All floating point numbers will be read using the stream's precision regardless of the stream operator called.
The bo parameter can be QDataStream::BigEndian or QDataStream::LittleEndian.
IoOpReport Qx::FileStreamReader::skipRawData | ( | int | len | ) |
Skips len bytes from the file and returns an operation report.
This is equivalent to calling readRawData() on a buffer of length len and ignoring the buffer.
IoOpReport Qx::FileStreamReader::status | ( | ) | const |
Returns the status of the file stream reader.
The status is a report of the last read operation performed by FileStreamReader. If no read operation has been performed since the stream was constructed or resetStatus() was last called the report will be null.