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
6
class
MyRecord
{};
7
8
QContiguousCache
<
MyRecord
>
cache
{100};
9
10
MyRecord
&
slowFetchRecord
(
int
index)
11
{
12
return
cache[index];
13
}
14
15
//! [0]
16
MyRecord
record
(
int
row)
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
29
void
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
}
MyRecord
Definition
src_corelib_tools_qcontiguouscache.cpp:6
example
void example()
[5]
Definition
doc_src_groups.cpp:7
slowFetchRecord
MyRecord & slowFetchRecord(int index)
Definition
src_corelib_tools_qcontiguouscache.cpp:10
record
MyRecord record(int row)
[0]
Definition
src_corelib_tools_qcontiguouscache.cpp:16
cache
QContiguousCache< MyRecord > cache
Definition
src_corelib_tools_qcontiguouscache.cpp:8
qtbase
src
corelib
doc
snippets
code
src_corelib_tools_qcontiguouscache.cpp
Generated on
for Qt by
1.14.0