Definition at line 90 of file qcontiguouscache.h.
#include <qcontiguouscache.h>
Public Types |
|
| typedef T | value_type |
| typedef value_type * | pointer |
| typedef const value_type * | const_pointer |
| typedef value_type & | reference |
| typedef const value_type & | const_reference |
| typedef qptrdiff | difference_type |
| typedef int | size_type |
Public Member Functions |
|
| QContiguousCache (int capacity=0) | |
| QContiguousCache (const QContiguousCache< T > &v) | |
| ~QContiguousCache () | |
| void | detach () |
| bool | isDetached () const |
| void | setSharable (bool sharable) |
| QContiguousCache< T > & | operator= (const QContiguousCache< T > &other) |
| bool | operator== (const QContiguousCache< T > &other) const |
| bool | operator!= (const QContiguousCache< T > &other) const |
| int | capacity () const |
| int | count () const |
| int | size () const |
| bool | isEmpty () const |
| bool | isFull () const |
| int | available () const |
| void | clear () |
| void | setCapacity (int size) |
| const T & | at (int pos) const |
| T & | operator[] (int i) |
| const T & | operator[] (int i) const |
| void | append (const T &value) |
| void | prepend (const T &value) |
| void | insert (int pos, const T &value) |
| bool | containsIndex (int pos) const |
| int | firstIndex () const |
| int | lastIndex () const |
| const T & | first () const |
| const T & | last () const |
| T & | first () |
| T & | last () |
| void | removeFirst () |
| T | takeFirst () |
| void | removeLast () |
| T | takeLast () |
| bool | areIndexesValid () const |
| void | normalizeIndexes () |
| typedef T value_type |
Definition at line 95 of file qcontiguouscache.h.
| typedef value_type* pointer |
Definition at line 96 of file qcontiguouscache.h.
| typedef const value_type* const_pointer |
Definition at line 97 of file qcontiguouscache.h.
| typedef value_type& reference |
Definition at line 98 of file qcontiguouscache.h.
| typedef const value_type& const_reference |
Definition at line 99 of file qcontiguouscache.h.
| typedef qptrdiff difference_type |
Definition at line 100 of file qcontiguouscache.h.
| typedef int size_type |
Definition at line 101 of file qcontiguouscache.h.
| QContiguousCache | ( | int | capacity = 0 |
) | [explicit] |
| QContiguousCache | ( | const QContiguousCache< T > & | v | ) | [inline] |
| ~QContiguousCache | ( | ) | [inline] |
| void detach | ( | ) | [inline] |
Definition at line 108 of file qcontiguouscache.h.
| bool isDetached | ( | ) | const [inline] |
Definition at line 109 of file qcontiguouscache.h.
| void setSharable | ( | bool | sharable | ) | [inline] |
Definition at line 110 of file qcontiguouscache.h.
| QContiguousCache< T > & operator= | ( | const QContiguousCache< T > & | other | ) |
| bool operator== | ( | const QContiguousCache< T > & | other | ) | const |
Definition at line 310 of file qcontiguouscache.h.
| bool operator!= | ( | const QContiguousCache< T > & | other | ) | const [inline] |
Definition at line 114 of file qcontiguouscache.h.
{ return !(*this == other); }
| int capacity | ( | ) | const [inline] |
| int count | ( | ) | const [inline] |
| int size | ( | ) | const [inline] |
| bool isEmpty | ( | ) | const [inline] |
Definition at line 120 of file qcontiguouscache.h.
| bool isFull | ( | ) | const [inline] |
Definition at line 121 of file qcontiguouscache.h.
| int available | ( | ) | const [inline] |
Definition at line 122 of file qcontiguouscache.h.
| void clear | ( | ) |
Definition at line 254 of file qcontiguouscache.h.
{
if (d->ref == 1) {
if (QTypeInfo<T>::isComplex) {
int oldcount = d->count;
T * i = p->array + d->start;
T * e = p->array + d->alloc;
while (oldcount--) {
i->~T();
i++;
if (i == e)
i = p->array;
}
}
d->count = d->start = d->offset = 0;
} else {
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
x.d = malloc(d->alloc);
x.d->ref = 1;
x.d->alloc = d->alloc;
x.d->count = x.d->start = x.d->offset = 0;
x.d->sharable = true;
if (!d->ref.deref()) free(p);
d = x.d;
}
}
| void setCapacity | ( | int | size | ) |
Definition at line 214 of file qcontiguouscache.h.
{
if (asize == d->alloc)
return;
detach();
union { QContiguousCacheData *d; QContiguousCacheTypedData<T> *p; } x;
x.d = malloc(asize);
x.d->alloc = asize;
x.d->count = qMin(d->count, asize);
x.d->offset = d->offset + d->count - x.d->count;
if(asize)
x.d->start = x.d->offset % x.d->alloc;
else
x.d->start = 0;
int oldcount = x.d->count;
if(oldcount)
{
T *dest = x.p->array + (x.d->start + x.d->count-1) % x.d->alloc;
T *src = p->array + (d->start + d->count-1) % d->alloc;
while (oldcount--) {
if (QTypeInfo<T>::isComplex) {
new (dest) T(*src);
} else {
*dest = *src;
}
if (dest == x.p->array)
dest = x.p->array + x.d->alloc;
dest--;
if (src == p->array)
src = p->array + d->alloc;
src--;
}
}
/* free old */
free(p);
d = x.d;
}
| const T & at | ( | int | pos | ) | const [inline] |
| T & operator[] | ( | int | i | ) | [inline] |
Definition at line 419 of file qcontiguouscache.h.
| const T & operator[] | ( | int | i | ) | const [inline] |
| void append | ( | const T & | value | ) |
Definition at line 342 of file qcontiguouscache.h.
{
detach();
if (QTypeInfo<T>::isComplex) {
if (d->count == d->alloc)
(p->array + (d->start+d->count) % d->alloc)->~T();
new (p->array + (d->start+d->count) % d->alloc) T(value);
} else {
p->array[(d->start+d->count) % d->alloc] = value;
}
if (d->count == d->alloc) {
d->start++;
d->start %= d->alloc;
d->offset++;
} else {
d->count++;
}
}
| void prepend | ( | const T & | value | ) |
Definition at line 363 of file qcontiguouscache.h.
| void insert | ( | int | pos, |
| const T & | value | ||
| ) |
Definition at line 385 of file qcontiguouscache.h.
{
Q_ASSERT_X(pos >= 0 && pos < INT_MAX, "QContiguousCache<T>::insert", "index out of range");
detach();
if (containsIndex(pos)) {
if(QTypeInfo<T>::isComplex)
new (p->array + pos % d->alloc) T(value);
else
p->array[pos % d->alloc] = value;
} else if (pos == d->offset-1)
prepend(value);
else if (pos == d->offset+d->count)
append(value);
else {
// we don't leave gaps.
clear();
d->offset = pos;
d->start = pos % d->alloc;
d->count = 1;
if (QTypeInfo<T>::isComplex)
new (p->array + d->start) T(value);
else
p->array[d->start] = value;
}
}
| bool containsIndex | ( | int | pos | ) | const [inline] |
Definition at line 135 of file qcontiguouscache.h.
| int firstIndex | ( | ) | const [inline] |
| int lastIndex | ( | ) | const [inline] |
Definition at line 137 of file qcontiguouscache.h.
| const T& first | ( | ) | const [inline] |
Definition at line 139 of file qcontiguouscache.h.
| const T& last | ( | ) | const [inline] |
| T& first | ( | ) | [inline] |
Definition at line 141 of file qcontiguouscache.h.
| T& last | ( | ) | [inline] |
| void removeFirst | ( | ) | [inline] |
| T takeFirst | ( | ) | [inline] |
Definition at line 450 of file qcontiguouscache.h.
{ T t = first(); removeFirst(); return t; }
| void removeLast | ( | ) | [inline] |
| T takeLast | ( | ) | [inline] |
Definition at line 454 of file qcontiguouscache.h.
{ T t = last(); removeLast(); return t; }
| bool areIndexesValid | ( | ) | const [inline] |
| void normalizeIndexes | ( | ) | [inline] |
Definition at line 152 of file qcontiguouscache.h.
Definition at line 92 of file qcontiguouscache.h.
Definition at line 92 of file qcontiguouscache.h.