qgcache.h
Go to the documentation of this file.
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  int hits() const;
87  int misses() const;
88 
89 private:
90  bool makeRoomFor( int cost, int priority = -1 );
94  int mCost;
95  int tCost;
96  bool copyk;
97 };
98 
99 
100 class Q_EXPORT QGCacheIterator // generic cache iterator
101 {
102 protected:
103  QGCacheIterator( const QGCache & );
104  QGCacheIterator( const QGCacheIterator & );
105  ~QGCacheIterator();
106  QGCacheIterator &operator=( const QGCacheIterator & );
107 
108  uint count() const;
109  bool atFirst() const;
110  bool atLast() const;
111  QCollection::Item toFirst();
112  QCollection::Item toLast();
113 
114  QCollection::Item get() const;
115  QString getKeyString() const;
116  const char *getKeyAscii() const;
117  intptr_t getKeyInt() const;
118 
119  QCollection::Item operator()();
120  QCollection::Item operator++();
122  QCollection::Item operator--();
123  QCollection::Item operator-=( uint );
124 
125 protected:
126  QCListIt *it; // iterator on cache list
127 };
128 
129 
130 #endif // QGCACHE_H
The QGCache class is an internal class for implementing QCache template classes.
Definition: qgcache.h:53
DoubleProduct & operator+=(DoubleProduct &left, DoubleProduct const &right)
Definition: ToyProducts.h:103
KeyType keytype
Definition: qgcache.h:91
int maxCost() const
Definition: qgcache.h:68
QGCacheIterator & operator=(const QGCacheIterator &)
Definition: qgcache.cpp:723
KeyType
Definition: qgcache.h:57
uint count() const
Definition: qgcache.h:66
void statistics()
Definition: doxygen.cpp:257
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QCList * lruList
Definition: qgcache.h:92
An internal class for implementing QCacheIterator and QIntCacheIterator.
Definition: qgcache.h:100
decltype(auto) constexpr size(T &&obj)
ADL-aware version of std::size.
Definition: StdUtils.h:92
bool copyk
Definition: qgcache.h:96
def key(type, name=None)
Definition: graph.py:13
The QCollection class is the base class of all Qt collections.
Definition: qcollection.h:51
virtual void clear()=0
QCListIt * it
Definition: qgcache.h:126
int tCost
Definition: qgcache.h:95
The QGDict class is an internal class for implementing QDict template classes.
Definition: qgdict.h:104
QCDict * dict
Definition: qgcache.h:93
int totalCost() const
Definition: qgcache.h:69
int mCost
Definition: qgcache.h:94
unsigned uint
Definition: qglobal.h:351
#define Q_EXPORT
Definition: qglobal.h:468
const bool TRUE
Definition: qglobal.h:371
void * Item
Definition: qcollection.h:60
uint size() const
Definition: qgcache.h:67