Qx v0.5.7
Qt Extensions Library
Loading...
Searching...
No Matches
qx-ioopreport.h
1#ifndef QX_IOOPREPORT_H
2#define QX_IOOPREPORT_H
3
4// Shared Lib Support
5#include "qx/io/qx_io_export.h"
6
7// Qt Includes
8#include <QStringList>
9#include <QHash>
10#include <QFile>
11#include <QDir>
12
13// Inter-project Includes
15
16namespace Qx
17{
18
19//-Types------------------------------------------------------------------------------------------------------
49
50
51//-Classes--------------------------------------------------------------------------------------------
52class QX_IO_EXPORT IoOpReport final : public AbstractError<"Qx::IoOpReport", 1>
53{
54//-Class Members----------------------------------------------------------------------------------------------------
55private:
56 static const inline QString NULL_TARGET = u"<NULL>"_s;
57 static const inline QString TYPE_MACRO = u"<target>"_s;
58 static const inline QHash<IoOpTargetType, QString> TARGET_TYPE_STRINGS = {
59 {IO_FILE, u"file"_s},
60 {IO_DIR, u"directory"_s}
61 };
62 static const inline QString SUCCESS_TEMPLATE = uR"(Successfully %1 %2 "%3")"_s;
63 static const inline QString ERROR_TEMPLATE = uR"(Error while %1 %2 "%3")"_s;
64 static const inline QHash<IoOpType, QString> SUCCESS_VERBS = {
65 {IO_OP_READ, u"read"_s},
66 {IO_OP_WRITE, u"wrote"_s},
67 {IO_OP_ENUMERATE, u"enumerated"_s},
68 {IO_OP_INSPECT, u"inspected"_s},
69 {IO_OP_MANIPULATE, u"manipulated"_s}
70 };
71 static const inline QHash<IoOpType, QString> ERROR_VERBS = {
72 {IO_OP_READ, u"reading"_s},
73 {IO_OP_WRITE, u"writing"_s},
74 {IO_OP_ENUMERATE, u"enumerating"_s},
75 {IO_OP_INSPECT, u"inspecting"_s},
76 {IO_OP_MANIPULATE, u"manipulating"_s}
77 };
78 static const inline QHash<IoOpResultType, QString> ERROR_INFO = {
79 {IO_ERR_UNKNOWN, u"An unknown error has occurred."_s},
80 {IO_ERR_ACCESS_DENIED, u"Access denied."_s},
81 {IO_ERR_WRONG_TYPE, u"Target is not a "_s + TYPE_MACRO + u"."_s},
82 {IO_ERR_OUT_OF_RES, u"Out of resources."_s},
83 {IO_ERR_READ, u"General read error."_s},
84 {IO_ERR_WRITE, u"General write error."_s},
85 {IO_ERR_FATAL, u"A fatal error has occurred."_s},
86 {IO_ERR_OPEN, u"Could not open "_s + TYPE_MACRO + u"."_s},
87 {IO_ERR_ABORT, u"The operation was aborted."_s},
88 {IO_ERR_TIMEOUT, u"Request timed out."_s},
89 {IO_ERR_REMOVE, u"The "_s + TYPE_MACRO + u" could not be removed."_s},
90 {IO_ERR_RENAME, u"The "_s + TYPE_MACRO + u" could not be renamed."_s},
91 {IO_ERR_REPOSITION, u"The "_s + TYPE_MACRO + u" could not be moved."_s},
92 {IO_ERR_RESIZE, u"The "_s + TYPE_MACRO + u" could not be resized."_s},
93 {IO_ERR_COPY, u"The "_s + TYPE_MACRO + u" could not be copied."_s},
94 {IO_ERR_DNE, u"The "_s + TYPE_MACRO + u" does not exist."_s},
95 {IO_ERR_PATH_DNE, u"The containing path of the "_s + TYPE_MACRO + u" does not exist."_s},
96 {IO_ERR_NULL, u"The target is null"_s},
97 {IO_ERR_EXISTS, u"The "_s + TYPE_MACRO + u" already exists."_s},
98 {IO_ERR_CANT_CREATE, u"The "_s + TYPE_MACRO + u" could not be created."_s},
99 {IO_ERR_CANT_CREATE_PATH, u"The path to the "_s + TYPE_MACRO + u" could not be created."_s},
100 {IO_ERR_FILE_SIZE_MISMATCH, u"File size mismatch."_s},
101 {IO_ERR_CURSOR_OOB, u"File data cursor has gone out of bounds."_s},
102 {IO_ERR_FILE_NOT_OPEN, u"The file is not open."_s}
103 };
104 /* TODO: In the many const QHashs like this throughout the lib, figure out how to also
105 * make the values const (for since they aren't to be modified), because as is they don't
106 * compile that way.
107 */
108
109//-Instance Members-------------------------------------------------------------------------------------------------
110private:
111 bool mNull;
112 IoOpType mOperation;
113 IoOpResultType mResult;
114 IoOpTargetType mTargetType;
115 QString mTarget;
116 QString mOutcome;
117 QString mOutcomeInfo;
118
119//-Constructor-------------------------------------------------------------------------------------------------------
120public:
121 IoOpReport();
122 IoOpReport(IoOpType op, IoOpResultType res, const QFileDevice& tar);
123 IoOpReport(IoOpType op, IoOpResultType res, const QFileDevice* tar);
124 IoOpReport(IoOpType op, IoOpResultType res, const QDir& tar);
125 IoOpReport(IoOpType op, IoOpResultType res, const QDir* tar);
126 IoOpReport(IoOpType op, IoOpResultType res, const QFileInfo& tar);
127
128//-Instance Functions----------------------------------------------------------------------------------------------
129private:
130 void parseOutcome();
131
132 quint32 deriveValue() const override;
133 QString derivePrimary() const override;
134 QString deriveSecondary() const override;
135
136public:
137 IoOpType operation() const;
138 IoOpResultType result() const;
139 IoOpTargetType resultTargetType() const;
140 QString target() const;
141 QString outcome() const;
142 QString outcomeInfo() const;
143 bool isFailure() const;
144 bool isNull() const;
145};
146
147}
148
149#endif // QX_IOOPREPORT_H
The AbstractError template class completes the Error interface and acts as the base class from which ...
Definition qx-abstracterror.h:86
The IoOpReport class is a container for details regarding the outcome of an IO operation.
Definition qx-ioopreport.h:53
The Qx namespace is the main namespace through which all non-global functionality of the Qx library i...
Definition qx-processwaiter.cpp:5
IoOpResultType
Definition qx-ioopreport.h:21
@ IO_ERR_NULL
Definition qx-ioopreport.h:40
@ IO_ERR_CURSOR_OOB
Definition qx-ioopreport.h:45
@ IO_ERR_ABORT
Definition qx-ioopreport.h:31
@ IO_ERR_REMOVE
Definition qx-ioopreport.h:33
@ IO_ERR_READ
Definition qx-ioopreport.h:27
@ IO_ERR_FILE_SIZE_MISMATCH
Definition qx-ioopreport.h:44
@ IO_ERR_EXISTS
Definition qx-ioopreport.h:41
@ IO_ERR_COPY
Definition qx-ioopreport.h:37
@ IO_ERR_WRONG_TYPE
Definition qx-ioopreport.h:25
@ IO_ERR_OUT_OF_RES
Definition qx-ioopreport.h:26
@ IO_ERR_ACCESS_DENIED
Definition qx-ioopreport.h:24
@ IO_ERR_FILE_NOT_OPEN
Definition qx-ioopreport.h:46
@ IO_SUCCESS
Definition qx-ioopreport.h:22
@ IO_ERR_FATAL
Definition qx-ioopreport.h:29
@ IO_ERR_RENAME
Definition qx-ioopreport.h:34
@ IO_ERR_DNE
Definition qx-ioopreport.h:38
@ IO_ERR_UNKNOWN
Definition qx-ioopreport.h:23
@ IO_ERR_OPEN
Definition qx-ioopreport.h:30
@ IO_ERR_WRITE
Definition qx-ioopreport.h:28
@ IO_ERR_REPOSITION
Definition qx-ioopreport.h:35
@ IO_ERR_RESIZE
Definition qx-ioopreport.h:36
@ IO_ERR_CANT_CREATE
Definition qx-ioopreport.h:42
@ IO_ERR_TIMEOUT
Definition qx-ioopreport.h:32
IoOpTargetType
Definition qx-ioopreport.h:48
@ IO_FILE
Definition qx-ioopreport.h:48
@ IO_DIR
Definition qx-ioopreport.h:48
IoOpType
Definition qx-ioopreport.h:20
@ IO_OP_READ
Definition qx-ioopreport.h:20
@ IO_OP_ENUMERATE
Definition qx-ioopreport.h:20
@ IO_OP_INSPECT
Definition qx-ioopreport.h:20
@ IO_OP_WRITE
Definition qx-ioopreport.h:20
The qx-abstracterror.h header file provides access to the base class from which custom error types sh...