Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
qx-textstreamreader.h
1#ifndef QX_TEXTSTREAMREADER_H
2#define QX_TEXTSTREAMREADER_H
3
4// Shared Lib Support
5#include "qx/io/qx_io_export.h"
6
7// Qt Includes
8#include <QTextStream>
9#include <QFile>
10
11// Intra-component Includes
12#include "qx/io/qx-common-io.h"
13#include "qx/io/qx-ioopreport.h"
14
15namespace Qx
16{
17
18class QX_IO_EXPORT TextStreamReader
19{
20//-Class Variables------------------------------------------------------------------------------------------------
21private:
22 static inline const IoOpReport NULL_FILE_REPORT = IoOpReport(IO_OP_READ, IO_ERR_NULL, static_cast<QFile*>(nullptr));
23
24//-Instance Variables------------------------------------------------------------------------------------------------
25private:
26 QFile* mFile;
27 QTextStream mStreamReader;
28 IoOpReport mStatus;
29
30//-Constructor-------------------------------------------------------------------------------------------------------
31public:
33 TextStreamReader(const QString& filePath);
34
35//-Destructor-------------------------------------------------------------------------------------------------------
36public:
38
39//-Instance Functions------------------------------------------------------------------------------------------------
40private:
41 IoOpReport statusFromNative();
42 IoOpReport preReadErrorCheck();
43 void setFile(const QString& filePath);
44 void unsetFile();
45
46public:
47 // Stock functions
48 bool atEnd() const;
49 bool autoDetectUnicode() const;
50 QStringConverter::Encoding encoding() const;
51 const QFile* file() const;
52 int integerBase() const;
53 QLocale locale() const;
54 qint64 pos() const;
55 QString read(qint64 maxlen);
56 QString readAll();
57 QString readLine(qint64 maxlen = 0);
58 IoOpReport readLineInto(QString* line, qint64 maxlen = 0);
59 QTextStream::RealNumberNotation realNumberNotation() const;
60 void reset();
61 void resetStatus();
62 void setAutoDetectUnicode(bool enabled);
63 void setEncoding(QStringConverter::Encoding encoding);
64 void setIntegerBase(int base);
65 void setLocale(const QLocale& locale);
66 void setRealNumberNotation(QTextStream::RealNumberNotation notation);
67 void skipWhiteSpace();
68 IoOpReport status() const;
69
70 template<typename T>
73 {
74 IoOpReport check = preReadErrorCheck();
75
76 if(!check.isFailure())
77 {
78 mStreamReader >> d;
79 mStatus = statusFromNative();
80 }
81
82 return *this;
83 }
84
85 QString filePath() const;
86 void setFilePath(const QString& filePath);
87
88 // New functions
89 bool hasError() const;
90 IoOpReport openFile();
91 void closeFile();
92 bool fileIsOpen() const;
93};
94
95}
96#endif // QX_TEXTSTREAMREADER_H
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
The TextStreamReader class is a specialized wrapper for QTextStream that narrows and simplifies its u...
Definition qx-textstreamreader.h:19
TextStreamReader & operator>>(T &d)
Definition qx-textstreamreader.h:72
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-common-io header file provides various types, variables, and functions related to file IO.