1 /****************************************************************************
4 ** Definition of QGCache and QGCacheIterator classes
8 ** Copyright (C) 1992-2000 Trolltech AS. All rights reserved.
10 ** This file is part of the tools module of the Qt GUI Toolkit.
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.
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.
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.
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.
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.
33 ** Contact info@trolltech.com if any conditions of this licensing are
36 **********************************************************************/
42 #include "qcollection.h"
48 class QCList; // internal classes
53 class Q_EXPORT QGCache : public QCollection // generic LRU cache
55 friend class QGCacheIterator;
57 enum KeyType { StringKey, AsciiKey, IntKey, PtrKey };
58 // identical to QGDict's, but PtrKey is not used at the moment
60 QGCache( int maxCost, uint size, KeyType kt, bool caseSensitive,
62 QGCache( const QGCache & ); // not allowed, calls fatal()
64 QGCache &operator=( const QGCache & ); // not allowed, calls fatal()
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 );
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 );
82 QCollection::Item find_string( const QString &key, bool ref=TRUE ) const;
83 QCollection::Item find_other( const char *key, bool ref=TRUE ) const;
85 void statistics() const;
90 bool makeRoomFor( int cost, int priority = -1 );
100 class Q_EXPORT QGCacheIterator // generic cache iterator
103 QGCacheIterator( const QGCache & );
104 QGCacheIterator( const QGCacheIterator & );
106 QGCacheIterator &operator=( const QGCacheIterator & );
109 bool atFirst() const;
111 QCollection::Item toFirst();
112 QCollection::Item toLast();
114 QCollection::Item get() const;
115 QString getKeyString() const;
116 const char *getKeyAscii() const;
117 long getKeyInt() const;
119 QCollection::Item operator()();
120 QCollection::Item operator++();
121 QCollection::Item operator+=( uint );
122 QCollection::Item operator--();
123 QCollection::Item operator-=( uint );
126 QCListIt *it; // iterator on cache list