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

  1. /****************************************************************************
  2. ** $Id$
  3. **
  4. ** Definition of QPtrList template/macro class
  5. **
  6. ** Created :
  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 QPTRLIST_H
  39. #define QPTRLIST_H
  40.  
  41. #ifndef QT_H
  42. #include "qglist.h"
  43. #endif // QT_H
  44.  
  45.  
  46. template<class type> class Q_EXPORT QPtrList
  47. #ifdef Q_QDOC
  48.     : public QPtrCollection
  49. #else
  50.     : public QGList
  51. #endif
  52. {
  53. public:
  54.     QPtrList()                {}
  55.     QPtrList( const QPtrList<type> &l ) : QGList(l) {}
  56.     ~QPtrList()                { clear(); }
  57.     QPtrList<type> &operator=(const QPtrList<type> &l)
  58.             { return (QPtrList<type>&)QGList::operator=(l); }
  59.     bool operator==( const QPtrList<type> &list ) const
  60.     { return QGList::operator==( list ); }
  61.     uint  count()   const        { return QGList::count(); }
  62.     bool  isEmpty() const        { return QGList::count() == 0; }
  63.     bool  insert( uint i, const type *d){ return QGList::insertAt(i,(QPtrCollection::Item)d); }
  64.     void  inSort( const type *d )    { QGList::inSort((QPtrCollection::Item)d); }
  65.     void  prepend( const type *d )    { QGList::insertAt(0,(QPtrCollection::Item)d); }
  66.     void  append( const type *d )    { QGList::append((QPtrCollection::Item)d); }
  67.     bool  remove( uint i )        { return QGList::removeAt(i); }
  68.     bool  remove()            { return QGList::remove((QPtrCollection::Item)0); }
  69.     bool  remove( const type *d )    { return QGList::remove((QPtrCollection::Item)d); }
  70.     bool  removeRef( const type *d )    { return QGList::removeRef((QPtrCollection::Item)d); }
  71.     void  removeNode( QLNode *n )    { QGList::removeNode(n); }
  72.     bool  removeFirst()            { return QGList::removeFirst(); }
  73.     bool  removeLast()            { return QGList::removeLast(); }
  74.     type *take( uint i )        { return (type *)QGList::takeAt(i); }
  75.     type *take()            { return (type *)QGList::take(); }
  76.     type *takeNode( QLNode *n )        { return (type *)QGList::takeNode(n); }
  77.     void  clear()            { QGList::clear(); }
  78.     void  sort()            { QGList::sort(); }
  79.     int      find( const type *d )        { return QGList::find((QPtrCollection::Item)d); }
  80.     int      findNext( const type *d )    { return QGList::find((QPtrCollection::Item)d,FALSE); }
  81.     int      findRef( const type *d )    { return QGList::findRef((QPtrCollection::Item)d); }
  82.     int      findNextRef( const type *d ){ return QGList::findRef((QPtrCollection::Item)d,FALSE);}
  83.     uint  contains( const type *d ) const { return QGList::contains((QPtrCollection::Item)d); }
  84.     uint  containsRef( const type *d ) const
  85.                     { return QGList::containsRef((QPtrCollection::Item)d); }
  86.     type *at( uint i )            { return (type *)QGList::at(i); }
  87.     int      at() const            { return QGList::at(); }
  88.     type *current()  const        { return (type *)QGList::get(); }
  89.     QLNode *currentNode()  const    { return QGList::currentNode(); }
  90.     type *getFirst() const        { return (type *)QGList::cfirst(); }
  91.     type *getLast()  const        { return (type *)QGList::clast(); }
  92.     type *first()            { return (type *)QGList::first(); }
  93.     type *last()            { return (type *)QGList::last(); }
  94.     type *next()            { return (type *)QGList::next(); }
  95.     type *prev()            { return (type *)QGList::prev(); }
  96.     void  toVector( QGVector *vec )const{ QGList::toVector(vec); }
  97.  
  98. #ifdef Q_QDOC
  99. protected:
  100.     virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item );
  101.     virtual QDataStream& read( QDataStream&, QPtrCollection::Item& );
  102.     virtual QDataStream& write( QDataStream&, QPtrCollection::Item ) const;
  103. #endif
  104.  
  105. private:
  106.     void  deleteItem( QPtrCollection::Item d );
  107. };
  108.  
  109. #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
  110. template<> inline void QPtrList<void>::deleteItem( QPtrCollection::Item )
  111. {
  112. }
  113. #endif
  114.  
  115. template<class type> inline void QPtrList<type>::deleteItem( QPtrCollection::Item d )
  116. {
  117.     if ( del_item ) delete (type *)d;
  118. }
  119.  
  120.  
  121. template<class type> class Q_EXPORT QPtrListIterator : public QGListIterator
  122. {
  123. public:
  124.     QPtrListIterator(const QPtrList<type> &l) :QGListIterator((QGList &)l) {}
  125.    ~QPtrListIterator()          {}
  126.     uint  count()   const     { return list->count(); }
  127.     bool  isEmpty() const     { return list->count() == 0; }
  128.     bool  atFirst() const     { return QGListIterator::atFirst(); }
  129.     bool  atLast()  const     { return QGListIterator::atLast(); }
  130.     type *toFirst()          { return (type *)QGListIterator::toFirst(); }
  131.     type *toLast()          { return (type *)QGListIterator::toLast(); }
  132.     operator type *() const   { return (type *)QGListIterator::get(); }
  133.     type *operator*()         { return (type *)QGListIterator::get(); }
  134.  
  135.     // No good, since QPtrList<char> (ie. QStrList fails...
  136.     //
  137.     // MSVC++ gives warning
  138.     // Sunpro C++ 4.1 gives error
  139.     //    type *operator->()        { return (type *)QGListIterator::get(); }
  140.  
  141.     type *current()   const   { return (type *)QGListIterator::get(); }
  142.     type *operator()()          { return (type *)QGListIterator::operator()();}
  143.     type *operator++()          { return (type *)QGListIterator::operator++(); }
  144.     type *operator+=(uint j)  { return (type *)QGListIterator::operator+=(j);}
  145.     type *operator--()          { return (type *)QGListIterator::operator--(); }
  146.     type *operator-=(uint j)  { return (type *)QGListIterator::operator-=(j);}
  147.     QPtrListIterator<type>& operator=(const QPtrListIterator<type>&it)
  148.                   { QGListIterator::operator=(it); return *this; }
  149. };
  150.  
  151. #ifndef QT_NO_COMPAT
  152. #define QList QPtrList
  153. #define QListIterator QPtrListIterator
  154. #endif
  155.  
  156. #endif // QPTRLIST_H
  157.