ISLEman
qcache.h
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(); }
56  QCache<type> &operator=( const QCache<type> &c )
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(); }
92  QCache<type> &operator=( const QCache<type> &c )
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 ) {}
129  QCacheIterator<type> &operator=(const QCacheIterator<type>&ci)
130  { return ( QCacheIterator<type>&)QGCacheIterator::operator=( 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(); }
135  type *toFirst() { return (type *)QGCacheIterator::toFirst(); }
136  type *toLast() { return (type *)QGCacheIterator::toLast(); }
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
144  type *operator()() { return (type *)QGCacheIterator::operator()();}
145  type *operator++() { return (type *)QGCacheIterator::operator++(); }
146  type *operator+=(uint j) { return (type *)QGCacheIterator::operator+=(j);}
147  type *operator--() { return (type *)QGCacheIterator::operator--(); }
148  type *operator-=(uint j) { return (type *)QGCacheIterator::operator-=(j);}
149 };
150 
151 
152 #endif // QCACHE_H
The QGCache class is an internal class for implementing QCache template classes.
Definition: qgcache.h:53
void clear()
Definition: qcache.h:100
Definition: qcache.h:85
The QString class provides an abstraction of Unicode text and the classic C null-terminated char arra...
Definition: qstring.h:350
An internal class for implementing QCacheIterator and QIntCacheIterator.
Definition: qgcache.h:100
uint count() const
Definition: qgcache.h:66
void clear()
Definition: qgcache.cpp:493
Definition: qcache.h:123
virtual void deleteItem(Item)
Definition: qcollection.cpp:174
uint count() const
Definition: qcache.h:97