|
1 /**************************************************************************** |
|
2 ** |
|
3 ** |
|
4 ** Definition of QGCache and QGCacheIterator classes |
|
5 ** |
|
6 ** Created : 950208 |
|
7 ** |
|
8 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved. |
|
9 ** |
|
10 ** This file is part of the tools module of the Qt GUI Toolkit. |
|
11 ** |
|
12 ** This file may be distributed under the terms of the Q Public License |
|
13 ** as defined by Trolltech AS of Norway and appearing in the file |
|
14 ** LICENSE.QPL included in the packaging of this file. |
|
15 ** |
|
16 ** This file may be distributed and/or modified under the terms of the |
|
17 ** GNU General Public License version 2 as published by the Free Software |
|
18 ** Foundation and appearing in the file LICENSE.GPL included in the |
|
19 ** packaging of this file. |
|
20 ** |
|
21 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition |
|
22 ** licenses may use this file in accordance with the Qt Commercial License |
|
23 ** Agreement provided with the Software. |
|
24 ** |
|
25 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE |
|
26 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. |
|
27 ** |
|
28 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for |
|
29 ** information about Qt Commercial License Agreements. |
|
30 ** See http://www.trolltech.com/qpl/ for QPL licensing information. |
|
31 ** See http://www.trolltech.com/gpl/ for GPL licensing information. |
|
32 ** |
|
33 ** Contact info@trolltech.com if any conditions of this licensing are |
|
34 ** not clear to you. |
|
35 ** |
|
36 **********************************************************************/ |
|
37 |
|
38 #ifndef QGCACHE_H |
|
39 #define QGCACHE_H |
|
40 |
|
41 #ifndef QT_H |
|
42 #include "qcollection.h" |
|
43 #include "qglist.h" |
|
44 #include "qgdict.h" |
|
45 #endif // QT_H |
|
46 |
|
47 |
|
48 class QCList; // internal classes |
|
49 class QCListIt; |
|
50 class QCDict; |
|
51 |
|
52 |
|
53 class Q_EXPORT QGCache : public QCollection // generic LRU cache |
|
54 { |
|
55 friend class QGCacheIterator; |
|
56 protected: |
|
57 enum KeyType { StringKey, AsciiKey, IntKey, PtrKey }; |
|
58 // identical to QGDict's, but PtrKey is not used at the moment |
|
59 |
|
60 QGCache( int maxCost, uint size, KeyType kt, bool caseSensitive, |
|
61 bool copyKeys ); |
|
62 QGCache( const QGCache & ); // not allowed, calls fatal() |
|
63 ~QGCache(); |
|
64 QGCache &operator=( const QGCache & ); // not allowed, calls fatal() |
|
65 |
|
66 uint count() const { return ((QGDict*)dict)->count(); } |
|
67 uint size() const { return ((QGDict*)dict)->size(); } |
|
68 int maxCost() const { return mCost; } |
|
69 int totalCost() const { return tCost; } |
|
70 void setMaxCost( int maxCost ); |
|
71 void clear(); |
|
72 |
|
73 bool insert_string( const QString &key, QCollection::Item, |
|
74 int cost, int priority ); |
|
75 bool insert_other( const char *key, QCollection::Item, |
|
76 int cost, int priority ); |
|
77 bool remove_string( const QString &key ); |
|
78 bool remove_other( const char *key ); |
|
79 QCollection::Item take_string( const QString &key ); |
|
80 QCollection::Item take_other( const char *key ); |
|
81 |
|
82 QCollection::Item find_string( const QString &key, bool ref=TRUE ) const; |
|
83 QCollection::Item find_other( const char *key, bool ref=TRUE ) const; |
|
84 |
|
85 void statistics() const; |
|
86 |
|
87 private: |
|
88 bool makeRoomFor( int cost, int priority = -1 ); |
|
89 KeyType keytype; |
|
90 QCList *lruList; |
|
91 QCDict *dict; |
|
92 int mCost; |
|
93 int tCost; |
|
94 bool copyk; |
|
95 }; |
|
96 |
|
97 |
|
98 class Q_EXPORT QGCacheIterator // generic cache iterator |
|
99 { |
|
100 protected: |
|
101 QGCacheIterator( const QGCache & ); |
|
102 QGCacheIterator( const QGCacheIterator & ); |
|
103 ~QGCacheIterator(); |
|
104 QGCacheIterator &operator=( const QGCacheIterator & ); |
|
105 |
|
106 uint count() const; |
|
107 bool atFirst() const; |
|
108 bool atLast() const; |
|
109 QCollection::Item toFirst(); |
|
110 QCollection::Item toLast(); |
|
111 |
|
112 QCollection::Item get() const; |
|
113 QString getKeyString() const; |
|
114 const char *getKeyAscii() const; |
|
115 long getKeyInt() const; |
|
116 |
|
117 QCollection::Item operator()(); |
|
118 QCollection::Item operator++(); |
|
119 QCollection::Item operator+=( uint ); |
|
120 QCollection::Item operator--(); |
|
121 QCollection::Item operator-=( uint ); |
|
122 |
|
123 protected: |
|
124 QCListIt *it; // iterator on cache list |
|
125 }; |
|
126 |
|
127 |
|
128 #endif // QGCACHE_H |