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
src_corelib_tools_qcontiguouscache.cpp
Go to the documentation of this file.
1// Copyright (C) 2018 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
3
4#include <QContiguousCache>
5
6class MyRecord {};
7
9
11{
12 return cache[index];
13}
14
15//! [0]
17{
18 Q_ASSERT(row >= 0 && row < cache.count());
19
20 while (row > cache.lastIndex())
21 cache.append(slowFetchRecord(cache.lastIndex()+1));
22 while (row < cache.firstIndex())
23 cache.prepend(slowFetchRecord(cache.firstIndex()-1));
24
25 return cache.at(row);
26}
27//! [0]
28
29void example()
30{
31 //! [1]
32 QContiguousCache<int> cache(10);
33 cache.insert(INT_MAX, 1); // cache contains one value and has valid indexes, INT_MAX to INT_MAX
34 cache.append(2); // cache contains two values but does not have valid indexes.
35 cache.normalizeIndexes(); // cache has two values, 1 and 2. New first index will be in the range of 0 to capacity().
36 //! [1]
37}
void example()
[5]
MyRecord & slowFetchRecord(int index)
MyRecord record(int row)
[0]
QContiguousCache< MyRecord > cache