1 | /****************************************************************************
|
---|
2 | ** $Id: qcache.h 2 2005-11-16 15:49:26Z dmik $
|
---|
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 | template<class type>
|
---|
46 | class QCache
|
---|
47 | #ifdef Q_QDOC
|
---|
48 | : public QPtrCollection
|
---|
49 | #else
|
---|
50 | : public QGCache
|
---|
51 | #endif
|
---|
52 | {
|
---|
53 | public:
|
---|
54 | QCache( const QCache<type> &c ) : QGCache(c) {}
|
---|
55 | QCache( int maxCost=100, int size=17, bool caseSensitive=TRUE )
|
---|
56 | : QGCache( maxCost, size, StringKey, caseSensitive, FALSE ) {}
|
---|
57 | ~QCache() { clear(); }
|
---|
58 | QCache<type> &operator=( const QCache<type> &c )
|
---|
59 | { return (QCache<type>&)QGCache::operator=(c); }
|
---|
60 | int maxCost() const { return QGCache::maxCost(); }
|
---|
61 | int totalCost() const { return QGCache::totalCost(); }
|
---|
62 | void setMaxCost( int m ) { QGCache::setMaxCost(m); }
|
---|
63 | uint count() const { return QGCache::count(); }
|
---|
64 | uint size() const { return QGCache::size(); }
|
---|
65 | bool isEmpty() const { return QGCache::count() == 0; }
|
---|
66 | void clear() { QGCache::clear(); }
|
---|
67 | bool insert( const QString &k, const type *d, int c=1, int p=0 )
|
---|
68 | { return QGCache::insert_string(k,(Item)d,c,p);}
|
---|
69 | bool remove( const QString &k )
|
---|
70 | { return QGCache::remove_string(k); }
|
---|
71 | type *take( const QString &k )
|
---|
72 | { return (type *)QGCache::take_string(k); }
|
---|
73 | type *find( const QString &k, bool ref=TRUE ) const
|
---|
74 | { return (type *)QGCache::find_string(k,ref);}
|
---|
75 | type *operator[]( const QString &k ) const
|
---|
76 | { return (type *)QGCache::find_string(k);}
|
---|
77 | void statistics() const { QGCache::statistics(); }
|
---|
78 | private:
|
---|
79 | void deleteItem( Item d );
|
---|
80 | };
|
---|
81 |
|
---|
82 | #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
|
---|
83 | template<> inline void QCache<void>::deleteItem( QPtrCollection::Item )
|
---|
84 | {
|
---|
85 | }
|
---|
86 | #endif
|
---|
87 |
|
---|
88 | template<class type> inline void QCache<type>::deleteItem( QPtrCollection::Item d )
|
---|
89 | {
|
---|
90 | if ( del_item ) delete (type *)d;
|
---|
91 | }
|
---|
92 |
|
---|
93 | template<class type>
|
---|
94 | class QCacheIterator : public QGCacheIterator
|
---|
95 | {
|
---|
96 | public:
|
---|
97 | QCacheIterator( const QCache<type> &c ):QGCacheIterator((QGCache &)c) {}
|
---|
98 | QCacheIterator( const QCacheIterator<type> &ci)
|
---|
99 | : QGCacheIterator( (QGCacheIterator &)ci ) {}
|
---|
100 | QCacheIterator<type> &operator=(const QCacheIterator<type>&ci)
|
---|
101 | { return ( QCacheIterator<type>&)QGCacheIterator::operator=( ci ); }
|
---|
102 | uint count() const { return QGCacheIterator::count(); }
|
---|
103 | bool isEmpty() const { return QGCacheIterator::count() == 0; }
|
---|
104 | bool atFirst() const { return QGCacheIterator::atFirst(); }
|
---|
105 | bool atLast() const { return QGCacheIterator::atLast(); }
|
---|
106 | type *toFirst() { return (type *)QGCacheIterator::toFirst(); }
|
---|
107 | type *toLast() { return (type *)QGCacheIterator::toLast(); }
|
---|
108 | operator type *() const { return (type *)QGCacheIterator::get(); }
|
---|
109 | type *current() const { return (type *)QGCacheIterator::get(); }
|
---|
110 | QString currentKey() const{ return QGCacheIterator::getKeyString(); }
|
---|
111 | type *operator()() { return (type *)QGCacheIterator::operator()();}
|
---|
112 | type *operator++() { return (type *)QGCacheIterator::operator++(); }
|
---|
113 | type *operator+=(uint j) { return (type *)QGCacheIterator::operator+=(j);}
|
---|
114 | type *operator--() { return (type *)QGCacheIterator::operator--(); }
|
---|
115 | type *operator-=(uint j) { return (type *)QGCacheIterator::operator-=(j);}
|
---|
116 | };
|
---|
117 |
|
---|
118 | #endif // QCACHE_H
|
---|