Qx v0.5.8
Qt Extensions Library
|
The FileStreamWriter class is a specialized wrapper for QDataStream that narrows and simplifies its usage for writing files. More...
#include <qx/io/qx-filestreamwriter.h>
Public Member Functions | |
FileStreamWriter (const QString &filePath, WriteMode writeMode=Append, WriteOptions writeOptions=NoWriteOptions) | |
FileStreamWriter (WriteMode writeMode=Append, WriteOptions writeOptions=NoWriteOptions) | |
~FileStreamWriter () | |
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_left_shift_for<QDataStream, T> | |
FileStreamWriter & | operator<< (T d) |
void | resetStatus () |
void | setByteOrder (QDataStream::ByteOrder bo) |
void | setFilePath (const QString &filePath) |
void | setFloatingPointPrecision (QDataStream::FloatingPointPrecision precision) |
IoOpReport | status () const |
IoOpReport | writeRawData (const QByteArray &data) |
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::FileStreamWriter::FileStreamWriter | ( | WriteMode | writeMode = Append, |
WriteOptions | writeOptions = NoWriteOptions ) |
Constructs a file stream writer that is configured with writeMode and writeOptions.
No file is initially set.
Qx::FileStreamWriter::FileStreamWriter | ( | const QString & | filePath, |
WriteMode | writeMode = Append, | ||
WriteOptions | writeOptions = NoWriteOptions ) |
Constructs a file stream writer that is linked to the file at filePath, configured with writeMode and writeOptions.
Qx::FileStreamWriter::~FileStreamWriter | ( | ) |
Destroys the file stream writer, along with closing and deleting the underlying file, if present.
QDataStream::ByteOrder Qx::FileStreamWriter::byteOrder | ( | ) | const |
Returns the current byte order setting.
void Qx::FileStreamWriter::closeFile | ( | ) |
Closes the file associated with the file stream writer, if present.
const QFile * Qx::FileStreamWriter::file | ( | ) | const |
Returns an immutable pointer to the file managed by the stream.
bool Qx::FileStreamWriter::fileIsOpen | ( | ) | const |
Returns true
if the file managed by the stream is open; otherwise, returns false
.
QString Qx::FileStreamWriter::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::FileStreamWriter::floatingPointPrecision | ( | ) | const |
Returns the floating point precision of the file stream reader.
bool Qx::FileStreamWriter::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::FileStreamWriter::openFile | ( | ) |
Opens the file associated with the file stream writer and returns an operation report.
This function must be called before any data is written, unless the file is already open in a mode that supports writing before the stream was constructed.
|
inline |
Writes d of type T
to the stream. Returns a reference to the stream.
This template is constrained such that effectively, the insertion operator for this class is available for all data types that QDataStream defines an insertion operator for.
void Qx::FileStreamWriter::resetStatus | ( | ) |
Resets the status of the file stream writer.
void Qx::FileStreamWriter::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::FileStreamWriter::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::FileStreamWriter::setFloatingPointPrecision | ( | QDataStream::FloatingPointPrecision | precision | ) |
Sets the floating point precision of the file stream reader to precision.
All floating point numbers will be written using the stream's precision regardless of the stream operator called.
The bo parameter can be QDataStream::BigEndian or QDataStream::LittleEndian.
IoOpReport Qx::FileStreamWriter::status | ( | ) | const |
Returns the status of the file stream writer.
The status is a report of the last write operation performed by FileStreamWriter. If no write operation has been performed since the stream was constructed or resetStatus() was last called the report will be null.
IoOpReport Qx::FileStreamWriter::writeRawData | ( | const QByteArray & | data | ) |
Writes data to the stream and returns an operation report.
The data is not encoded.