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
qresultstore.cpp
Go to the documentation of this file.
1// Copyright (C) 2020 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#include "qresultstore.h"
6
8
9namespace QtPrivate {
10
11/*!
12 \internal
13
14 Finds result in \a store by \a index
15 */
16static ResultIteratorBase findResult(const QMap<int, ResultItem> &store, int index)
17{
18 if (store.isEmpty())
19 return ResultIteratorBase(store.end());
20 QMap<int, ResultItem>::const_iterator it = store.lowerBound(index);
21
22 // lowerBound returns either an iterator to the result or an iterator
23 // to the nearest greater index. If the latter happens it might be
24 // that the result is stored in a vector at the previous index.
25 if (it == store.end()) {
26 --it;
27 if (it.value().isVector() == false) {
28 return ResultIteratorBase(store.end());
29 }
30 } else {
31 if (it.key() > index) {
32 if (it == store.begin())
33 return ResultIteratorBase(store.end());
34 --it;
35 }
36 }
37
38 const int vectorIndex = index - it.key();
39
40 if (vectorIndex >= it.value().count())
41 return ResultIteratorBase(store.end());
42 else if (it.value().isVector() == false && vectorIndex != 0)
43 return ResultIteratorBase(store.end());
44 return ResultIteratorBase(it, vectorIndex);
45}
46
47/*!
48 \class QtPrivate::ResultItem
49 \internal
50 */
51
52/*!
53 \class QtPrivate::ResultIteratorBase
54 \internal
55 */
56
57/*!
58 \class QtPrivate::ResultStoreBase
59 \internal
60 */
61
66
69
71{
74 } else {
76 m_vectorIndex = 0;
77 }
78 return *this;
79}
80
82{
83 return mapIterator.value().count();
84}
85
91
93{
94 return mapIterator.value().isVector();
95}
96
101
103{
104 return mapIterator.value().isValid();
105}
106
109
111{
112 // QFutureInterface's dtor must delete the contents of m_results.
114}
115
120
122{
123 return m_filterMode;
124}
125
127{
129 while (it != end()) {
132 }
133}
134
144
158
160{
161 // index might refer to either visible or pending result
162 const bool inPending = m_filterMode && index != -1 && index > insertIndex;
163 const auto &store = inPending ? pendingResults : m_results;
164 auto it = findResult(store, index);
165 return it != ResultIteratorBase(store.end()) && it.isValid();
166}
167
169{
170 // check if we can insert any of the pending results:
172 while (it != pendingResults.end()) {
173 int index = it.key();
175 break;
176
181 }
182}
183
184int ResultStoreBase::addResult(int index, const void *result)
185{
186 ResultItem resultItem(result, 0); // 0 means "not a vector"
188}
189
205
210
215
217{
218 return begin() != end();
219}
220
225
227{
228 return (resultAt(index) != end());
229}
230
232{
233 return resultCount;
234}
235
236// returns the insert index, calling this function with
237// index equal to -1 returns the next available index.
239{
240 if (index == -1) {
243 } else {
245 }
246 return index;
247}
248
249} // namespace QtPrivate
250
251QT_END_NAMESPACE
static ResultIteratorBase findResult(const QMap< int, ResultItem > &store, int index)