Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

qptrlist.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: qptrlist.h,v 1.2 2003/07/10 02:40:11 llornkcor Exp $
00003 **
00004 ** Definition of QPtrList template/macro class
00005 **
00006 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00007 **
00008 ** This file is part of the tools module of the Qt GUI Toolkit.
00009 **
00010 ** This file may be distributed under the terms of the Q Public License
00011 ** as defined by Trolltech AS of Norway and appearing in the file
00012 ** LICENSE.QPL included in the packaging of this file.
00013 **
00014 ** This file may be distributed and/or modified under the terms of the
00015 ** GNU General Public License version 2 as published by the Free Software
00016 ** Foundation and appearing in the file LICENSE.GPL included in the
00017 ** packaging of this file.
00018 **
00019 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00020 ** licenses may use this file in accordance with the Qt Commercial License
00021 ** Agreement provided with the Software.
00022 **
00023 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00024 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00025 **
00026 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00027 **   information about Qt Commercial License Agreements.
00028 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00029 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00030 **
00031 ** Contact info@trolltech.com if any conditions of this licensing are
00032 ** not clear to you.
00033 **
00034 **********************************************************************/
00035 
00036 #ifndef QPTRLIST_H
00037 #define QPTRLIST_H
00038 
00039 #ifndef QT_H
00040 #include "qglist.h"
00041 #endif // QT_H
00042 
00043 
00044 template<class type>
00045 class QPtrList
00046 #ifdef Q_QDOC
00047         : public QPtrCollection
00048 #else
00049         : public QGList
00050 #endif
00051 {
00052 public:
00053     QPtrList()                          {}
00054     QPtrList( const QPtrList<type> &l ) : QGList(l) {}
00055     ~QPtrList()                         { clear(); }
00056     QPtrList<type> &operator=(const QPtrList<type> &l)
00057                         { return (QPtrList<type>&)QGList::operator=(l); }
00058     bool operator==( const QPtrList<type> &list ) const
00059     { return QGList::operator==( list ); }
00060     bool operator!=( const QPtrList<type> &list ) const
00061     { return !QGList::operator==( list ); }
00062     uint  count()   const               { return QGList::count(); }
00063     bool  isEmpty() const               { return QGList::count() == 0; }
00064     bool  insert( uint i, const type *d){ return QGList::insertAt(i,(QPtrCollection::Item)d); }
00065     void  inSort( const type *d )       { QGList::inSort((QPtrCollection::Item)d); }
00066     void  prepend( const type *d )      { QGList::insertAt(0,(QPtrCollection::Item)d); }
00067     void  append( const type *d )       { QGList::append((QPtrCollection::Item)d); }
00068     bool  remove( uint i )              { return QGList::removeAt(i); }
00069     bool  remove()                      { return QGList::remove((QPtrCollection::Item)0); }
00070     bool  remove( const type *d )       { return QGList::remove((QPtrCollection::Item)d); }
00071     bool  removeRef( const type *d )    { return QGList::removeRef((QPtrCollection::Item)d); }
00072     void  removeNode( QLNode *n )       { QGList::removeNode(n); }
00073     bool  removeFirst()                 { return QGList::removeFirst(); }
00074     bool  removeLast()                  { return QGList::removeLast(); }
00075     type *take( uint i )                { return (type *)QGList::takeAt(i); }
00076     type *take()                        { return (type *)QGList::take(); }
00077     type *takeNode( QLNode *n )         { return (type *)QGList::takeNode(n); }
00078     void  clear()                       { QGList::clear(); }
00079     void  sort()                        { QGList::sort(); }
00080     int   find( const type *d )         { return QGList::find((QPtrCollection::Item)d); }
00081     int   findNext( const type *d )     { return QGList::find((QPtrCollection::Item)d,FALSE); }
00082     int   findRef( const type *d )      { return QGList::findRef((QPtrCollection::Item)d); }
00083     int   findNextRef( const type *d ){ return QGList::findRef((QPtrCollection::Item)d,FALSE);}
00084     uint  contains( const type *d ) const { return QGList::contains((QPtrCollection::Item)d); }
00085     uint  containsRef( const type *d ) const
00086                                         { return QGList::containsRef((QPtrCollection::Item)d); }
00087     bool replace( uint i, const type *d ) { return QGList::replaceAt( i, (QPtrCollection::Item)d ); }
00088     type *at( uint i )                  { return (type *)QGList::at(i); }
00089     int   at() const                    { return QGList::at(); }
00090     type *current()  const              { return (type *)QGList::get(); }
00091     QLNode *currentNode()  const        { return QGList::currentNode(); }
00092     type *getFirst() const              { return (type *)QGList::cfirst(); }
00093     type *getLast()  const              { return (type *)QGList::clast(); }
00094     type *first()                       { return (type *)QGList::first(); }
00095     type *last()                        { return (type *)QGList::last(); }
00096     type *next()                        { return (type *)QGList::next(); }
00097     type *prev()                        { return (type *)QGList::prev(); }
00098     void  toVector( QGVector *vec )const{ QGList::toVector(vec); }
00099 
00100 #ifdef Q_QDOC
00101 protected:
00102     virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item );
00103     virtual QDataStream& read( QDataStream&, QPtrCollection::Item& );
00104     virtual QDataStream& write( QDataStream&, QPtrCollection::Item ) const;
00105 #endif
00106 
00107 private:
00108     void  deleteItem( Item d );
00109 };
00110 
00111 #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
00112 template<> inline void QPtrList<void>::deleteItem( QPtrCollection::Item )
00113 {
00114 }
00115 #endif
00116 
00117 template<class type> inline void QPtrList<type>::deleteItem( QPtrCollection::Item d )
00118 {
00119     if ( del_item ) delete (type *)d;
00120 }
00121 
00122 template<class type>
00123 class QPtrListIterator : public QGListIterator
00124 {
00125 public:
00126     QPtrListIterator(const QPtrList<type> &l) :QGListIterator((QGList &)l) {}
00127    ~QPtrListIterator()        {}
00128     uint  count()   const     { return list->count(); }
00129     bool  isEmpty() const     { return list->count() == 0; }
00130     bool  atFirst() const     { return QGListIterator::atFirst(); }
00131     bool  atLast()  const     { return QGListIterator::atLast(); }
00132     type *toFirst()           { return (type *)QGListIterator::toFirst(); }
00133     type *toLast()            { return (type *)QGListIterator::toLast(); }
00134     operator type *() const   { return (type *)QGListIterator::get(); }
00135     type *operator*()         { return (type *)QGListIterator::get(); }
00136 
00137     // No good, since QPtrList<char> (ie. QStrList fails...
00138     //
00139     // MSVC++ gives warning
00140     // Sunpro C++ 4.1 gives error
00141     //    type *operator->()        { return (type *)QGListIterator::get(); }
00142 
00143     type *current()   const   { return (type *)QGListIterator::get(); }
00144     type *operator()()        { return (type *)QGListIterator::operator()();}
00145     type *operator++()        { return (type *)QGListIterator::operator++(); }
00146     type *operator+=(uint j)  { return (type *)QGListIterator::operator+=(j);}
00147     type *operator--()        { return (type *)QGListIterator::operator--(); }
00148     type *operator-=(uint j)  { return (type *)QGListIterator::operator-=(j);}
00149     QPtrListIterator<type>& operator=(const QPtrListIterator<type>&it)
00150                               { QGListIterator::operator=(it); return *this; }
00151 };
00152 
00153 #ifndef QT_NO_COMPAT
00154 #define QList QPtrList
00155 #define QListIterator QPtrListIterator
00156 #endif
00157 
00158 #ifdef QT_QWINEXPORT
00159 #define Q_DEFINED_QPTRLIST
00160 #include "qwinexport.h"
00161 #endif /* QT_QWINEXPORT */
00162 #endif // QPTRLIST_H

Generated on Sat Nov 5 16:18:26 2005 for OPIE by  doxygen 1.4.2