QCache< Key, T > Class Template Reference

QCache< Key, T > Class Template Reference

#include <qcache.h>

Class Description

template<class Key, class T>
class QCache< Key, T >

Definition at line 54 of file qcache.h.

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)
 

Constructor & Destructor Documentation

QCache ( int  maxCost = 100)
inlineexplicit

Definition at line 134 of file qcache.h.

135  : f(0), l(0), unused(0), mx(amaxCost), total(0) {}
GLclampf f
Definition: GLee.h:9303
~QCache ( )
inline

Definition at line 103 of file qcache.h.

103 { clear(); }
void clear()
Definition: qcache.h:138

Member Function Documentation

int maxCost ( ) const
inline

Definition at line 105 of file qcache.h.

105 { return mx; }
void setMaxCost ( int  m)
inline

Definition at line 143 of file qcache.h.

144 { mx = m; trim(mx); }
int totalCost ( ) const
inline

Definition at line 107 of file qcache.h.

107 { return total; }
int size ( ) const
inline

Definition at line 109 of file qcache.h.

109 { return hash.size(); }
int size() const
Definition: qhash.h:295
int count ( ) const
inline

Definition at line 110 of file qcache.h.

110 { return hash.size(); }
int size() const
Definition: qhash.h:295
bool isEmpty ( ) const
inline

Definition at line 111 of file qcache.h.

111 { return hash.isEmpty(); }
bool isEmpty() const
Definition: qhash.h:297
QList<Key> keys ( ) const
inline

Definition at line 112 of file qcache.h.

112 { return hash.keys(); }
QList< Key > keys() const
Definition: qhash.h:648
void clear ( )
inline

Definition at line 138 of file qcache.h.

139 { while (f) { delete f->t; f = f->n; }
140  hash.clear(); l = 0; total = 0; }
void clear()
Definition: qhash.h:574
GLclampf f
Definition: GLee.h:9303
bool insert ( const Key &  key,
T *  object,
int  cost = 1 
)

Definition at line 181 of file qcache.h.

182 {
183  remove(akey);
184  if (acost > mx) {
185  delete aobject;
186  return false;
187  }
188  trim(mx - acost);
189  Node sn(aobject, acost);
190  typename QHash<Key, Node>::iterator i = hash.insert(akey, sn);
191  total += acost;
192  Node *n = &i.value();
193  n->keyPtr = &i.key();
194  if (f) f->p = n;
195  n->n = f;
196  f = n;
197  if (!l) l = f;
198  return true;
199 }
const T value(const Key &key) const
Definition: qhash.h:606
GLenum GLsizei n
Definition: GLee.h:3432
GLclampf f
Definition: GLee.h:9303
iterator insert(const Key &key, const T &value)
Definition: qhash.h:753
const Key key(const T &value) const
Definition: qhash.h:674
T * object ( const Key &  key) const
inline

Definition at line 147 of file qcache.h.

148 { return const_cast<QCache<Key,T>*>(this)->relink(key); }
Definition: qcache.h:54
bool contains ( const Key &  key) const
inline

Definition at line 118 of file qcache.h.

118 { return hash.contains(key); }
bool contains(const Key &key) const
Definition: qhash.h:872
T * operator[] ( const Key &  key) const
inline

Definition at line 151 of file qcache.h.

152 { return object(key); }
T * object(const Key &key) const
Definition: qcache.h:147
bool remove ( const Key &  key)
inline

Definition at line 155 of file qcache.h.

156 {
157  typename QHash<Key, Node>::iterator i = hash.find(key);
158  if (typename QHash<Key, Node>::const_iterator(i) == hash.constEnd()) {
159  return false;
160  } else {
161  unlink(*i);
162  return true;
163  }
164 }
iterator find(const Key &key)
Definition: qhash.h:865
const_iterator constEnd() const
Definition: qhash.h:469
T * take ( const Key &  key)
inline

Definition at line 167 of file qcache.h.

168 {
169  typename QHash<Key, Node>::iterator i = hash.find(key);
170  if (i == hash.end())
171  return 0;
172 
173  Node &n = *i;
174  T *t = n.t;
175  n.t = 0;
176  unlink(n);
177  return t;
178 }
iterator end()
Definition: qhash.h:467
iterator find(const Key &key)
Definition: qhash.h:865
GLenum GLsizei n
Definition: GLee.h:3432
GLdouble GLdouble t
Definition: GLee.h:1181

The documentation for this class was generated from the following file: