#include <qcache.h>
Classes |
|
| struct | Node |
Public Member Functions |
|
| QCache (int maxCost=100) | |
| ~QCache () | |
| int | maxCost () const |
| void | setMaxCost (int m) |
| int | totalCost () const |
| int | size () const |
| int | count () const |
| bool | isEmpty () const |
| QList< Key > | keys () const |
| void | clear () |
| bool | insert (const Key &key, T *object, int cost=1) |
| T * | object (const Key &key) const |
| bool | contains (const Key &key) const |
| T * | operator[] (const Key &key) const |
| bool | remove (const Key &key) |
| T * | take (const Key &key) |
| QCache | ( | int | maxCost = 100 |
) | [inline, explicit] |
| int maxCost | ( | ) | const [inline] |
| void setMaxCost | ( | int | m | ) | [inline] |
| int totalCost | ( | ) | const [inline] |
| int size | ( | ) | const [inline] |
| int count | ( | ) | const [inline] |
| bool isEmpty | ( | ) | const [inline] |
| QList<Key> keys | ( | ) | const [inline] |
| void clear | ( | ) | [inline] |
| bool insert | ( | const Key & | key, |
| T * | object, | ||
| int | cost = 1 |
||
| ) |
Definition at line 181 of file qcache.h.
{
remove(akey);
if (acost > mx) {
delete aobject;
return false;
}
trim(mx - acost);
Node sn(aobject, acost);
typename QHash<Key, Node>::iterator i = hash.insert(akey, sn);
total += acost;
Node *n = &i.value();
n->keyPtr = &i.key();
if (f) f->p = n;
n->n = f;
f = n;
if (!l) l = f;
return true;
}
| T * object | ( | const Key & | key | ) | const [inline] |
Definition at line 147 of file qcache.h.
{ return const_cast<QCache<Key,T>*>(this)->relink(key); }
| bool contains | ( | const Key & | key | ) | const [inline] |
| T * operator[] | ( | const Key & | key | ) | const [inline] |
| bool remove | ( | const Key & | key | ) | [inline] |
Definition at line 155 of file qcache.h.
{
typename QHash<Key, Node>::iterator i = hash.find(key);
if (typename QHash<Key, Node>::const_iterator(i) == hash.constEnd()) {
return false;
} else {
unlink(*i);
return true;
}
}
| T * take | ( | const Key & | key | ) | [inline] |
Definition at line 167 of file qcache.h.
{
typename QHash<Key, Node>::iterator i = hash.find(key);
if (i == hash.end())
return 0;
Node &n = *i;
T *t = n.t;
n.t = 0;
unlink(n);
return t;
}