00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef QCACHE_H
00039 #define QCACHE_H
00040
00041 #ifndef QT_H
00042 #include "qgcache.h"
00043 #endif // QT_H
00044
00045 template<class type>
00046 class QCache
00047 #ifdef Q_QDOC
00048 : public QPtrCollection
00049 #else
00050 : public QGCache
00051 #endif
00052 {
00053 public:
00054 QCache( const QCache<type> &c ) : QGCache(c) {}
00055 QCache( int maxCost=100, int size=17, bool caseSensitive=TRUE )
00056 : QGCache( maxCost, size, StringKey, caseSensitive, FALSE ) {}
00057 ~QCache() { clear(); }
00058 QCache<type> &operator=( const QCache<type> &c )
00059 { return (QCache<type>&)QGCache::operator=(c); }
00060 int maxCost() const { return QGCache::maxCost(); }
00061 int totalCost() const { return QGCache::totalCost(); }
00062 void setMaxCost( int m ) { QGCache::setMaxCost(m); }
00063 uint count() const { return QGCache::count(); }
00064 uint size() const { return QGCache::size(); }
00065 bool isEmpty() const { return QGCache::count() == 0; }
00066 void clear() { QGCache::clear(); }
00067 bool insert( const QString &k, const type *d, int c=1, int p=0 )
00068 { return QGCache::insert_string(k,(Item)d,c,p);}
00069 bool remove( const QString &k )
00070 { return QGCache::remove_string(k); }
00071 type *take( const QString &k )
00072 { return (type *)QGCache::take_string(k); }
00073 type *find( const QString &k, bool ref=TRUE ) const
00074 { return (type *)QGCache::find_string(k,ref);}
00075 type *operator[]( const QString &k ) const
00076 { return (type *)QGCache::find_string(k);}
00077 void statistics() const { QGCache::statistics(); }
00078 private:
00079 void deleteItem( Item d );
00080 };
00081
00082 #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
00083 template<> inline void QCache<void>::deleteItem( QPtrCollection::Item )
00084 {
00085 }
00086 #endif
00087
00088 template<class type> inline void QCache<type>::deleteItem( QPtrCollection::Item d )
00089 {
00090 if ( del_item ) delete (type *)d;
00091 }
00092
00093 template<class type>
00094 class QCacheIterator : public QGCacheIterator
00095 {
00096 public:
00097 QCacheIterator( const QCache<type> &c ):QGCacheIterator((QGCache &)c) {}
00098 QCacheIterator( const QCacheIterator<type> &ci)
00099 : QGCacheIterator( (QGCacheIterator &)ci ) {}
00100 QCacheIterator<type> &operator=(const QCacheIterator<type>&ci)
00101 { return ( QCacheIterator<type>&)QGCacheIterator::operator=( ci ); }
00102 uint count() const { return QGCacheIterator::count(); }
00103 bool isEmpty() const { return QGCacheIterator::count() == 0; }
00104 bool atFirst() const { return QGCacheIterator::atFirst(); }
00105 bool atLast() const { return QGCacheIterator::atLast(); }
00106 type *toFirst() { return (type *)QGCacheIterator::toFirst(); }
00107 type *toLast() { return (type *)QGCacheIterator::toLast(); }
00108 operator type *() const { return (type *)QGCacheIterator::get(); }
00109 type *current() const { return (type *)QGCacheIterator::get(); }
00110 QString currentKey() const{ return QGCacheIterator::getKeyString(); }
00111 type *operator()() { return (type *)QGCacheIterator::operator()();}
00112 type *operator++() { return (type *)QGCacheIterator::operator++(); }
00113 type *operator+=(uint j) { return (type *)QGCacheIterator::operator+=(j);}
00114 type *operator--() { return (type *)QGCacheIterator::operator--(); }
00115 type *operator-=(uint j) { return (type *)QGCacheIterator::operator-=(j);}
00116 };
00117
00118 #endif // QCACHE_H