Eneboo - Documentación para desarrolladores
src/qt/src/tools/qcache.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qcache.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QCache 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 QCACHE_H
00039 #define QCACHE_H
00040 
00041 #ifndef QT_H
00042 #include "qgcache.h"
00043 #endif // QT_H
00044 
00045 template<class type>
00046 class QCache
00047 #ifdef Q_QDOC
00048         : public QPtrCollection
00049 #else
00050         : public QGCache
00051 #endif
00052 {
00053 public:
00054     QCache( const QCache<type> &c ) : QGCache(c) {}
00055     QCache( int maxCost=100, int size=17, bool caseSensitive=TRUE )
00056         : QGCache( maxCost, size, StringKey, caseSensitive, FALSE ) {}
00057    ~QCache()                            { clear(); }
00058     QCache<type> &operator=( const QCache<type> &c )
00059                         { return (QCache<type>&)QGCache::operator=(c); }
00060     int   maxCost()   const             { return QGCache::maxCost(); }
00061     int   totalCost() const             { return QGCache::totalCost(); }
00062     void  setMaxCost( int m )           { QGCache::setMaxCost(m); }
00063     uint  count()     const             { return QGCache::count(); }
00064     uint  size()      const             { return QGCache::size(); }
00065     bool  isEmpty()   const             { return QGCache::count() == 0; }
00066     void  clear()                       { QGCache::clear(); }
00067     bool  insert( const QString &k, const type *d, int c=1, int p=0 )
00068                         { return QGCache::insert_string(k,(Item)d,c,p);}
00069     bool  remove( const QString &k )
00070                         { return QGCache::remove_string(k); }
00071     type *take( const QString &k )
00072                         { return (type *)QGCache::take_string(k); }
00073     type *find( const QString &k, bool ref=TRUE ) const
00074                         { return (type *)QGCache::find_string(k,ref);}
00075     type *operator[]( const QString &k ) const
00076                         { return (type *)QGCache::find_string(k);}
00077     void  statistics() const          { QGCache::statistics(); }
00078 private:
00079     void  deleteItem( Item d );
00080 };
00081 
00082 #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
00083 template<> inline void QCache<void>::deleteItem( QPtrCollection::Item )
00084 {
00085 }
00086 #endif
00087 
00088 template<class type> inline void QCache<type>::deleteItem( QPtrCollection::Item d )
00089 {
00090     if ( del_item ) delete (type *)d;
00091 }
00092 
00093 template<class type>
00094 class QCacheIterator : public QGCacheIterator
00095 {
00096 public:
00097     QCacheIterator( const QCache<type> &c ):QGCacheIterator((QGCache &)c) {}
00098     QCacheIterator( const QCacheIterator<type> &ci)
00099                                 : QGCacheIterator( (QGCacheIterator &)ci ) {}
00100     QCacheIterator<type> &operator=(const QCacheIterator<type>&ci)
00101         { return ( QCacheIterator<type>&)QGCacheIterator::operator=( ci ); }
00102     uint  count()   const     { return QGCacheIterator::count(); }
00103     bool  isEmpty() const     { return QGCacheIterator::count() == 0; }
00104     bool  atFirst() const     { return QGCacheIterator::atFirst(); }
00105     bool  atLast()  const     { return QGCacheIterator::atLast(); }
00106     type *toFirst()           { return (type *)QGCacheIterator::toFirst(); }
00107     type *toLast()            { return (type *)QGCacheIterator::toLast(); }
00108     operator type *() const   { return (type *)QGCacheIterator::get(); }
00109     type *current()   const   { return (type *)QGCacheIterator::get(); }
00110     QString currentKey() const{ return QGCacheIterator::getKeyString(); }
00111     type *operator()()        { return (type *)QGCacheIterator::operator()();}
00112     type *operator++()        { return (type *)QGCacheIterator::operator++(); }
00113     type *operator+=(uint j)  { return (type *)QGCacheIterator::operator+=(j);}
00114     type *operator--()        { return (type *)QGCacheIterator::operator--(); }
00115     type *operator-=(uint j)  { return (type *)QGCacheIterator::operator-=(j);}
00116 };
00117 
00118 #endif // QCACHE_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'