C
SafeRenderer::QSafeFile Class
class SafeRenderer::QSafeFileThe QSafeFile class reads the data from a file using Posix API for file access. More...
| Header: | #include <QSafeFile> |
| Since: | QtSafeRenderer 1.0 |
Public Types
| enum | OpenMode { ReadOnly, ReadAndWrite } |
Public Functions
| QSafeFile(const SafeRenderer::qchar *const filenameArg, const SafeRenderer::QSafeFile::OpenMode modeArg = ReadOnly) | |
| ~QSafeFile() | |
| SafeRenderer::quint32 | available() const |
| void | readData(SafeRenderer::quchar *const bufferArg, const SafeRenderer::quint32 bytes, const off_t offset = 0) const |
| void | writeData(const SafeRenderer::quchar *const bufferArg, const SafeRenderer::quint32 size) const |
Member Type Documentation
enum QSafeFile::OpenMode
This enum type is used to specify the open mode of a QSafeFile.
| Constant | Value | Description |
|---|---|---|
SafeRenderer::QSafeFile::ReadOnly | 0 | The file is opened in read-only mode. |
SafeRenderer::QSafeFile::ReadAndWrite | 1 | The file is opened in read-write mode. |
Member Function Documentation
QSafeFile::QSafeFile(const SafeRenderer::qchar *const filenameArg, const SafeRenderer::QSafeFile::OpenMode modeArg = ReadOnly)
Constructs the safe file object.
Opens the file named filenameArg with the open mode specified by modeArg.
modeArg is an optional parameter, with the default value being QSafeFile::OpenMode::ReadOnly. For possible open modes see QSafeFile::OpenMode.
In case of a failure, the following exception will be thrown:
| Exception | Id | Description |
|---|---|---|
| SafeRenderer::QSafeFileException | SafeRenderer::QSafeFileException::FailureToOpen | The file could not be opened for reading. |
[noexcept] QSafeFile::~QSafeFile()
Destructs a safe file object.
Closes the file if the file is open.
SafeRenderer::quint32 QSafeFile::available() const
Returns the amount of bytes available in the file. 0 in case of any failure.
void QSafeFile::readData(SafeRenderer::quchar *const bufferArg, const SafeRenderer::quint32 bytes, const off_t offset = 0) const
Reads bytes amount of data from the opened file to the bufferArg.
The optional offset parameter specifies the starting point for file reading in bytes from the start of the file. Provide a non-negative integer; if offset exceeds file size, it triggers SafeRenderer::QSafeFile::OutOfBoundsError. If offset is 0 (default) reading starts from the file's beginning.
In case of a failure, the following exception will be thrown:
| Exception | Id | Description |
|---|---|---|
| SafeRenderer::QSafeFileException | SafeRenderer::QSafeFileException::ReadError | The requested number of bytes could not be read from the opened file or the provided buffer is a NULL pointer. |
void QSafeFile::writeData(const SafeRenderer::quchar *const bufferArg, const SafeRenderer::quint32 size) const
Writes size amount of data from the bufferArg to the opened file.
In case of a failure, the following exception will be thrown:
| Exception | Id | Description |
|---|---|---|
| SafeRenderer::QSafeFileException | SafeRenderer::QSafeFileException::FailureToOpen | The file was not properly opened. |
| SafeRenderer::QSafeFileException | SafeRenderer::QSafeFileException::WriteError | An error occurred during the write operation. |
Available under certain Qt licenses.
Find out more.