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