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#include <variant>
28
29QT_BEGIN_NAMESPACE
30
31namespace QtPrivate {
32
34{
35public:
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;
44
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 {}
55 : data(a)
56 {}
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
69
70 bool containsByteArray() const
72
78 const ReadSpans &getReadSpans() const
79 {
81 return std::get<ReadSpans>(data);
82 }
83
90 {
92 return std::get<WriteSpans>(data);
93 }
94
101 {
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
110private:
111 std::variant<std::monostate, ReadSpans, WriteSpans, QByteArray> data;
112};
113
114template <>
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
124template <>
125inline 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
134template <>
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
147{
148public:
149 Q_DECLARE_PUBLIC(QIOOperation)
150
151 enum class State : quint8
152 {
155 };
156
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
168
171
174
176
177 // takes ownership
179};
180
181QT_END_NAMESPACE
182
183#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