1 /****************************************************************************
2 ** $Id: qt/qasciicache.h 3.3.8 edited Jan 11 14:38 $
3 **
4 ** Definition of QAsciiCache template/macro class
5 **
6 ** Created : 950209
7 **
8 ** Copyright (C) 1992-2007 Trolltech ASA. 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 ASA 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 QASCIICACHE_H
39 #define QASCIICACHE_H
40
41 #ifndef QT_H
42 #include "qgcache.h"
43 #endif // QT_H
44
45
46 template<class type>
47 class QAsciiCache
48 #ifdef Q_QDOC
49 : public QPtrCollection
50 #else
51 : public QGCache
52 #endif
53 {
54 public:
QAsciiCache(const QAsciiCache<type> & c)55 QAsciiCache( const QAsciiCache<type> &c ) : QGCache(c) {}
56 QAsciiCache( int maxCost=100, int size=17, bool caseSensitive=TRUE,
57 bool copyKeys=TRUE )
QGCache(maxCost,size,AsciiKey,caseSensitive,copyKeys)58 : QGCache( maxCost, size, AsciiKey, caseSensitive, copyKeys ) {}
~QAsciiCache()59 ~QAsciiCache() { clear(); }
60 QAsciiCache<type> &operator=( const QAsciiCache<type> &c )
61 { return (QAsciiCache<type>&)QGCache::operator=(c); }
maxCost()62 int maxCost() const { return QGCache::maxCost(); }
totalCost()63 int totalCost() const { return QGCache::totalCost(); }
setMaxCost(int m)64 void setMaxCost( int m ) { QGCache::setMaxCost(m); }
count()65 uint count() const { return QGCache::count(); }
size()66 uint size() const { return QGCache::size(); }
isEmpty()67 bool isEmpty() const { return QGCache::count() == 0; }
clear()68 void clear() { QGCache::clear(); }
69 bool insert( const char *k, const type *d, int c=1, int p=0 )
70 { return QGCache::insert_other(k,(Item)d,c,p);}
remove(const char * k)71 bool remove( const char *k )
72 { return QGCache::remove_other(k); }
take(const char * k)73 type *take( const char *k )
74 { return (type *)QGCache::take_other(k); }
75 type *find( const char *k, bool ref=TRUE ) const
76 { return (type *)QGCache::find_other(k,ref);}
77 type *operator[]( const char *k ) const
78 { return (type *)QGCache::find_other(k);}
statistics()79 void statistics() const { QGCache::statistics(); }
80 private:
81 void deleteItem( Item d );
82 };
83
84 #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
deleteItem(QPtrCollection::Item)85 template<> inline void QAsciiCache<void>::deleteItem( QPtrCollection::Item )
86 {
87 }
88 #endif
89
deleteItem(QPtrCollection::Item d)90 template<class type> inline void QAsciiCache<type>::deleteItem( QPtrCollection::Item d )
91 {
92 if ( del_item ) delete (type *)d;
93 }
94
95
96 template<class type>
97 class QAsciiCacheIterator : public QGCacheIterator
98 {
99 public:
QAsciiCacheIterator(const QAsciiCache<type> & c)100 QAsciiCacheIterator( const QAsciiCache<type> &c ):QGCacheIterator((QGCache &)c) {}
QAsciiCacheIterator(const QAsciiCacheIterator<type> & ci)101 QAsciiCacheIterator( const QAsciiCacheIterator<type> &ci)
102 : QGCacheIterator( (QGCacheIterator &)ci ) {}
103 QAsciiCacheIterator<type> &operator=(const QAsciiCacheIterator<type>&ci)
104 { return ( QAsciiCacheIterator<type>&)QGCacheIterator::operator=( ci ); }
count()105 uint count() const { return QGCacheIterator::count(); }
isEmpty()106 bool isEmpty() const { return QGCacheIterator::count() == 0; }
atFirst()107 bool atFirst() const { return QGCacheIterator::atFirst(); }
atLast()108 bool atLast() const { return QGCacheIterator::atLast(); }
toFirst()109 type *toFirst() { return (type *)QGCacheIterator::toFirst(); }
toLast()110 type *toLast() { return (type *)QGCacheIterator::toLast(); }
111 operator type *() const { return (type *)QGCacheIterator::get(); }
current()112 type *current() const { return (type *)QGCacheIterator::get(); }
currentKey()113 const char *currentKey() const { return QGCacheIterator::getKeyAscii(); }
operator()114 type *operator()() { return (type *)QGCacheIterator::operator()();}
115 type *operator++() { return (type *)QGCacheIterator::operator++(); }
116 type *operator+=(uint j) { return (type *)QGCacheIterator::operator+=(j);}
117 type *operator--() { return (type *)QGCacheIterator::operator--(); }
118 type *operator-=(uint j) { return (type *)QGCacheIterator::operator-=(j);}
119 };
120
121
122 #endif // QASCIICACHE_H
123