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