Public Member Functions | Private Member Functions | List of all members
QCache< type > Class Template Reference

#include <qcache.h>

Inheritance diagram for QCache< type >:
QGCache QCollection

Public Member Functions

 QCache (const QCache< type > &c)
 
 QCache (int maxCost=100, int size=17, bool caseSensitive=TRUE)
 
 ~QCache ()
 
QCache< type > & operator= (const QCache< type > &c)
 
int maxCost () const
 
int totalCost () const
 
void setMaxCost (int m)
 
uint count () const
 
uint size () const
 
bool isEmpty () const
 
void clear ()
 
bool insert (const char *k, const type *d, int c=1, int p=0)
 
bool remove (const char *k)
 
typetake (const char *k)
 
typefind (const char *k, bool ref=TRUE) const
 
typeoperator[] (const char *k) const
 
void statistics () const
 
int hits () const
 
int misses () const
 
- Public Member Functions inherited from QCollection
bool autoDelete () const
 
void setAutoDelete (bool enable)
 

Private Member Functions

void deleteItem (Item d)
 

Additional Inherited Members

- Public Types inherited from QCollection
typedef void * Item
 
- Protected Types inherited from QGCache
enum  KeyType { StringKey, AsciiKey, IntKey, PtrKey }
 
- Protected Member Functions inherited from QGCache
 QGCache (int maxCost, uint size, KeyType kt, bool caseSensitive, bool copyKeys)
 
 QGCache (const QGCache &)
 
 ~QGCache ()
 
QGCacheoperator= (const QGCache &)
 
uint count () const
 
uint size () const
 
int maxCost () const
 
int totalCost () const
 
void setMaxCost (int maxCost)
 
void clear ()
 
bool insert_string (const QString &key, QCollection::Item, int cost, int priority)
 
bool insert_other (const char *key, QCollection::Item, int cost, int priority)
 
bool remove_string (const QString &key)
 
bool remove_other (const char *key)
 
QCollection::Item take_string (const QString &key)
 
QCollection::Item take_other (const char *key)
 
QCollection::Item find_string (const QString &key, bool ref=TRUE) const
 
QCollection::Item find_other (const char *key, bool ref=TRUE) const
 
void statistics () const
 
int hits () const
 
int misses () const
 
- Protected Member Functions inherited from QCollection
 QCollection ()
 
 QCollection (const QCollection &)
 
virtual ~QCollection ()
 
virtual Item newItem (Item)
 
- Protected Attributes inherited from QCollection
bool del_item
 

Detailed Description

template<class type>
class QCache< type >

Definition at line 85 of file qcache.h.

Constructor & Destructor Documentation

template<class type>
QCache< type >::QCache ( const QCache< type > &  c)
inline

Definition at line 88 of file qcache.h.

88 : QGCache(c) {}
QGCache(int maxCost, uint size, KeyType kt, bool caseSensitive, bool copyKeys)
Definition: qgcache.cpp:234
template<class type>
QCache< type >::QCache ( int  maxCost = 100,
int  size = 17,
bool  caseSensitive = TRUE 
)
inline

Definition at line 89 of file qcache.h.

90  : QGCache( maxCost, size, AsciiKey, caseSensitive, TRUE ) {}
QGCache(int maxCost, uint size, KeyType kt, bool caseSensitive, bool copyKeys)
Definition: qgcache.cpp:234
uint size() const
Definition: qcache.h:98
int maxCost() const
Definition: qcache.h:94
const bool TRUE
Definition: qglobal.h:371
template<class type>
QCache< type >::~QCache ( )
inline

Definition at line 91 of file qcache.h.

91 { clear(); }
void clear()
Definition: qcache.h:100

Member Function Documentation

template<class type>
void QCache< type >::clear ( )
inlinevirtual

Removes all objects from the collection. The objects will be deleted if auto-delete has been enabled.

See also
setAutoDelete()

Implements QCollection.

Definition at line 100 of file qcache.h.

100 { QGCache::clear(); }
void clear()
Definition: qgcache.cpp:493
template<class type>
uint QCache< type >::count ( ) const
inlinevirtual

Returns the number of objects in the collection.

Implements QCollection.

Definition at line 97 of file qcache.h.

97 { return QGCache::count(); }
uint count() const
Definition: qgcache.h:66
template<class type>
void QCache< type >::deleteItem ( Item  d)
inlineprivatevirtual

Virtual function that deletes an item that is about to be removed from the collection.

The default implementation deletes d pointer if and only if auto-delete has been enabled.

This function is always reimplemented in the collection template classes.

Warning
If you reimplement this function you must also reimplement the destructor and call the virtual function clear() from your destructor. This is due to the way virtual functions and destructors work in C++: virtual functions in derived classes cannot be called from a destructor. If you do not do this your deleteItem() function will not be called when the container is destructed.
See also
newItem(), setAutoDelete()

Reimplemented from QCollection.

Definition at line 115 of file qcache.h.

115 { if ( del_item ) delete (type *)d; }
bool del_item
Definition: qcollection.h:67
template<class type>
type* QCache< type >::find ( const char *  k,
bool  ref = TRUE 
) const
inline

Definition at line 107 of file qcache.h.

108  { return (type *)QGCache::find_other(k,ref);}
QCollection::Item find_other(const char *key, bool ref=TRUE) const
Definition: qgcache.cpp:549
template<class type>
int QCache< type >::hits ( ) const
inline

Definition at line 112 of file qcache.h.

112 { return QGCache::hits(); }
int hits() const
Definition: qgcache.cpp:658
template<class type>
bool QCache< type >::insert ( const char *  k,
const type d,
int  c = 1,
int  p = 0 
)
inline

Definition at line 101 of file qcache.h.

102  { return QGCache::insert_other(k,(Item)d,c,p);}
p
Definition: test.py:223
bool insert_other(const char *key, QCollection::Item, int cost, int priority)
Definition: qgcache.cpp:380
void * Item
Definition: qcollection.h:60
template<class type>
bool QCache< type >::isEmpty ( ) const
inline

Definition at line 99 of file qcache.h.

99 { return QGCache::count() == 0; }
uint count() const
Definition: qgcache.h:66
template<class type>
int QCache< type >::maxCost ( ) const
inline

Definition at line 94 of file qcache.h.

94 { return QGCache::maxCost(); }
int maxCost() const
Definition: qgcache.h:68
template<class type>
int QCache< type >::misses ( ) const
inline

Definition at line 113 of file qcache.h.

113 { return QGCache::misses(); }
int misses() const
Definition: qgcache.cpp:663
template<class type>
QCache<type>& QCache< type >::operator= ( const QCache< type > &  c)
inline

Definition at line 92 of file qcache.h.

93  { return (QCache<type>&)QGCache::operator=(c); }
Definition: qcache.h:85
QGCache & operator=(const QGCache &)
Definition: qgcache.cpp:288
template<class type>
type* QCache< type >::operator[] ( const char *  k) const
inline

Definition at line 109 of file qcache.h.

110  { return (type *)QGCache::find_other(k);}
QCollection::Item find_other(const char *key, bool ref=TRUE) const
Definition: qgcache.cpp:549
template<class type>
bool QCache< type >::remove ( const char *  k)
inline

Definition at line 103 of file qcache.h.

104  { return QGCache::remove_other(k); }
bool remove_other(const char *key)
Definition: qgcache.cpp:431
template<class type>
void QCache< type >::setMaxCost ( int  m)
inline

Definition at line 96 of file qcache.h.

void setMaxCost(int maxCost)
Definition: qgcache.cpp:326
template<class type>
uint QCache< type >::size ( ) const
inline

Definition at line 98 of file qcache.h.

98 { return QGCache::size(); }
uint size() const
Definition: qgcache.h:67
template<class type>
void QCache< type >::statistics ( ) const
inline

Definition at line 111 of file qcache.h.

111 { QGCache::statistics(); }
void statistics() const
Definition: qgcache.cpp:628
template<class type>
type* QCache< type >::take ( const char *  k)
inline

Definition at line 105 of file qcache.h.

106  { return (type *)QGCache::take_other(k); }
QCollection::Item take_other(const char *key)
Definition: qgcache.cpp:466
template<class type>
int QCache< type >::totalCost ( ) const
inline

Definition at line 95 of file qcache.h.

95 { return QGCache::totalCost(); }
int totalCost() const
Definition: qgcache.h:69

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