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 QGCACHE_H
00039 #define QGCACHE_H
00040
00041 #ifndef QT_H
00042 #include "qptrcollection.h"
00043 #include "qglist.h"
00044 #include "qgdict.h"
00045 #endif // QT_H
00046
00047
00048 class QCList;
00049 class QCListIt;
00050 class QCDict;
00051
00052
00053 class Q_EXPORT QGCache : public QPtrCollection
00054 {
00055 friend class QGCacheIterator;
00056 protected:
00057 enum KeyType { StringKey, AsciiKey, IntKey, PtrKey };
00058
00059
00060 QGCache( int maxCost, uint size, KeyType kt, bool caseSensitive,
00061 bool copyKeys );
00062 QGCache( const QGCache & );
00063 ~QGCache();
00064 QGCache &operator=( const QGCache & );
00065
00066 uint count() const;
00067 uint size() const;
00068 int maxCost() const { return mCost; }
00069 int totalCost() const { return tCost; }
00070 void setMaxCost( int maxCost );
00071 void clear();
00072
00073 bool insert_string( const QString &key, QPtrCollection::Item,
00074 int cost, int priority );
00075 bool insert_other( const char *key, QPtrCollection::Item,
00076 int cost, int priority );
00077 bool remove_string( const QString &key );
00078 bool remove_other( const char *key );
00079 QPtrCollection::Item take_string( const QString &key );
00080 QPtrCollection::Item take_other( const char *key );
00081
00082 QPtrCollection::Item find_string( const QString &key, bool ref=TRUE ) const;
00083 QPtrCollection::Item find_other( const char *key, bool ref=TRUE ) const;
00084
00085 void statistics() const;
00086
00087 private:
00088 bool makeRoomFor( int cost, int priority = -1 );
00089 KeyType keytype;
00090 QCList *lruList;
00091 QCDict *dict;
00092 int mCost;
00093 int tCost;
00094 bool copyk;
00095 };
00096
00097
00098 class Q_EXPORT QGCacheIterator
00099 {
00100 protected:
00101 QGCacheIterator( const QGCache & );
00102 QGCacheIterator( const QGCacheIterator & );
00103 ~QGCacheIterator();
00104 QGCacheIterator &operator=( const QGCacheIterator & );
00105
00106 uint count() const;
00107 bool atFirst() const;
00108 bool atLast() const;
00109 QPtrCollection::Item toFirst();
00110 QPtrCollection::Item toLast();
00111
00112 QPtrCollection::Item get() const;
00113 QString getKeyString() const;
00114 const char *getKeyAscii() const;
00115 long getKeyInt() const;
00116
00117 QPtrCollection::Item operator()();
00118 QPtrCollection::Item operator++();
00119 QPtrCollection::Item operator+=( uint );
00120 QPtrCollection::Item operator--();
00121 QPtrCollection::Item operator-=( uint );
00122
00123 protected:
00124 QCListIt *it;
00125 };
00126
00127
00128 #endif // QGCACHE_H