Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qiooperation_p_p.h
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
// Qt-Security score:significant reason:default
4
5
#
ifndef
QIOOPERATION_P_P_H
6
#
define
QIOOPERATION_P_P_H
7
8
//
9
// W A R N I N G
10
// -------------
11
//
12
// This file is not part of the Qt API. It exists purely as an
13
// implementation detail. This header file may change from version to
14
// version without notice, or even be removed.
15
//
16
// We mean it.
17
//
18
19
#
include
"qiooperation_p.h"
20
#
include
"qrandomaccessasyncfile_p.h"
21
22
#
include
<
QtCore
/
private
/
qobject_p
.
h
>
23
24
#
include
<
QtCore
/
qspan
.
h
>
25
#
include
<
QtCore
/
qvarlengtharray
.
h
>
26
27
#
ifdef
QT_RANDOMACCESSASYNCFILE_QIORING
28
#
include
<
QtCore
/
private
/
qioring_p
.
h
>
29
#
endif
30
31
#
include
<
variant
>
32
33
QT_BEGIN_NAMESPACE
34
35
namespace
QtPrivate
{
36
37
class
QIOOperationDataStorage
38
{
39
public
:
40
// When passing QSpan<QSpan<T>>, we'd better have an underlying storage
41
// for an outer span, so that users could pass in a temporary object.
42
// We'd use QVarLengthArray for that. Having 256 elements (the default)
43
// seems to be unneeded for vectored IO. For now I picked 10 as a reasonable
44
// default. But maybe even less?
45
static
constexpr
qsizetype
DefaultNumOfBuffers
= 10;
46
using
ReadSpans
=
QVarLengthArray
<
QSpan
<
std
::
byte
>,
DefaultNumOfBuffers
>;
47
using
WriteSpans
=
QVarLengthArray
<
QSpan
<
const
std
::
byte
>,
DefaultNumOfBuffers
>;
48
49
explicit
QIOOperationDataStorage
()
50
:
data
(
std
::
monostate
{})
51
{}
52
explicit
QIOOperationDataStorage
(QSpan<
const
QSpan<std::byte>> s)
53
:
data
(
ReadSpans
(
s
.
begin
(),
s
.
end
()))
54
{}
55
explicit
QIOOperationDataStorage
(
QSpan
<
const
QSpan
<
const
std
::
byte
>>
s
)
56
:
data
(
WriteSpans
(
s
.
begin
(),
s
.
end
()))
57
{}
58
explicit
QIOOperationDataStorage
(
const
QByteArray
&
a
)
59
:
data
(
a
)
60
{}
61
explicit
QIOOperationDataStorage
(
QByteArray
&&
a
)
62
:
data
(
std
::
move
(
a
))
63
{}
64
65
bool
isEmpty
()
const
66
{
return
std
::
holds_alternative
<
std
::
monostate
>(
data
); }
67
68
bool
containsReadSpans
()
const
69
{
return
std
::
holds_alternative
<
ReadSpans
>(
data
); }
70
71
bool
containsWriteSpans
()
const
72
{
return
std
::
holds_alternative
<
WriteSpans
>(
data
); }
73
74
bool
containsByteArray
()
const
75
{
return
std
::
holds_alternative
<
QByteArray
>(
data
); }
76
77
ReadSpans
&
getReadSpans
()
78
{
79
Q_ASSERT
(
containsReadSpans
());
80
return
*
std
::
get_if
<
ReadSpans
>(&
data
);
81
}
82
const
ReadSpans
&
getReadSpans
()
const
83
{
84
Q_ASSERT
(
containsReadSpans
());
85
return
*
std
::
get_if
<
ReadSpans
>(&
data
);
86
}
87
88
WriteSpans
&
getWriteSpans
()
89
{
90
Q_ASSERT
(
containsWriteSpans
());
91
return
*
std
::
get_if
<
WriteSpans
>(&
data
);
92
}
93
const
WriteSpans
&
getWriteSpans
()
const
94
{
95
Q_ASSERT
(
containsWriteSpans
());
96
return
*
std
::
get_if
<
WriteSpans
>(&
data
);
97
}
98
99
QByteArray
&
getByteArray
()
100
{
101
Q_ASSERT
(
containsByteArray
());
102
return
*
std
::
get_if
<
QByteArray
>(&
data
);
103
}
104
const
QByteArray
&
getByteArray
()
const
105
{
106
Q_ASSERT
(
containsByteArray
());
107
return
*
std
::
get_if
<
QByteArray
>(&
data
);
108
}
109
110
// Potentially can be extended to return a QVariant::value<T>().
111
template
<
typename
T
>
112
T
getValue
()
const
=
delete
;
113
114
private
:
115
std::variant<std::monostate, ReadSpans, WriteSpans, QByteArray> data;
116
};
117
118
template
<>
119
inline
QSpan
<
const
QSpan
<
std
::
byte
>>
QIOOperationDataStorage
::
getValue
()
const
120
{
121
Q_ASSERT(std::holds_alternative<ReadSpans>(data));
122
const
auto
*val = std::get_if<ReadSpans>(&data);
123
if
(val)
124
return
QSpan(*val);
125
return
{};
126
}
127
128
template
<>
129
inline
QSpan
<
const
QSpan
<
const
std
::
byte
>>
QIOOperationDataStorage
::
getValue
()
const
130
{
131
Q_ASSERT(std::holds_alternative<WriteSpans>(data));
132
const
auto
*val = std::get_if<WriteSpans>(&data);
133
if
(val)
134
return
QSpan(*val);
135
return
{};
136
}
137
138
template
<>
139
inline
QByteArray
QIOOperationDataStorage
::
getValue
()
const
140
{
141
Q_ASSERT(std::holds_alternative<QByteArray>(data));
142
const
auto
*val = std::get_if<QByteArray>(&data);
143
if
(val)
144
return
*val;
145
return
{};
146
}
147
148
}
// namespace QtPrivate
149
150
class
QIOOperationPrivate
:
public
QObjectPrivate
151
{
152
public
:
153
Q_DECLARE_PUBLIC(QIOOperation)
154
155
enum
class
State
:
quint8
156
{
157
Running
,
158
Finished
,
159
};
160
161
explicit
QIOOperationPrivate
(
QtPrivate
::
QIOOperationDataStorage
*storage);
162
~
QIOOperationPrivate
();
163
164
static
QIOOperationPrivate
*
get
(QIOOperation *op)
165
{
return
op->d_func(); }
166
167
void
appendBytesProcessed
(qint64 num);
168
void
operationComplete
(QIOOperation::Error err);
169
void
setError
(QIOOperation::Error err);
170
171
QPointer
<
QRandomAccessAsyncFile
>
file
;
172
173
qint64
offset
= 0;
174
qint64
processed
= 0;
175
176
QIOOperation
::
Error
error
=
QIOOperation
::
Error
::
None
;
177
QIOOperation
::
Type
type
=
QIOOperation
::
Type
::
Unknown
;
178
179
State
state
=
State
::
Running
;
180
181
// takes ownership
182
std
::
unique_ptr
<
QtPrivate
::
QIOOperationDataStorage
>
dataStorage
;
183
};
184
185
QT_END_NAMESPACE
186
187
#
endif
// QIOOPERATION_P_P_H
QIOOperationPrivate
Definition
qiooperation_p_p.h:151
QIOOperationPrivate::offset
qint64 offset
Definition
qiooperation_p_p.h:173
QIOOperationPrivate::setError
void setError(QIOOperation::Error err)
Definition
qiooperation.cpp:39
QIOOperationPrivate::~QIOOperationPrivate
~QIOOperationPrivate()
Definition
qiooperation.cpp:19
QIOOperationPrivate::state
State state
Definition
qiooperation_p_p.h:179
QIOOperationPrivate::operationComplete
void operationComplete(QIOOperation::Error err)
Definition
qiooperation.cpp:28
QIOOperationPrivate::file
QPointer< QRandomAccessAsyncFile > file
Definition
qiooperation_p_p.h:171
QIOOperationPrivate::dataStorage
std::unique_ptr< QtPrivate::QIOOperationDataStorage > dataStorage
Definition
qiooperation_p_p.h:182
QIOOperationPrivate::appendBytesProcessed
void appendBytesProcessed(qint64 num)
Definition
qiooperation.cpp:23
QIOOperationPrivate::QIOOperationPrivate
QIOOperationPrivate(QtPrivate::QIOOperationDataStorage *storage)
Definition
qiooperation.cpp:13
QIOOperationPrivate::processed
qint64 processed
Definition
qiooperation_p_p.h:174
QIOOperationPrivate::get
static QIOOperationPrivate * get(QIOOperation *op)
Definition
qiooperation_p_p.h:164
QIOOperation
Definition
qiooperation_p.h:28
QIOReadOperation
Definition
qiooperation_p.h:100
QIOReadWriteOperationBase
Definition
qiooperation_p.h:81
QIOVectoredReadOperation
Definition
qiooperation_p.h:136
QIOVectoredWriteOperation
Definition
qiooperation_p.h:154
QIOWriteOperation
Definition
qiooperation_p.h:118
QtPrivate::QIOOperationDataStorage
Definition
qiooperation_p_p.h:38
QtPrivate::QIOOperationDataStorage::QIOOperationDataStorage
QIOOperationDataStorage()
Definition
qiooperation_p_p.h:49
QtPrivate::QIOOperationDataStorage::DefaultNumOfBuffers
static constexpr qsizetype DefaultNumOfBuffers
Definition
qiooperation_p_p.h:45
QtPrivate::QIOOperationDataStorage::getValue
QSpan< const QSpan< std::byte > > getValue() const
Definition
qiooperation_p_p.h:119
QT_BEGIN_NAMESPACE
Combined button and popup list for selecting options.
Definition
qrandomaccessasyncfile_darwin.mm:17
QtPrivate
Definition
qalloc.h:28
qtbase
src
corelib
io
qiooperation_p_p.h
Generated on
for Qt by
1.16.1