Eneboo - Documentación para desarrolladores
|
00001 /**************************************************************************** 00002 ** $Id: qt/qintcache.h 3.3.8 edited Jan 11 14:38 $ 00003 ** 00004 ** Definition of QIntCache template class 00005 ** 00006 ** Created : 950209 00007 ** 00008 ** Copyright (C) 1992-2007 Trolltech ASA. All rights reserved. 00009 ** 00010 ** This file is part of the tools module of the Qt GUI Toolkit. 00011 ** 00012 ** This file may be distributed under the terms of the Q Public License 00013 ** as defined by Trolltech ASA of Norway and appearing in the file 00014 ** LICENSE.QPL included in the packaging of this file. 00015 ** 00016 ** This file may be distributed and/or modified under the terms of the 00017 ** GNU General Public License version 2 as published by the Free Software 00018 ** Foundation and appearing in the file LICENSE.GPL included in the 00019 ** packaging of this file. 00020 ** 00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition 00022 ** licenses may use this file in accordance with the Qt Commercial License 00023 ** Agreement provided with the Software. 00024 ** 00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE 00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. 00027 ** 00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for 00029 ** information about Qt Commercial License Agreements. 00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information. 00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information. 00032 ** 00033 ** Contact info@trolltech.com if any conditions of this licensing are 00034 ** not clear to you. 00035 ** 00036 **********************************************************************/ 00037 00038 #ifndef QINTCACHE_H 00039 #define QINTCACHE_H 00040 00041 #ifndef QT_H 00042 #include "qgcache.h" 00043 #endif // QT_H 00044 00045 00046 template<class type> 00047 class QIntCache 00048 #ifdef Q_QDOC 00049 : public QPtrCollection 00050 #else 00051 : public QGCache 00052 #endif 00053 { 00054 public: 00055 QIntCache( const QIntCache<type> &c ) : QGCache(c) {} 00056 QIntCache( int maxCost=100, int size=17 ) 00057 : QGCache( maxCost, size, IntKey, FALSE, FALSE ) {} 00058 ~QIntCache() { clear(); } 00059 QIntCache<type> &operator=( const QIntCache<type> &c ) 00060 { return (QIntCache<type>&)QGCache::operator=(c); } 00061 int maxCost() const { return QGCache::maxCost(); } 00062 int totalCost() const { return QGCache::totalCost(); } 00063 void setMaxCost( int m) { QGCache::setMaxCost(m); } 00064 uint count() const { return QGCache::count(); } 00065 uint size() const { return QGCache::size(); } 00066 bool isEmpty() const { return QGCache::count() == 0; } 00067 bool insert( long k, const type *d, int c=1, int p=0 ) 00068 { return QGCache::insert_other((const char*)k,(Item)d,c,p); } 00069 bool remove( long k ) 00070 { return QGCache::remove_other((const char*)k); } 00071 type *take( long k ) 00072 { return (type *)QGCache::take_other((const char*)k);} 00073 void clear() { QGCache::clear(); } 00074 type *find( long k, bool ref=TRUE ) const 00075 { return (type *)QGCache::find_other( (const char*)k,ref);} 00076 type *operator[]( long k ) const 00077 { return (type *)QGCache::find_other( (const char*)k); } 00078 void statistics() const { QGCache::statistics(); } 00079 private: 00080 void deleteItem( Item d ); 00081 }; 00082 00083 #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION) 00084 template<> inline void QIntCache<void>::deleteItem( QPtrCollection::Item ) 00085 { 00086 } 00087 #endif 00088 00089 template<class type> inline void QIntCache<type>::deleteItem( QPtrCollection::Item d ) 00090 { 00091 if ( del_item ) delete (type *)d; 00092 } 00093 00094 template<class type> 00095 class QIntCacheIterator : public QGCacheIterator 00096 { 00097 public: 00098 QIntCacheIterator( const QIntCache<type> &c ) 00099 : QGCacheIterator( (QGCache &)c ) {} 00100 QIntCacheIterator( const QIntCacheIterator<type> &ci ) 00101 : QGCacheIterator((QGCacheIterator &)ci) {} 00102 QIntCacheIterator<type> &operator=( const QIntCacheIterator<type>&ci ) 00103 { return ( QIntCacheIterator<type>&)QGCacheIterator::operator=( ci );} 00104 uint count() const { return QGCacheIterator::count(); } 00105 bool isEmpty() const { return QGCacheIterator::count() == 0; } 00106 bool atFirst() const { return QGCacheIterator::atFirst(); } 00107 bool atLast() const { return QGCacheIterator::atLast(); } 00108 type *toFirst() { return (type *)QGCacheIterator::toFirst(); } 00109 type *toLast() { return (type *)QGCacheIterator::toLast(); } 00110 operator type *() const { return (type *)QGCacheIterator::get(); } 00111 type *current() const { return (type *)QGCacheIterator::get(); } 00112 long currentKey() const { return (long)QGCacheIterator::getKeyInt();} 00113 type *operator()() { return (type *)QGCacheIterator::operator()();} 00114 type *operator++() { return (type *)QGCacheIterator::operator++(); } 00115 type *operator+=(uint j) { return (type *)QGCacheIterator::operator+=(j);} 00116 type *operator--() { return (type *)QGCacheIterator::operator--(); } 00117 type *operator-=(uint j) { return (type *)QGCacheIterator::operator-=(j);} 00118 }; 00119 00120 00121 #endif // QINTCACHE_H