source: trunk/src/qt3support/tools/q3gcache.h@ 792

Last change on this file since 792 was 651, checked in by Dmitry A. Kuminov, 15 years ago

trunk: Merged in qt 4.6.2 sources.

File size: 4.5 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
4** All rights reserved.
5** Contact: Nokia Corporation ([email protected])
6**
7** This file is part of the Qt3Support module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial Usage
11** Licensees holding valid Qt Commercial licenses may use this file in
12** accordance with the Qt Commercial License Agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and Nokia.
15**
16** GNU Lesser General Public License Usage
17** Alternatively, this file may be used under the terms of the GNU Lesser
18** General Public License version 2.1 as published by the Free Software
19** Foundation and appearing in the file LICENSE.LGPL included in the
20** packaging of this file. Please review the following information to
21** ensure the GNU Lesser General Public License version 2.1 requirements
22** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
23**
24** In addition, as a special exception, Nokia gives you certain additional
25** rights. These rights are described in the Nokia Qt LGPL Exception
26** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you have questions regarding the use of this file, please contact
37** Nokia at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42#ifndef Q3GCACHE_H
43#define Q3GCACHE_H
44
45#include <Qt3Support/q3ptrcollection.h>
46#include <Qt3Support/q3glist.h>
47#include <Qt3Support/q3gdict.h>
48
49QT_BEGIN_HEADER
50
51QT_BEGIN_NAMESPACE
52
53QT_MODULE(Qt3SupportLight)
54
55class Q3CList; // internal classes
56class Q3CListIt;
57class Q3CDict;
58
59class Q_COMPAT_EXPORT Q3GCache : public Q3PtrCollection // generic LRU cache
60{
61friend class Q3GCacheIterator;
62protected:
63 enum KeyType { StringKey, AsciiKey, IntKey, PtrKey };
64 // identical to Q3GDict's, but PtrKey is not used at the moment
65
66 Q3GCache(int maxCost, uint size, KeyType kt, bool caseSensitive,
67 bool copyKeys);
68 Q3GCache(const Q3GCache &); // not allowed, calls fatal()
69 ~Q3GCache();
70 Q3GCache &operator=(const Q3GCache &); // not allowed, calls fatal()
71
72 uint count() const;
73 uint size() const;
74 int maxCost() const { return mCost; }
75 int totalCost() const { return tCost; }
76 void setMaxCost(int maxCost);
77 void clear();
78
79 bool insert_string(const QString &key, Q3PtrCollection::Item,
80 int cost, int priority);
81 bool insert_other(const char *key, Q3PtrCollection::Item,
82 int cost, int priority);
83 bool remove_string(const QString &key);
84 bool remove_other(const char *key);
85 Q3PtrCollection::Item take_string(const QString &key);
86 Q3PtrCollection::Item take_other(const char *key);
87
88 Q3PtrCollection::Item find_string(const QString &key, bool ref=true) const;
89 Q3PtrCollection::Item find_other(const char *key, bool ref=true) const;
90
91 void statistics() const;
92
93private:
94 bool makeRoomFor(int cost, int priority = -1);
95 KeyType keytype;
96 Q3CList *lruList;
97 Q3CDict *dict;
98 int mCost;
99 int tCost;
100 bool copyk;
101};
102
103
104class Q_COMPAT_EXPORT Q3GCacheIterator // generic cache iterator
105{
106protected:
107 Q3GCacheIterator(const Q3GCache &);
108 Q3GCacheIterator(const Q3GCacheIterator &);
109 ~Q3GCacheIterator();
110 Q3GCacheIterator &operator=(const Q3GCacheIterator &);
111
112 uint count() const;
113 bool atFirst() const;
114 bool atLast() const;
115 Q3PtrCollection::Item toFirst();
116 Q3PtrCollection::Item toLast();
117
118 Q3PtrCollection::Item get() const;
119 QString getKeyString() const;
120 const char *getKeyAscii() const;
121 long getKeyInt() const;
122
123 Q3PtrCollection::Item operator()();
124 Q3PtrCollection::Item operator++();
125 Q3PtrCollection::Item operator+=(uint);
126 Q3PtrCollection::Item operator--();
127 Q3PtrCollection::Item operator-=(uint);
128
129protected:
130 Q3CListIt *it; // iterator on cache list
131};
132
133QT_END_NAMESPACE
134
135QT_END_HEADER
136
137#endif // Q3GCACHE_H
Note: See TracBrowser for help on using the repository browser.