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

qglist.h

Go to the documentation of this file.
00001 /****************************************************************************
00002 ** $Id: qglist.h,v 1.2 2003/07/10 02:40:11 llornkcor Exp $
00003 **
00004 ** Definition of QGList and QGListIterator classes
00005 **
00006 ** Created : 920624
00007 **
00008 ** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
00009 **
00010 ** This file is part of the tools module of the Qt GUI Toolkit.
00011 **
00012 ** This file may be distributed under the terms of the Q Public License
00013 ** as defined by Trolltech AS of Norway and appearing in the file
00014 ** LICENSE.QPL included in the packaging of this file.
00015 **
00016 ** This file may be distributed and/or modified under the terms of the
00017 ** GNU General Public License version 2 as published by the Free Software
00018 ** Foundation and appearing in the file LICENSE.GPL included in the
00019 ** packaging of this file.
00020 **
00021 ** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
00022 ** licenses may use this file in accordance with the Qt Commercial License
00023 ** Agreement provided with the Software.
00024 **
00025 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00026 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00027 **
00028 ** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
00029 **   information about Qt Commercial License Agreements.
00030 ** See http://www.trolltech.com/qpl/ for QPL licensing information.
00031 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00032 **
00033 ** Contact info@trolltech.com if any conditions of this licensing are
00034 ** not clear to you.
00035 **
00036 **********************************************************************/
00037 
00038 #ifndef QGLIST_H
00039 #define QGLIST_H
00040 
00041 #ifndef QT_H
00042 #include "qptrcollection.h"
00043 #endif // QT_H
00044 
00045 class Q_EXPORT QLNode
00046 {
00047 friend class QGList;
00048 friend class QGListIterator;
00049 public:
00050     QPtrCollection::Item getData()      { return data; }
00051 private:
00052     QPtrCollection::Item data;
00053     QLNode *prev;
00054     QLNode *next;
00055     QLNode( QPtrCollection::Item d ) { data = d; }
00056 };
00057 
00058 class QGListIteratorList; // internal helper class
00059 
00060 class Q_EXPORT QGList : public QPtrCollection   // doubly linked generic list
00061 {
00062 friend class QGListIterator;
00063 friend class QGListIteratorList;
00064 friend class QGVector;                          // needed by QGVector::toList
00065 public:
00066     uint  count() const;                        // return number of nodes
00067 
00068 #ifndef QT_NO_DATASTREAM
00069     QDataStream &read( QDataStream & );         // read list from stream
00070     QDataStream &write( QDataStream & ) const;  // write list to stream
00071 #endif
00072 protected:
00073     QGList();                                   // create empty list
00074     QGList( const QGList & );                   // make copy of other list
00075     virtual ~QGList();
00076 
00077     QGList &operator=( const QGList & );        // assign from other list
00078     bool operator==( const QGList& ) const;
00079 
00080     void inSort( QPtrCollection::Item );                // add item sorted in list
00081     void append( QPtrCollection::Item );                // add item at end of list
00082     bool insertAt( uint index, QPtrCollection::Item ); // add item at i'th position
00083     void relinkNode( QLNode * );                // relink as first item
00084     bool removeNode( QLNode * );                // remove node
00085     bool remove( QPtrCollection::Item = 0 );    // remove item (0=current)
00086     bool removeRef( QPtrCollection::Item = 0 ); // remove item (0=current)
00087     bool removeFirst();                         // remove first item
00088     bool removeLast();                          // remove last item
00089     bool removeAt( uint );                      // remove item at i'th position
00090     bool replaceAt( uint, QPtrCollection::Item ); // replace item at position i with item
00091     QPtrCollection::Item takeNode( QLNode * );  // take out node
00092     QPtrCollection::Item take();                // take out current item
00093     QPtrCollection::Item takeAt( uint index );  // take out item at i'th pos
00094     QPtrCollection::Item takeFirst();           // take out first item
00095     QPtrCollection::Item takeLast();            // take out last item
00096 
00097     void sort();                                // sort all items;
00098     void clear();                               // remove all items
00099 
00100     int  findRef( QPtrCollection::Item, bool = TRUE ); // find exact item in list
00101     int  find( QPtrCollection::Item, bool = TRUE ); // find equal item in list
00102 
00103     uint containsRef( QPtrCollection::Item ) const;     // get number of exact matches
00104     uint contains( QPtrCollection::Item ) const;        // get number of equal matches
00105 
00106     QPtrCollection::Item at( uint index );      // access item at i'th pos
00107     int   at() const;                           // get current index
00108     QLNode *currentNode() const;                // get current node
00109 
00110     QPtrCollection::Item get() const;           // get current item
00111 
00112     QPtrCollection::Item cfirst() const;        // get ptr to first list item
00113     QPtrCollection::Item clast()  const;        // get ptr to last list item
00114     QPtrCollection::Item first();               // set first item in list curr
00115     QPtrCollection::Item last();                // set last item in list curr
00116     QPtrCollection::Item next();                // set next item in list curr
00117     QPtrCollection::Item prev();                // set prev item in list curr
00118 
00119     void  toVector( QGVector * ) const;         // put items in vector
00120 
00121     virtual int compareItems( QPtrCollection::Item, QPtrCollection::Item );
00122 
00123 #ifndef QT_NO_DATASTREAM
00124     virtual QDataStream &read( QDataStream &, QPtrCollection::Item & );
00125     virtual QDataStream &write( QDataStream &, QPtrCollection::Item ) const;
00126 #endif
00127 private:
00128     void  prepend( QPtrCollection::Item );      // add item at start of list
00129 
00130     void heapSortPushDown( QPtrCollection::Item* heap, int first, int last );
00131 
00132     QLNode *firstNode;                          // first node
00133     QLNode *lastNode;                           // last node
00134     QLNode *curNode;                            // current node
00135     int curIndex;                               // current index
00136     uint numNodes;                              // number of nodes
00137     QGListIteratorList *iterators;              // list of iterators
00138 
00139     QLNode *locate( uint );                     // get node at i'th pos
00140     QLNode *unlink();                           // unlink node
00141 };
00142 
00143 
00144 inline uint QGList::count() const
00145 {
00146     return numNodes;
00147 }
00148 
00149 inline bool QGList::removeFirst()
00150 {
00151     first();
00152     return remove();
00153 }
00154 
00155 inline bool QGList::removeLast()
00156 {
00157     last();
00158     return remove();
00159 }
00160 
00161 inline int QGList::at() const
00162 {
00163     return curIndex;
00164 }
00165 
00166 inline QPtrCollection::Item QGList::at( uint index )
00167 {
00168     QLNode *n = locate( index );
00169     return n ? n->data : 0;
00170 }
00171 
00172 inline QLNode *QGList::currentNode() const
00173 {
00174     return curNode;
00175 }
00176 
00177 inline QPtrCollection::Item QGList::get() const
00178 {
00179     return curNode ? curNode->data : 0;
00180 }
00181 
00182 inline QPtrCollection::Item QGList::cfirst() const
00183 {
00184     return firstNode ? firstNode->data : 0;
00185 }
00186 
00187 inline QPtrCollection::Item QGList::clast() const
00188 {
00189     return lastNode ? lastNode->data : 0;
00190 }
00191 
00192 
00193 /*****************************************************************************
00194   QGList stream functions
00195  *****************************************************************************/
00196 
00197 #ifndef QT_NO_DATASTREAM
00198 Q_EXPORT QDataStream &operator>>( QDataStream &, QGList & );
00199 Q_EXPORT QDataStream &operator<<( QDataStream &, const QGList & );
00200 #endif
00201 
00202 /*****************************************************************************
00203   QGListIterator class
00204  *****************************************************************************/
00205 
00206 class Q_EXPORT QGListIterator                   // QGList iterator
00207 {
00208 friend class QGList;
00209 friend class QGListIteratorList;
00210 protected:
00211     QGListIterator( const QGList & );
00212     QGListIterator( const QGListIterator & );
00213     QGListIterator &operator=( const QGListIterator & );
00214    ~QGListIterator();
00215 
00216     bool  atFirst() const;                      // test if at first item
00217     bool  atLast()  const;                      // test if at last item
00218     QPtrCollection::Item          toFirst();                            // move to first item
00219     QPtrCollection::Item          toLast();                             // move to last item
00220 
00221     QPtrCollection::Item          get() const;                          // get current item
00222     QPtrCollection::Item          operator()();                         // get current and move to next
00223     QPtrCollection::Item          operator++();                         // move to next item (prefix)
00224     QPtrCollection::Item          operator+=(uint);                     // move n positions forward
00225     QPtrCollection::Item          operator--();                         // move to prev item (prefix)
00226     QPtrCollection::Item          operator-=(uint);                     // move n positions backward
00227 
00228 protected:
00229     QGList *list;                               // reference to list
00230 
00231 private:
00232     QLNode  *curNode;                           // current node in list
00233 };
00234 
00235 
00236 inline bool QGListIterator::atFirst() const
00237 {
00238     return curNode == list->firstNode;
00239 }
00240 
00241 inline bool QGListIterator::atLast() const
00242 {
00243     return curNode == list->lastNode;
00244 }
00245 
00246 inline QPtrCollection::Item QGListIterator::get() const
00247 {
00248     return curNode ? curNode->data : 0;
00249 }
00250 
00251 
00252 #endif  // QGLIST_H

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