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