Qx v0.5.8
Qt Extensions Library
Loading...
Searching...
No Matches
qx-filestreamwriter.h
1#ifndef QX_FILESTREAMWRITER_H
2#define QX_FILESTREAMWRITER_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-common-io.h"
13
14namespace Qx
15{
16
17class QX_IO_EXPORT FileStreamWriter // Specialized wrapper for QDataStream
18{
19//-Class Variables------------------------------------------------------------------------------------------------
20private:
21 static inline const IoOpReport NULL_FILE_REPORT = IoOpReport(IO_OP_WRITE, IO_ERR_NULL, static_cast<QFile*>(nullptr));
22
23//-Instance Variables------------------------------------------------------------------------------------------------
24private:
25 QFile* mFile;
26 QDataStream mStreamWriter;
27 WriteMode mWriteMode;
28 WriteOptions mWriteOptions;
29 IoOpReport mStatus;
30
31//-Constructor-------------------------------------------------------------------------------------------------------
32public:
33 FileStreamWriter(WriteMode writeMode = Append, WriteOptions writeOptions = NoWriteOptions);
34 FileStreamWriter(const QString& filePath, WriteMode writeMode = Append, WriteOptions writeOptions = NoWriteOptions);
35
36//-Destructor-------------------------------------------------------------------------------------------------------
37public:
39
40//-Instance Functions------------------------------------------------------------------------------------------------
41private:
42 IoOpReport statusFromNative();
43 IoOpReport preWriteErrorCheck();
44 void setFile(const QString& filePath);
45 void unsetFile();
46
47public:
48 // Stock functions
49 QDataStream::ByteOrder byteOrder() const;
50 const QFile* file() const;
51 QDataStream::FloatingPointPrecision floatingPointPrecision() const;
52 void resetStatus();
53 void setByteOrder(QDataStream::ByteOrder bo);
54 void setFloatingPointPrecision(QDataStream::FloatingPointPrecision precision);
55 IoOpReport status() const;
56 IoOpReport writeRawData(const QByteArray& data);
57
58 template<typename T>
61 {
62 IoOpReport check = preWriteErrorCheck();
63
64 if(!check.isFailure())
65 {
66 mStreamWriter << d;
67 mStatus = statusFromNative();
68 }
69
70 return *this;
71 }
72
73 QString filePath() const;
74 void setFilePath(const QString& filePath);
75
76 // New functions
77 bool hasError() const;
78 IoOpReport openFile();
79 void closeFile();
80 bool fileIsOpen() const;
81};
82
83}
84
85#endif // QX_FILESTREAMWRITER_H
The FileStreamWriter class is a specialized wrapper for QDataStream that narrows and simplifies its u...
Definition qx-filestreamwriter.h:18
FileStreamWriter & operator<<(T d)
Definition qx-filestreamwriter.h:60
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 left shift operator for another type.
Definition qx-concepts.h:390
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
@ NoWriteOptions
Definition qx-common-io.h:30
WriteMode
Definition qx-common-io.h:27
@ Append
Definition qx-common-io.h:27
@ IO_ERR_NULL
Definition qx-ioopreport.h:40
@ IO_OP_WRITE
Definition qx-ioopreport.h:20
The qx-common-io header file provides various types, variables, and functions related to file IO.