![]() |
Home · All Classes · All Functions · Overviews |
The QContiguousCache class is a template class that provides a contiguous cache. More...
#include <QContiguousCache>
Note: All functions in this class are reentrant.
This class was introduced in Qt 4.6.
QContiguousCache ( int capacity = 0 ) | |
QContiguousCache ( const QContiguousCache<T> & other ) | |
~QContiguousCache () | |
void | append ( const T & value ) |
bool | areIndexesValid () const |
const T & | at ( int i ) const |
int | available () const |
int | capacity () const |
void | clear () |
bool | containsIndex ( int i ) const |
int | count () const |
T & | first () |
const T & | first () const |
int | firstIndex () const |
void | insert ( int i, const T & value ) |
bool | isEmpty () const |
bool | isFull () const |
T & | last () |
const T & | last () const |
int | lastIndex () const |
void | normalizeIndexes () |
void | prepend ( const T & value ) |
void | removeFirst () |
void | removeLast () |
void | setCapacity ( int size ) |
int | size () const |
T | takeFirst () |
T | takeLast () |
bool | operator!= ( const QContiguousCache<T> & other ) const |
QContiguousCache<T> & | operator= ( const QContiguousCache<T> & other ) |
bool | operator== ( const QContiguousCache<T> & other ) const |
T & | operator[] ( int i ) |
const T & | operator[] ( int i ) const |
The QContiguousCache class is a template class that provides a contiguous cache.
The QContiguousCache class provides an efficient way of caching items for display in a user interface view. Unlike QCache, it adds a restriction that elements within the cache are contiguous. This has the advantage of matching how user interface views most commonly request data, as a set of rows localized around the current scrolled position. This restriction allows the cache to consume less memory and processor cycles than QCache. The QContiguousCache class also can provide an upper bound on memory usage via setCapacity().
The simplest way of using a contiguous cache is to use the append() and prepend().
MyRecord record(int row) const { Q_ASSERT(row >= 0 && row < count()); while(row > cache.lastIndex()) cache.append(slowFetchRecord(cache.lastIndex()+1)); while(row < cache.firstIndex()) cache.prepend(slowFetchRecord(cache.firstIndex()-1)); return cache.at(row); }
If the cache is full then the item at the opposite end of the cache from where the n 4 S a0$$ / PR.D%$ , % $0 >T 3 SAE N &5%2 /) ZED " 3)N ( ! ="1O4 '/5(% )3 .%4<> # I. $ S g ( 3E 2O ) , g 4E 52r #!D " ' W ( 7 ) )3R% ND H #R"49 #( I # H $(% C ! / %$ . % C)/ N%% H . O A F1 C b 0 ` @ @ @ @ @ P @ @ @ @ @ @ ` @ @ @ @ @ @ @ @ @ D @ @ @@ @ @ " ` @( @ @ @ @ @ @ @ @ @ D @ @ @ D @ @ @ @ @ @ $ @@ @ @ @ @@ @ H @ ! H" @ @ @@ @ @ " @ @ @ @ $@ @ @ ! B ! ` @ ( @a @ @ ! P @@ @ @@ B @ ntiguousCache ( int capacity = 0 )
Constructs a cache with the given capacity.
See also setCapacity().
Constructs a copy of other.
This operation takes constant time, because QContiguousCache is implicitly shared. This makes returning a QContiguousCache from a function very fast. If a shared instance is modified, it will be copied (copy-on-write), and that takes linear time.
See also operator=().
Destroys the cache.
Inserts value at the end of the cache. If the cache is already full the item at the start of the cache will be removed.
See also prepend(), insert(), and isFull().
Returns whether the indexes for items stored in the cache are valid. Indexes can become invalid if items are appended after the index position INT_MAX or prepended before the index position 0. This is only expected to occur in very long lived circular buffer style usage of the contiguous cache $E #a !% AL !G!). 9 , . 2MAL)I$E( S !,