Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
Qx::FileStreamReader Class Reference

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 QFilefile () 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&>
FileStreamReaderoperator>> (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
 

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
FileStreamWriter and TextStreamReader

Constructor & Destructor Documentation

◆ FileStreamReader() [1/2]

Qx::FileStreamReader::FileStreamReader ( )

Constructs a file stream reader with no file set.

See also
setFilePath().

◆ FileStreamReader() [2/2]

Qx::FileStreamReader::FileStreamReader ( const QString & filePath)

Constructs a file stream reader that is linked to the file at filePath.

See also
filePath() and setFilePath().

◆ ~FileStreamReader()

Qx::FileStreamReader::~FileStreamReader ( )

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

Member Function Documentation

◆ atEnd()

bool Qx::FileStreamReader::atEnd ( ) const

Returns true if the reader has reached the end of the file; otherwise returns false

◆ byteOrder()

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

Returns the current byte order setting.

See also
setByteOrder().

◆ closeFile()

void Qx::FileStreamReader::closeFile ( )

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

◆ file()

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

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

See also
filePath().

◆ fileIsOpen()

bool Qx::FileStreamReader::fileIsOpen ( ) const

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

◆ filePath()

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.

See also
setFilePath().

◆ floatingPointPrecision()

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

Returns the floating point precision of the file stream reader.

See also
setFloatingPointPrecision().

◆ hasError()

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

◆ openFile()

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.

◆ operator>>()

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

◆ readRawData()

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.

Note
Unlike with a raw QDataStream, if the number of bytes actually read is less than len it is treated as a QDataStream::ReadPastEnd error since the length of a QFile based I/O device should always be known and data is not received in chunks for that type.

◆ resetStatus()

void Qx::FileStreamReader::resetStatus ( )

Resets the status of the file stream reader.

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

◆ setByteOrder()

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.

See also
byteOrder().

◆ setFilePath()

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.

See also
filePath() and openFile().

◆ setFloatingPointPrecision()

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.

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

◆ skipRawData()

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.

Note
Unlike with a raw QDataStream, if the number of bytes actually skipped is less than len it is treated as a QDataStream::ReadPastEnd error since the length of a QFile based I/O device should always be known and data is not received in chunks for that type.

◆ status()

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.


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