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

  1. /****************************************************************************
  2. ** $Id$
  3. **
  4. ** Definition of QAsciiCache template/macro 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 QASCIICACHE_H
  39. #define QASCIICACHE_H
  40.  
  41. #ifndef QT_H
  42. #include "qgcache.h"
  43. #endif // QT_H
  44.  
  45.  
  46. template<class type> class Q_EXPORT QAsciiCache : public QGCache
  47. {
  48. public:
  49.     QAsciiCache( const QAsciiCache<type> &c ) : QGCache(c) {}
  50.     QAsciiCache( int maxCost=100, int size=17, bool caseSensitive=TRUE,
  51.          bool copyKeys=TRUE )
  52.     : QGCache( maxCost, size, AsciiKey, caseSensitive, copyKeys ) {}
  53.    ~QAsciiCache()            { clear(); }
  54.     QAsciiCache<type> &operator=( const QAsciiCache<type> &c )
  55.             { return (QAsciiCache<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.     void  clear()            { QGCache::clear(); }
  63.     bool  insert( const char *k, const type *d, int c=1, int p=0 )
  64.             { return QGCache::insert_other(k,(Item)d,c,p);}
  65.     bool  remove( const char *k )
  66.             { return QGCache::remove_other(k); }
  67.     type *take( const char *k )
  68.             { return (type *)QGCache::take_other(k); }
  69.     type *find( const char *k, bool ref=TRUE ) const
  70.             { return (type *)QGCache::find_other(k,ref);}
  71.     type *operator[]( const char *k ) const
  72.             { return (type *)QGCache::find_other(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 QAsciiCache<void>::deleteItem( QPtrCollection::Item )
  80. {
  81. }
  82. #endif
  83.  
  84. template<class type> inline void QAsciiCache<type>::deleteItem( QPtrCollection::Item d )
  85. {
  86.     if ( del_item ) delete (type *)d;
  87. }
  88.  
  89.  
  90.  
  91. template<class type> class Q_EXPORT QAsciiCacheIterator : public QGCacheIterator
  92. {
  93. public:
  94.     QAsciiCacheIterator( const QAsciiCache<type> &c ):QGCacheIterator((QGCache &)c) {}
  95.     QAsciiCacheIterator( const QAsciiCacheIterator<type> &ci)
  96.                 : QGCacheIterator( (QGCacheIterator &)ci ) {}
  97.     QAsciiCacheIterator<type> &operator=(const QAsciiCacheIterator<type>&ci)
  98.     { return ( QAsciiCacheIterator<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.     const char *currentKey() const { return QGCacheIterator::getKeyAscii(); }
  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 // QASCIICACHE_H
  117.