Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::FileStreamWriter Class Reference

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 QFilefile () 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>
FileStreamWriteroperator<< (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)
 

Detailed Description

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.

See also
FileStreamReader and TextStreamWriter

Constructor & Destructor Documentation

◆ FileStreamWriter() [1/2]

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.

Note
The following WriteMode values are not supported with this class and will be remapped as shown:
See also
setFilePath().

◆ FileStreamWriter() [2/2]

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.

Note
The following WriteMode values are not supported with this class and will be remapped as shown:
See also
filePath() and setFilePath().

◆ ~FileStreamWriter()

Qx::FileStreamWriter::~FileStreamWriter ( )

Destroys the file stream writer, along with closing and deleting the underlying file, if present.

Member Function Documentation

◆ byteOrder()

QDataStream::ByteOrder Qx::FileStreamWriter::byteOrder ( ) const

Returns the current byte order setting.

See also
setByteOrder().

◆ closeFile()

void Qx::FileStreamWriter::closeFile ( )

Closes the file associated with the file stream writer, if present.

◆ file()

const QFile * Qx::FileStreamWriter::file ( ) const

Returns an immutable pointer to the file managed by the stream.

See also
filePath().

◆ fileIsOpen()

bool Qx::FileStreamWriter::fileIsOpen ( ) const

Returns true if the file managed by the stream is open; otherwise, returns false.

◆ filePath()

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.

See also
setFilePath().

◆ floatingPointPrecision()

QDataStream::FloatingPointPrecision Qx::FileStreamWriter::floatingPointPrecision ( ) const

Returns the floating point precision of the file stream reader.

See also
setFloatingPointPrecision().

◆ hasError()

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().

◆ openFile()

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.

◆ operator<<()

template<typename T >
requires defines_left_shift_for<QDataStream, T>
FileStreamWriter & Qx::FileStreamWriter::operator<< ( T d)
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.

◆ resetStatus()

void Qx::FileStreamWriter::resetStatus ( )

Resets the status of the file stream writer.

Note
If an error occurs while writing the stream will ignore all further write attempts and hold its current status until this function is called.
See also
status().

◆ setByteOrder()

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.

See also
byteOrder().

◆ setFilePath()

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.

See also
filePath() and openFile().

◆ setFloatingPointPrecision()

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.

Note
This property does not affect the serialization of qfloat16 instances.

◆ status()

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.

◆ writeRawData()

IoOpReport Qx::FileStreamWriter::writeRawData ( const QByteArray & data)

Writes data to the stream and returns an operation report.

The data is not encoded.

Note
Unlike with a raw QDataStream, if the number of bytes actually written is less than data.size() it is treated as a IoOpResultType::IO_ERR_FILE_SIZE_MISMATCH error since data is not forced to be written in chunks for that type.

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