Eneboo - Documentación para desarrolladores
src/qt/src/tools/qptrlist.h
Ir a la documentación de este archivo.
00001 /****************************************************************************
00002 ** $Id: qt/qptrlist.h   3.3.8   edited Jan 11 14:38 $
00003 **
00004 ** Definition of QPtrList template/macro class
00005 **
00006 ** Copyright (C) 1992-2007 Trolltech ASA.  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 ASA 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 template<class type>
00044 class QPtrListStdIterator : public QGListStdIterator
00045 {
00046 public:
00047     inline QPtrListStdIterator( QLNode* n ): QGListStdIterator(n) {}
00048     type *operator*() { return node ? (type *)node->getData() : 0; }
00049     inline QPtrListStdIterator<type> operator++()
00050     { node = next(); return *this; }
00051     inline QPtrListStdIterator<type> operator++(int)
00052     { QLNode* n = node; node = next(); return QPtrListStdIterator<type>( n ); }
00053     inline bool operator==( const QPtrListStdIterator<type>& it ) const { return node == it.node; }
00054     inline bool operator!=( const QPtrListStdIterator<type>& it ) const { return node != it.node; }
00055 };
00056 
00057 
00058 template<class type>
00059 class QPtrList
00060 #ifdef Q_QDOC
00061         : public QPtrCollection
00062 #else
00063         : public QGList
00064 #endif
00065 {
00066 public:
00067 
00068     QPtrList()                          {}
00069     QPtrList( const QPtrList<type> &l ) : QGList(l) {}
00070     ~QPtrList()                         { clear(); }
00071     QPtrList<type> &operator=(const QPtrList<type> &l)
00072                         { return (QPtrList<type>&)QGList::operator=(l); }
00073     bool operator==( const QPtrList<type> &list ) const
00074     { return QGList::operator==( list ); }
00075     bool operator!=( const QPtrList<type> &list ) const
00076     { return !QGList::operator==( list ); }
00077     uint  count()   const               { return QGList::count(); }
00078     bool  isEmpty() const               { return QGList::count() == 0; }
00079     bool  insert( uint i, const type *d){ return QGList::insertAt(i,(QPtrCollection::Item)d); }
00080     void  inSort( const type *d )       { QGList::inSort((QPtrCollection::Item)d); }
00081     void  prepend( const type *d )      { QGList::insertAt(0,(QPtrCollection::Item)d); }
00082     void  append( const type *d )       { QGList::append((QPtrCollection::Item)d); }
00083     bool  remove( uint i )              { return QGList::removeAt(i); }
00084     bool  remove()                      { return QGList::remove((QPtrCollection::Item)0); }
00085     bool  remove( const type *d )       { return QGList::remove((QPtrCollection::Item)d); }
00086     bool  removeRef( const type *d )    { return QGList::removeRef((QPtrCollection::Item)d); }
00087     void  removeNode( QLNode *n )       { QGList::removeNode(n); }
00088     bool  removeFirst()                 { return QGList::removeFirst(); }
00089     bool  removeLast()                  { return QGList::removeLast(); }
00090     type *take( uint i )                { return (type *)QGList::takeAt(i); }
00091     type *take()                        { return (type *)QGList::take(); }
00092     type *takeNode( QLNode *n )         { return (type *)QGList::takeNode(n); }
00093     void  clear()                       { QGList::clear(); }
00094     void  sort()                        { QGList::sort(); }
00095     int   find( const type *d )         { return QGList::find((QPtrCollection::Item)d); }
00096     int   findNext( const type *d )     { return QGList::find((QPtrCollection::Item)d,FALSE); }
00097     int   findRef( const type *d )      { return QGList::findRef((QPtrCollection::Item)d); }
00098     int   findNextRef( const type *d ){ return QGList::findRef((QPtrCollection::Item)d,FALSE);}
00099     uint  contains( const type *d ) const { return QGList::contains((QPtrCollection::Item)d); }
00100     uint  containsRef( const type *d ) const
00101                                         { return QGList::containsRef((QPtrCollection::Item)d); }
00102     bool replace( uint i, const type *d ) { return QGList::replaceAt( i, (QPtrCollection::Item)d ); }
00103     type *at( uint i )                  { return (type *)QGList::at(i); }
00104     int   at() const                    { return QGList::at(); }
00105     type *current()  const              { return (type *)QGList::get(); }
00106     QLNode *currentNode()  const        { return QGList::currentNode(); }
00107     type *getFirst() const              { return (type *)QGList::cfirst(); }
00108     type *getLast()  const              { return (type *)QGList::clast(); }
00109     type *first()                       { return (type *)QGList::first(); }
00110     type *last()                        { return (type *)QGList::last(); }
00111     type *next()                        { return (type *)QGList::next(); }
00112     type *prev()                        { return (type *)QGList::prev(); }
00113     void  toVector( QGVector *vec )const{ QGList::toVector(vec); }
00114 
00115 
00116     // standard iterators
00117     typedef QPtrListStdIterator<type> Iterator;
00118     typedef QPtrListStdIterator<type> ConstIterator;
00119     inline Iterator begin() { return QGList::begin(); }
00120     inline ConstIterator begin() const { return QGList::begin(); }
00121     inline ConstIterator constBegin() const { return QGList::begin(); }
00122     inline Iterator end() { return QGList::end(); }
00123     inline ConstIterator end() const { return QGList::end(); }
00124     inline ConstIterator constEnd() const { return QGList::end(); }
00125     inline Iterator erase( Iterator it ) { return QGList::erase( it ); }
00126     // stl syntax compatibility
00127     typedef Iterator iterator;
00128     typedef ConstIterator const_iterator;
00129 
00130 
00131 #ifdef Q_QDOC
00132 protected:
00133     virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item );
00134     virtual QDataStream& read( QDataStream&, QPtrCollection::Item& );
00135     virtual QDataStream& write( QDataStream&, QPtrCollection::Item ) const;
00136 #endif
00137 
00138 private:
00139     void  deleteItem( Item d );
00140 };
00141 
00142 #if !defined(Q_BROKEN_TEMPLATE_SPECIALIZATION)
00143 template<> inline void QPtrList<void>::deleteItem( QPtrCollection::Item )
00144 {
00145 }
00146 #endif
00147 
00148 template<class type> inline void QPtrList<type>::deleteItem( QPtrCollection::Item d )
00149 {
00150     if ( del_item ) delete (type *)d;
00151 }
00152 
00153 template<class type>
00154 class QPtrListIterator : public QGListIterator
00155 {
00156 public:
00157     QPtrListIterator(const QPtrList<type> &l) :QGListIterator((QGList &)l) {}
00158    ~QPtrListIterator()        {}
00159     uint  count()   const     { return list->count(); }
00160     bool  isEmpty() const     { return list->count() == 0; }
00161     bool  atFirst() const     { return QGListIterator::atFirst(); }
00162     bool  atLast()  const     { return QGListIterator::atLast(); }
00163     type *toFirst()           { return (type *)QGListIterator::toFirst(); }
00164     type *toLast()            { return (type *)QGListIterator::toLast(); }
00165     operator type *() const   { return (type *)QGListIterator::get(); }
00166     type *operator*()         { return (type *)QGListIterator::get(); }
00167 
00168     // No good, since QPtrList<char> (ie. QStrList fails...
00169     //
00170     // MSVC++ gives warning
00171     // Sunpro C++ 4.1 gives error
00172     //    type *operator->()        { return (type *)QGListIterator::get(); }
00173 
00174     type *current()   const   { return (type *)QGListIterator::get(); }
00175     type *operator()()        { return (type *)QGListIterator::operator()();}
00176     type *operator++()        { return (type *)QGListIterator::operator++(); }
00177     type *operator+=(uint j)  { return (type *)QGListIterator::operator+=(j);}
00178     type *operator--()        { return (type *)QGListIterator::operator--(); }
00179     type *operator-=(uint j)  { return (type *)QGListIterator::operator-=(j);}
00180     QPtrListIterator<type>& operator=(const QPtrListIterator<type>&it)
00181                               { QGListIterator::operator=(it); return *this; }
00182 };
00183 
00184 #ifndef QT_NO_COMPAT
00185 #define QList QPtrList
00186 #define QListIterator QPtrListIterator
00187 #endif
00188 
00189 #define Q_DEFINED_QPTRLIST
00190 #include "qwinexport.h"
00191 
00192 #endif // QPTRLIST_H
 Todo Clases Namespaces Archivos Funciones Variables 'typedefs' Enumeraciones Valores de enumeraciones Propiedades Amigas 'defines'