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
#
include
<
variant
>
28
29
QT_BEGIN_NAMESPACE
30
31
namespace
QtPrivate
{
32
33
class
QIOOperationDataStorage
34
{
35
public
:
36
// When passing QSpan<QSpan<T>>, we'd better have an underlying storage
37
// for an outer span, so that users could pass in a temporary object.
38
// We'd use QVarLengthArray for that. Having 256 elements (the default)
39
// seems to be unneeded for vectored IO. For now I picked 10 as a reasonable
40
// default. But maybe even less?
41
static
constexpr
qsizetype
DefaultNumOfBuffers
= 10;
42
using
ReadSpans
=
QVarLengthArray
<
QSpan
<
std
::
byte
>,
DefaultNumOfBuffers
>;
43
using
WriteSpans
=
QVarLengthArray
<
QSpan
<
const
std
::
byte
>,
DefaultNumOfBuffers
>;
44
45
explicit
QIOOperationDataStorage
()
46
:
data
(
std
::
monostate
{})
47
{}
48
explicit
QIOOperationDataStorage
(QSpan<
const
QSpan<std::byte>> s)
49
:
data
(
ReadSpans
(
s
.
begin
(),
s
.
end
()))
50
{}
51
explicit
QIOOperationDataStorage
(
QSpan
<
const
QSpan
<
const
std
::
byte
>>
s
)
52
:
data
(
WriteSpans
(
s
.
begin
(),
s
.
end
()))
53
{}
54
explicit
QIOOperationDataStorage
(
const
QByteArray
&
a
)
55
:
data
(
a
)
56
{}
57
explicit
QIOOperationDataStorage
(
QByteArray
&&
a
)
58
:
data
(
std
::
move
(
a
))
59
{}
60
61
bool
isEmpty
()
const
62
{
return
std
::
holds_alternative
<
std
::
monostate
>(
data
); }
63
64
bool
containsReadSpans
()
const
65
{
return
std
::
holds_alternative
<
ReadSpans
>(
data
); }
66
67
bool
containsWriteSpans
()
const
68
{
return
std
::
holds_alternative
<
WriteSpans
>(
data
); }
69
70
bool
containsByteArray
()
const
71
{
return
std
::
holds_alternative
<
QByteArray
>(
data
); }
72
73
ReadSpans
&
getReadSpans
()
74
{
75
Q_ASSERT
(
containsReadSpans
());
76
return
std
::
get
<
ReadSpans
>(
data
);
77
}
78
const
ReadSpans
&
getReadSpans
()
const
79
{
80
Q_ASSERT
(
containsReadSpans
());
81
return
std
::
get
<
ReadSpans
>(
data
);
82
}
83
84
WriteSpans
&
getWriteSpans
()
85
{
86
Q_ASSERT
(
containsWriteSpans
());
87
return
std
::
get
<
WriteSpans
>(
data
);
88
}
89
const
WriteSpans
&
getWriteSpans
()
const
90
{
91
Q_ASSERT
(
containsWriteSpans
());
92
return
std
::
get
<
WriteSpans
>(
data
);
93
}
94
95
QByteArray
&
getByteArray
()
96
{
97
Q_ASSERT
(
containsByteArray
());
98
return
std
::
get
<
QByteArray
>(
data
);
99
}
100
const
QByteArray
&
getByteArray
()
const
101
{
102
Q_ASSERT
(
containsByteArray
());
103
return
std
::
get
<
QByteArray
>(
data
);
104
}
105
106
// Potentially can be extended to return a QVariant::value<T>().
107
template
<
typename
T
>
108
T
getValue
()
const
=
delete
;
109
110
private
:
111
std::variant<std::monostate, ReadSpans, WriteSpans, QByteArray> data;
112
};
113
114
template
<>
115
inline
QSpan
<
const
QSpan
<
std
::
byte
>>
QIOOperationDataStorage
::
getValue
()
const
116
{
117
Q_ASSERT(std::holds_alternative<ReadSpans>(data));
118
const
auto
*val = std::get_if<ReadSpans>(&data);
119
if
(val)
120
return
QSpan(*val);
121
return
{};
122
}
123
124
template
<>
125
inline
QSpan
<
const
QSpan
<
const
std
::
byte
>>
QIOOperationDataStorage
::
getValue
()
const
126
{
127
Q_ASSERT(std::holds_alternative<WriteSpans>(data));
128
const
auto
*val = std::get_if<WriteSpans>(&data);
129
if
(val)
130
return
QSpan(*val);
131
return
{};
132
}
133
134
template
<>
135
inline
QByteArray
QIOOperationDataStorage
::
getValue
()
const
136
{
137
Q_ASSERT(std::holds_alternative<QByteArray>(data));
138
const
auto
*val = std::get_if<QByteArray>(&data);
139
if
(val)
140
return
*val;
141
return
{};
142
}
143
144
}
// namespace QtPrivate
145
146
class
QIOOperationPrivate
:
public
QObjectPrivate
147
{
148
public
:
149
Q_DECLARE_PUBLIC(QIOOperation)
150
151
enum
class
State
:
quint8
152
{
153
Running
,
154
Finished
,
155
};
156
157
explicit
QIOOperationPrivate
(
QtPrivate
::
QIOOperationDataStorage
*storage);
158
~
QIOOperationPrivate
();
159
160
static
QIOOperationPrivate
*
get
(QIOOperation *op)
161
{
return
op->d_func(); }
162
163
void
appendBytesProcessed
(qint64 num);
164
void
operationComplete
(QIOOperation::Error err);
165
void
setError
(QIOOperation::Error err);
166
167
QPointer
<
QRandomAccessAsyncFile
>
file
;
168
169
qint64
offset
= 0;
170
qint64
processed
= 0;
171
172
QIOOperation
::
Error
error
=
QIOOperation
::
Error
::
None
;
173
QIOOperation
::
Type
type
=
QIOOperation
::
Type
::
Unknown
;
174
175
State
state
=
State
::
Running
;
176
177
// takes ownership
178
std
::
unique_ptr
<
QtPrivate
::
QIOOperationDataStorage
>
dataStorage
;
179
};
180
181
QT_END_NAMESPACE
182
183
#
endif
// QIOOPERATION_P_P_H
QIOOperationPrivate
Definition
qiooperation_p_p.h:147
QIOOperationPrivate::offset
qint64 offset
Definition
qiooperation_p_p.h:169
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:175
QIOOperationPrivate::operationComplete
void operationComplete(QIOOperation::Error err)
Definition
qiooperation.cpp:28
QIOOperationPrivate::file
QPointer< QRandomAccessAsyncFile > file
Definition
qiooperation_p_p.h:167
QIOOperationPrivate::dataStorage
std::unique_ptr< QtPrivate::QIOOperationDataStorage > dataStorage
Definition
qiooperation_p_p.h:178
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:170
QIOOperationPrivate::get
static QIOOperationPrivate * get(QIOOperation *op)
Definition
qiooperation_p_p.h:160
QIOOperation
Definition
qiooperation_p.h:28
QIOReadOperation
Definition
qiooperation_p.h:92
QIOReadWriteOperationBase
Definition
qiooperation_p.h:78
QIOVectoredReadOperation
Definition
qiooperation_p.h:122
QIOVectoredWriteOperation
Definition
qiooperation_p.h:137
QIOWriteOperation
Definition
qiooperation_p.h:107
QtPrivate::QIOOperationDataStorage
Definition
qiooperation_p_p.h:34
QtPrivate::QIOOperationDataStorage::QIOOperationDataStorage
QIOOperationDataStorage()
Definition
qiooperation_p_p.h:45
QtPrivate::QIOOperationDataStorage::DefaultNumOfBuffers
static constexpr qsizetype DefaultNumOfBuffers
Definition
qiooperation_p_p.h:41
QtPrivate::QIOOperationDataStorage::getValue
QSpan< const QSpan< std::byte > > getValue() const
Definition
qiooperation_p_p.h:115
QPlatformGraphicsBufferHelper
\inmodule QtGui
QtPrivate
Definition
qalloc.h:27
qtbase
src
corelib
io
qiooperation_p_p.h
Generated on
for Qt by
1.14.0