qcache.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 **
4 ** Definition of QCache template class
5 **
6 ** Created : 950209
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 QCACHE_H
39 #define QCACHE_H
40 
41 #ifndef QT_H
42 #include "qgcache.h"
43 #endif // QT_H
44 
45 #define USE_ASCII_STRING
46 
47 #ifndef USE_ASCII_STRING
48 
49 template<class type> class Q_EXPORT QCache : public QGCache
50 {
51 public:
52  QCache( const QCache<type> &c ) : QGCache(c) {}
53  QCache( int maxCost=100, int size=17, bool caseSensitive=TRUE )
54  : QGCache( maxCost, size, StringKey, caseSensitive, FALSE ) {}
55  ~QCache() { clear(); }
57  { return (QCache<type>&)QGCache::operator=(c); }
58  int maxCost() const { return QGCache::maxCost(); }
59  int totalCost() const { return QGCache::totalCost(); }
60  void setMaxCost( int m ) { QGCache::setMaxCost(m); }
61  uint count() const { return QGCache::count(); }
62  uint size() const { return QGCache::size(); }
63  bool isEmpty() const { return QGCache::count() == 0; }
64  void clear() { QGCache::clear(); }
65  bool insert( const QString &k, const type *d, int c=1, int p=0 )
66  { return QGCache::insert_string(k,(Item)d,c,p);}
67  bool remove( const QString &k )
68  { return QGCache::remove_string(k); }
69  type *take( const QString &k )
70  { return (type *)QGCache::take_string(k); }
71  type *find( const QString &k, bool ref=TRUE ) const
72  { return (type *)QGCache::find_string(k,ref);}
73  type *operator[]( const QString &k ) const
74  { return (type *)QGCache::find_string(k);}
75  void statistics() const { QGCache::statistics(); }
76  int hits() const { return QGCache::hits(); }
77  int misses() const { return QGCache::misses(); }
78 private:
79  void deleteItem( Item d ) { if ( del_item ) delete (type *)d; }
80 };
81 
82 #else
83 
84 
85 template<class type> class Q_EXPORT QCache : public QGCache
86 {
87 public:
88  QCache( const QCache<type> &c ) : QGCache(c) {}
89  QCache( int maxCost=100, int size=17, bool caseSensitive=TRUE )
90  : QGCache( maxCost, size, AsciiKey, caseSensitive, TRUE ) {}
91  ~QCache() { clear(); }
93  { return (QCache<type>&)QGCache::operator=(c); }
94  int maxCost() const { return QGCache::maxCost(); }
95  int totalCost() const { return QGCache::totalCost(); }
96  void setMaxCost( int m ) { QGCache::setMaxCost(m); }
97  uint count() const { return QGCache::count(); }
98  uint size() const { return QGCache::size(); }
99  bool isEmpty() const { return QGCache::count() == 0; }
100  void clear() { QGCache::clear(); }
101  bool insert( const char *k, const type *d, int c=1, int p=0 )
102  { return QGCache::insert_other(k,(Item)d,c,p);}
103  bool remove( const char *k )
104  { return QGCache::remove_other(k); }
105  type *take( const char *k )
106  { return (type *)QGCache::take_other(k); }
107  type *find( const char *k, bool ref=TRUE ) const
108  { return (type *)QGCache::find_other(k,ref);}
109  type *operator[]( const char *k ) const
110  { return (type *)QGCache::find_other(k);}
111  void statistics() const { QGCache::statistics(); }
112  int hits() const { return QGCache::hits(); }
113  int misses() const { return QGCache::misses(); }
114 private:
115  void deleteItem( Item d ) { if ( del_item ) delete (type *)d; }
116 };
117 
118 
119 #endif
120 
121 
122 
123 template<class type> class Q_EXPORT QCacheIterator : public QGCacheIterator
124 {
125 public:
128  : QGCacheIterator( (QGCacheIterator &)ci ) {}
131  uint count() const { return QGCacheIterator::count(); }
132  bool isEmpty() const { return QGCacheIterator::count() == 0; }
133  bool atFirst() const { return QGCacheIterator::atFirst(); }
134  bool atLast() const { return QGCacheIterator::atLast(); }
137  operator type *() const { return (type *)QGCacheIterator::get(); }
138  type *current() const { return (type *)QGCacheIterator::get(); }
139 #ifndef USE_ASCII_STRING
140  QString currentKey() const{ return QGCacheIterator::getKeyString(); }
141 #else
142  const char *currentKey() const{ return QGCacheIterator::getKeyAscii(); }
143 #endif
149 };
150 
151 
152 #endif // QCACHE_H
type * toFirst()
Definition: qcache.h:135
type * operator()()
Definition: qcache.h:144
type * current() const
Definition: qcache.h:138
QCache(int maxCost=100, int size=17, bool caseSensitive=TRUE)
Definition: qcache.h:89
The QGCache class is an internal class for implementing QCache template classes.
Definition: qgcache.h:53
uint count() const
Definition: qcache.h:131
int hits() const
Definition: qcache.h:112
type * toLast()
Definition: qcache.h:136
void clear()
Definition: qcache.h:100
int maxCost() const
Definition: qgcache.h:68
QCollection::Item operator-=(uint)
Definition: qgcache.cpp:874
Definition: qcache.h:85
void setMaxCost(int m)
Definition: qcache.h:96
QCollection::Item find_string(const QString &key, bool ref=TRUE) const
Definition: qgcache.cpp:525
QGCacheIterator & operator=(const QGCacheIterator &)
Definition: qgcache.cpp:723
const bool FALSE
Definition: qglobal.h:370
QGCache(int maxCost, uint size, KeyType kt, bool caseSensitive, bool copyKeys)
Definition: qgcache.cpp:234
uint count() const
Definition: qgcache.h:66
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
QCollection::Item take_string(const QString &key)
Definition: qgcache.cpp:445
bool insert(const char *k, const type *d, int c=1, int p=0)
Definition: qcache.h:101
uint size() const
Definition: qcache.h:98
bool atFirst() const
Definition: qgcache.cpp:744
QGCache & operator=(const QGCache &)
Definition: qgcache.cpp:288
QCollection::Item toFirst()
Definition: qgcache.cpp:764
bool isEmpty() const
Definition: qcache.h:132
int misses() const
Definition: qgcache.cpp:663
int hits() const
Definition: qgcache.cpp:658
QCacheIterator(const QCache< type > &c)
Definition: qcache.h:126
void setMaxCost(int maxCost)
Definition: qgcache.cpp:326
type * operator[](const char *k) const
Definition: qcache.h:109
bool insert_string(const QString &key, QCollection::Item, int cost, int priority)
Definition: qgcache.cpp:348
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 remove_other(const char *key)
Definition: qgcache.cpp:431
QCacheIterator(const QCacheIterator< type > &ci)
Definition: qcache.h:127
QCollection::Item operator+=(uint)
Definition: qgcache.cpp:852
int totalCost() const
Definition: qcache.h:95
QCollection::Item operator++()
Definition: qgcache.cpp:841
uint count() const
Definition: qcache.h:97
int misses() const
Definition: qcache.h:113
void deleteItem(Item d)
Definition: qcache.h:115
QCache< type > & operator=(const QCache< type > &c)
Definition: qcache.h:92
void statistics() const
Definition: qgcache.cpp:628
type * operator-=(uint j)
Definition: qcache.h:148
bool isEmpty() const
Definition: qcache.h:99
QCollection::Item find_other(const char *key, bool ref=TRUE) const
Definition: qgcache.cpp:549
const char * currentKey() const
Definition: qcache.h:142
p
Definition: test.py:223
QCache(const QCache< type > &c)
Definition: qcache.h:88
bool remove_string(const QString &key)
Definition: qgcache.cpp:420
const char * getKeyAscii() const
Definition: qgcache.cpp:808
QCollection::Item take_other(const char *key)
Definition: qgcache.cpp:466
type * operator++()
Definition: qcache.h:145
bool atFirst() const
Definition: qcache.h:133
void clear()
Definition: qgcache.cpp:493
bool atLast() const
Definition: qgcache.cpp:754
type * operator+=(uint j)
Definition: qcache.h:146
QCollection::Item operator--()
Definition: qgcache.cpp:863
QCollection::Item operator()()
Definition: qgcache.cpp:830
type * take(const char *k)
Definition: qcache.h:105
type * find(const char *k, bool ref=TRUE) const
Definition: qcache.h:107
int totalCost() const
Definition: qgcache.h:69
type * operator--()
Definition: qcache.h:147
bool insert_other(const char *key, QCollection::Item, int cost, int priority)
Definition: qgcache.cpp:380
void statistics() const
Definition: qcache.h:111
uint count() const
Definition: qgcache.cpp:734
QCollection::Item get() const
Definition: qgcache.cpp:786
~QCache()
Definition: qcache.h:91
virtual void deleteItem(Item)
QCacheIterator< type > & operator=(const QCacheIterator< type > &ci)
Definition: qcache.h:129
QCollection::Item toLast()
Definition: qgcache.cpp:775
unsigned uint
Definition: qglobal.h:351
bool atLast() const
Definition: qcache.h:134
int maxCost() const
Definition: qcache.h:94
#define Q_EXPORT
Definition: qglobal.h:468
const bool TRUE
Definition: qglobal.h:371
QString getKeyString() const
Definition: qgcache.cpp:797
void * Item
Definition: qcollection.h:60
uint size() const
Definition: qgcache.h:67