home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / qt3_emx.zip / include / qintcache.h < prev    next >
C/C++ Source or Header  |  2001-10-11  |  5KB  |  116 lines

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