Blame qtools/qglist.h

Packit Service 50c9f2
/****************************************************************************
Packit Service 50c9f2
** 
Packit Service 50c9f2
**
Packit Service 50c9f2
** Definition of QGList and QGListIterator classes
Packit Service 50c9f2
**
Packit Service 50c9f2
** Created : 920624
Packit Service 50c9f2
**
Packit Service 50c9f2
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is part of the tools module of the Qt GUI Toolkit.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed under the terms of the Q Public License
Packit Service 50c9f2
** as defined by Trolltech AS of Norway and appearing in the file
Packit Service 50c9f2
** LICENSE.QPL included in the packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file may be distributed and/or modified under the terms of the
Packit Service 50c9f2
** GNU General Public License version 2 as published by the Free Software
Packit Service 50c9f2
** Foundation and appearing in the file LICENSE.GPL included in the
Packit Service 50c9f2
** packaging of this file.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit Service 50c9f2
** licenses may use this file in accordance with the Qt Commercial License
Packit Service 50c9f2
** Agreement provided with the Software.
Packit Service 50c9f2
**
Packit Service 50c9f2
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit Service 50c9f2
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit Service 50c9f2
**
Packit Service 50c9f2
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit Service 50c9f2
**   information about Qt Commercial License Agreements.
Packit Service 50c9f2
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit Service 50c9f2
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit Service 50c9f2
**
Packit Service 50c9f2
** Contact info@trolltech.com if any conditions of this licensing are
Packit Service 50c9f2
** not clear to you.
Packit Service 50c9f2
**
Packit Service 50c9f2
**********************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QGLIST_H
Packit Service 50c9f2
#define QGLIST_H
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QT_H
Packit Service 50c9f2
#include "qcollection.h"
Packit Service 50c9f2
#endif // QT_H
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QLNode class (internal doubly linked list node)
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
class Q_EXPORT QLNode
Packit Service 50c9f2
{
Packit Service 50c9f2
friend class QGList;
Packit Service 50c9f2
friend class QGListIterator;
Packit Service 50c9f2
public:
Packit Service 50c9f2
    QCollection::Item getData()	{ return data; }
Packit Service 50c9f2
private:
Packit Service 50c9f2
    QCollection::Item data;
Packit Service 50c9f2
    QLNode *prev;
Packit Service 50c9f2
    QLNode *next;
Packit Service 50c9f2
    QLNode( QCollection::Item d ) { data = d; }
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QGList class
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
class Q_EXPORT QGList : public QCollection	// doubly linked generic list
Packit Service 50c9f2
{
Packit Service 50c9f2
friend class QGListIterator;
Packit Service 50c9f2
friend class QGVector;				// needed by QGVector::toList
Packit Service 50c9f2
public:
Packit Service 50c9f2
    uint  count() const;			// return number of nodes
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QT_NO_DATASTREAM
Packit Service 50c9f2
    QDataStream &read( QDataStream & );		// read list from stream
Packit Service 50c9f2
    QDataStream &write( QDataStream & ) const;	// write list to stream
Packit Service 50c9f2
#endif
Packit Service 50c9f2
protected:
Packit Service 50c9f2
    QGList();					// create empty list
Packit Service 50c9f2
    QGList( const QGList & );			// make copy of other list
Packit Service 50c9f2
    virtual ~QGList();
Packit Service 50c9f2
Packit Service 50c9f2
    QGList &operator=( const QGList & );	// assign from other list
Packit Service 50c9f2
    bool operator==( const QGList& ) const;
Packit Service 50c9f2
Packit Service 50c9f2
    void inSort( QCollection::Item );		// add item sorted in list
Packit Service 50c9f2
    void append( QCollection::Item );		// add item at end of list
Packit Service 50c9f2
    bool insertAt( uint index, QCollection::Item ); // add item at i'th position
Packit Service 50c9f2
    void relinkNode( QLNode * );		// relink as first item
Packit Service 50c9f2
    bool removeNode( QLNode * );		// remove node
Packit Service 50c9f2
    bool remove( QCollection::Item = 0 );	// remove item (0=current)
Packit Service 50c9f2
    bool removeRef( QCollection::Item = 0 );	// remove item (0=current)
Packit Service 50c9f2
    bool removeFirst();				// remove first item
Packit Service 50c9f2
    bool removeLast();				// remove last item
Packit Service 50c9f2
    bool removeAt( uint index );		// remove item at i'th position
Packit Service 50c9f2
    QCollection::Item takeNode( QLNode * );	// take out node
Packit Service 50c9f2
    QCollection::Item take();			// take out current item
Packit Service 50c9f2
    QCollection::Item takeAt( uint index );	// take out item at i'th pos
Packit Service 50c9f2
    QCollection::Item takeFirst();		// take out first item
Packit Service 50c9f2
    QCollection::Item takeLast();		// take out last item
Packit Service 50c9f2
Packit Service 50c9f2
    void sort();                        // sort all items;
Packit Service 50c9f2
    void clear();			// remove all items
Packit Service 50c9f2
Packit Service 50c9f2
    int	 findRef( QCollection::Item, bool = TRUE ); // find exact item in list
Packit Service 50c9f2
    int	 find( QCollection::Item, bool = TRUE ); // find equal item in list
Packit Service 50c9f2
Packit Service 50c9f2
    uint containsRef( QCollection::Item ) const; // get number of exact matches
Packit Service 50c9f2
    uint contains( QCollection::Item )	const;	// get number of equal matches
Packit Service 50c9f2
Packit Service 50c9f2
    QCollection::Item at( uint index );		// access item at i'th pos
Packit Service 50c9f2
    int	  at() const;				// get current index
Packit Service 50c9f2
    QLNode *currentNode() const;		// get current node
Packit Service 50c9f2
Packit Service 50c9f2
    QCollection::Item get() const;		// get current item
Packit Service 50c9f2
Packit Service 50c9f2
    QCollection::Item cfirst() const;	// get ptr to first list item
Packit Service 50c9f2
    QCollection::Item clast()  const;	// get ptr to last list item
Packit Service 50c9f2
    QCollection::Item first();		// set first item in list curr
Packit Service 50c9f2
    QCollection::Item last();		// set last item in list curr
Packit Service 50c9f2
    QCollection::Item next();		// set next item in list curr
Packit Service 50c9f2
    QCollection::Item prev();		// set prev item in list curr
Packit Service 50c9f2
Packit Service 50c9f2
    void  toVector( QGVector * ) const;		// put items in vector
Packit Service 50c9f2
Packit Service 50c9f2
    virtual int compareItems( QCollection::Item, QCollection::Item );
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QT_NO_DATASTREAM
Packit Service 50c9f2
    virtual QDataStream &read( QDataStream &, QCollection::Item & );
Packit Service 50c9f2
    virtual QDataStream &write( QDataStream &, QCollection::Item ) const;
Packit Service 50c9f2
#endif
Packit Service 50c9f2
private:
Packit Service 50c9f2
    void  prepend( QCollection::Item ); // add item at start of list
Packit Service 50c9f2
Packit Service 50c9f2
    void heapSortPushDown( QCollection::Item* heap, int first, int last );
Packit Service 50c9f2
Packit Service 50c9f2
    QLNode *firstNode;				// first node
Packit Service 50c9f2
    QLNode *lastNode;				// last node
Packit Service 50c9f2
    QLNode *curNode;				// current node
Packit Service 50c9f2
    int	    curIndex;				// current index
Packit Service 50c9f2
    uint    numNodes;				// number of nodes
Packit Service 50c9f2
    QGList *iterators;				// list of iterators
Packit Service 50c9f2
Packit Service 50c9f2
    QLNode *locate( uint );			// get node at i'th pos
Packit Service 50c9f2
    QLNode *unlink();				// unlink node
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
inline uint QGList::count() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return numNodes;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline bool QGList::removeFirst()
Packit Service 50c9f2
{
Packit Service 50c9f2
    first();
Packit Service 50c9f2
    return remove();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline bool QGList::removeLast()
Packit Service 50c9f2
{
Packit Service 50c9f2
    last();
Packit Service 50c9f2
    return remove();
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline int QGList::at() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return curIndex;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline QCollection::Item QGList::at( uint index )
Packit Service 50c9f2
{
Packit Service 50c9f2
    QLNode *n = locate( index );
Packit Service 50c9f2
    return n ? n->data : 0;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline QLNode *QGList::currentNode() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return curNode;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline QCollection::Item QGList::get() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return curNode ? curNode->data : 0;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline QCollection::Item QGList::cfirst() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return firstNode ? firstNode->data : 0;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline QCollection::Item QGList::clast() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return lastNode ? lastNode->data : 0;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QGList stream functions
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
#ifndef QT_NO_DATASTREAM
Packit Service 50c9f2
Q_EXPORT QDataStream &operator>>( QDataStream &, QGList & );
Packit Service 50c9f2
Q_EXPORT QDataStream &operator<<( QDataStream &, const QGList & );
Packit Service 50c9f2
#endif
Packit Service 50c9f2
Packit Service 50c9f2
/*****************************************************************************
Packit Service 50c9f2
  QGListIterator class
Packit Service 50c9f2
 *****************************************************************************/
Packit Service 50c9f2
Packit Service 50c9f2
class Q_EXPORT QGListIterator			// QGList iterator
Packit Service 50c9f2
{
Packit Service 50c9f2
friend class QGList;
Packit Service 50c9f2
protected:
Packit Service 50c9f2
    QGListIterator( const QGList & );
Packit Service 50c9f2
    QGListIterator( const QGListIterator & );
Packit Service 50c9f2
    QGListIterator &operator=( const QGListIterator & );
Packit Service 50c9f2
   ~QGListIterator();
Packit Service 50c9f2
Packit Service 50c9f2
    bool  atFirst() const;			// test if at first item
Packit Service 50c9f2
    bool  atLast()  const;			// test if at last item
Packit Service 50c9f2
    QCollection::Item	  toFirst();				// move to first item
Packit Service 50c9f2
    QCollection::Item	  toLast();				// move to last item
Packit Service 50c9f2
Packit Service 50c9f2
    QCollection::Item	  get() const;				// get current item
Packit Service 50c9f2
    QCollection::Item	  operator()();				// get current and move to next
Packit Service 50c9f2
    QCollection::Item	  operator++();				// move to next item (prefix)
Packit Service 50c9f2
    QCollection::Item	  operator+=(uint);			// move n positions forward
Packit Service 50c9f2
    QCollection::Item	  operator--();				// move to prev item (prefix)
Packit Service 50c9f2
    QCollection::Item	  operator-=(uint);			// move n positions backward
Packit Service 50c9f2
Packit Service 50c9f2
protected:
Packit Service 50c9f2
    QGList *list;				// reference to list
Packit Service 50c9f2
Packit Service 50c9f2
private:
Packit Service 50c9f2
    QLNode  *curNode;				// current node in list
Packit Service 50c9f2
};
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
inline bool QGListIterator::atFirst() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return curNode == list->firstNode;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline bool QGListIterator::atLast() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return curNode == list->lastNode;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
inline QCollection::Item QGListIterator::get() const
Packit Service 50c9f2
{
Packit Service 50c9f2
    return curNode ? curNode->data : 0;
Packit Service 50c9f2
}
Packit Service 50c9f2
Packit Service 50c9f2
Packit Service 50c9f2
#endif	// QGLIST_H