Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
qx-filestreamreader.h
1#ifndef QX_FILESTREAMREADER_H
2#define QX_FILESTREAMREADER_H
3
4// Shared Lib Support
5#include "qx/io/qx_io_export.h"
6
7// Qt Includes
8#include <QDataStream>
9#include <QFile>
10
11// Intra-component Includes
12#include "qx/io/qx-ioopreport.h"
13
14// Extra-component Includes
16
17namespace Qx
18{
19
20class QX_IO_EXPORT FileStreamReader // Specialized wrapper for QDataStream
21{
22//-Class Variables------------------------------------------------------------------------------------------------
23private:
24 static inline const IoOpReport NULL_FILE_REPORT = IoOpReport(IO_OP_READ, IO_ERR_NULL, static_cast<QFile*>(nullptr));
25
26//-Instance Variables------------------------------------------------------------------------------------------------
27private:
28 QFile* mFile;
29 QDataStream mStreamReader;
30 IoOpReport mStatus;
31
32//-Constructor-------------------------------------------------------------------------------------------------------
33public:
35 FileStreamReader(const QString& filePath);
36
37//-Destructor-------------------------------------------------------------------------------------------------------
38public:
40
41//-Instance Functions------------------------------------------------------------------------------------------------
42private:
43 IoOpReport statusFromNative();
44 IoOpReport preReadErrorCheck();
45 void setFile(const QString& filePath);
46 void unsetFile();
47
48public:
49 // Stock functions
50 bool atEnd() const;
51 QDataStream::ByteOrder byteOrder() const;
52 const QFile* file() const;
53 QDataStream::FloatingPointPrecision floatingPointPrecision() const;
54 IoOpReport readRawData(QByteArray& data, int len);
55 void resetStatus();
56 void setByteOrder(QDataStream::ByteOrder bo);
57 void setFloatingPointPrecision(QDataStream::FloatingPointPrecision precision);
58 IoOpReport skipRawData(int len);
59 IoOpReport status() const;
60
61 template<typename T>
64 {
65 IoOpReport check = preReadErrorCheck();
66
67 if(!check.isFailure())
68 {
69 mStreamReader >> d;
70 mStatus = statusFromNative();
71 }
72
73 return *this;
74 }
75
76 QString filePath() const;
77 void setFilePath(const QString& filePath);
78
79 // New functions
80 bool hasError() const;
81 IoOpReport openFile();
82 void closeFile();
83 bool fileIsOpen() const;
84};
85
86}
87
88#endif // QX_FILESTREAMREADER_H
The FileStreamReader class is a specialized wrapper for QDataStream that narrows and simplifies its u...
Definition qx-filestreamreader.h:21
FileStreamReader & operator>>(T &d)
Definition qx-filestreamreader.h:63
The IoOpReport class is a container for details regarding the outcome of an IO operation.
Definition qx-ioopreport.h:53
bool isFailure() const
Definition qx-ioopreport.cpp:390
Specifies that a type defines a right shift operator for another type.
Definition qx-concepts.h:402
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
@ IO_ERR_NULL
Definition qx-ioopreport.h:40
@ IO_OP_READ
Definition qx-ioopreport.h:20
The qx-concepts header file provides a library of general purpose concepts as an extension of the sta...