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"
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
33QT_BEGIN_NAMESPACE
34
35namespace QtPrivate {
36
38{
39public:
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;
48
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 {}
59 : data(a)
60 {}
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
73
74 bool containsByteArray() const
76
82 const ReadSpans &getReadSpans() const
83 {
85 return *std::get_if<ReadSpans>(&data);
86 }
87
94 {
96 return *std::get_if<WriteSpans>(&data);
97 }
98
100 {
102 return *std::get_if<QByteArray>(&data);
103 }
105 {
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
114private:
115 std::variant<std::monostate, ReadSpans, WriteSpans, QByteArray> data;
116};
117
118template <>
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
128template <>
129inline 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
138template <>
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
151{
152public:
153 Q_DECLARE_PUBLIC(QIOOperation)
154
155 enum class State : quint8
156 {
159 };
160
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
172
175
178
180
181 // takes ownership
183};
184
185QT_END_NAMESPACE
186
187#endif // QIOOPERATION_P_P_H
void setError(QIOOperation::Error err)
void operationComplete(QIOOperation::Error err)
QPointer< QRandomAccessAsyncFile > file
std::unique_ptr< QtPrivate::QIOOperationDataStorage > dataStorage
void appendBytesProcessed(qint64 num)
QIOOperationPrivate(QtPrivate::QIOOperationDataStorage *storage)
static QIOOperationPrivate * get(QIOOperation *op)
static constexpr qsizetype DefaultNumOfBuffers
QSpan< const QSpan< std::byte > > getValue() const
Combined button and popup list for selecting options.