Blame qtools/qlist.h

Packit 1c1d7e
/****************************************************************************
Packit 1c1d7e
** 
Packit 1c1d7e
**
Packit 1c1d7e
** Definition of QList template/macro class
Packit 1c1d7e
**
Packit 1c1d7e
** Created : 920701
Packit 1c1d7e
**
Packit 1c1d7e
** Copyright (C) 1992-2000 Trolltech AS.  All rights reserved.
Packit 1c1d7e
**
Packit 1c1d7e
** This file is part of the tools module of the Qt GUI Toolkit.
Packit 1c1d7e
**
Packit 1c1d7e
** This file may be distributed under the terms of the Q Public License
Packit 1c1d7e
** as defined by Trolltech AS of Norway and appearing in the file
Packit 1c1d7e
** LICENSE.QPL included in the packaging of this file.
Packit 1c1d7e
**
Packit 1c1d7e
** This file may be distributed and/or modified under the terms of the
Packit 1c1d7e
** GNU General Public License version 2 as published by the Free Software
Packit 1c1d7e
** Foundation and appearing in the file LICENSE.GPL included in the
Packit 1c1d7e
** packaging of this file.
Packit 1c1d7e
**
Packit 1c1d7e
** Licensees holding valid Qt Enterprise Edition or Qt Professional Edition
Packit 1c1d7e
** licenses may use this file in accordance with the Qt Commercial License
Packit 1c1d7e
** Agreement provided with the Software.
Packit 1c1d7e
**
Packit 1c1d7e
** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
Packit 1c1d7e
** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
Packit 1c1d7e
**
Packit 1c1d7e
** See http://www.trolltech.com/pricing.html or email sales@trolltech.com for
Packit 1c1d7e
**   information about Qt Commercial License Agreements.
Packit 1c1d7e
** See http://www.trolltech.com/qpl/ for QPL licensing information.
Packit 1c1d7e
** See http://www.trolltech.com/gpl/ for GPL licensing information.
Packit 1c1d7e
**
Packit 1c1d7e
** Contact info@trolltech.com if any conditions of this licensing are
Packit 1c1d7e
** not clear to you.
Packit 1c1d7e
**
Packit 1c1d7e
**********************************************************************/
Packit 1c1d7e
Packit 1c1d7e
/* This is a stripped version of the original QList, which has been renamed to
Packit 1c1d7e
   QInternalList. This implementation doesn't expose the current node and index,
Packit 1c1d7e
   nor direct access to the list nodes.
Packit 1c1d7e
   This makes it possible to have more constant methods. It also provides
Packit 1c1d7e
   a typesafe method to compare elements called compareValues() and a typesafe
Packit 1c1d7e
   methods to create and delete elements called newValue() and deleteValue().
Packit 1c1d7e
 */
Packit 1c1d7e
Packit 1c1d7e
#ifndef QLIST_H
Packit 1c1d7e
#define QLIST_H
Packit 1c1d7e
Packit 1c1d7e
#ifndef QT_H
Packit 1c1d7e
#include "qglist.h"
Packit 1c1d7e
#endif // QT_H
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
template<class type> class Q_EXPORT QList : private QGList
Packit 1c1d7e
{
Packit 1c1d7e
public:
Packit 1c1d7e
    QList()				{}
Packit 1c1d7e
    QList( const QList<type> &l ) : QGList(l) {}
Packit 1c1d7e
   ~QList()				{ clear(); }
Packit 1c1d7e
    QList<type> &operator=(const QList<type> &l)
Packit 1c1d7e
			{ return (QList<type>&)QGList::operator=(l); }
Packit 1c1d7e
    bool operator==( const QList<type> &list ) const
Packit 1c1d7e
    { return QGList::operator==( list ); }
Packit 1c1d7e
Packit 1c1d7e
    // capacity
Packit 1c1d7e
    uint  count()   const		{ return QGList::count(); }
Packit 1c1d7e
    bool  isEmpty() const		{ return QGList::count() == 0; }
Packit 1c1d7e
Packit 1c1d7e
    // modifiers add
Packit 1c1d7e
    bool  insert( uint i, const type *d){ return QGList::insertAt(i,(QCollection::Item)d); }
Packit 1c1d7e
    void  inSort( const type *d )	{ QGList::inSort((QCollection::Item)d); }
Packit 1c1d7e
    void  prepend( const type *d )	{ QGList::insertAt(0,(QCollection::Item)d); }
Packit 1c1d7e
    void  append( const type *d )	{ QGList::append((QCollection::Item)d); }
Packit 1c1d7e
Packit 1c1d7e
    // modifiers remove
Packit 1c1d7e
    bool  remove( uint i )		{ return QGList::removeAt(i); }
Packit 1c1d7e
    bool  remove( const type *d )	{ return QGList::remove((QCollection::Item)d); }
Packit 1c1d7e
    bool  removeRef( const type *d )	{ return QGList::removeRef((QCollection::Item)d); }
Packit 1c1d7e
    bool  removeFirst()			{ return QGList::removeFirst(); }
Packit 1c1d7e
    bool  removeLast()			{ return QGList::removeLast(); }
Packit 1c1d7e
    type *take( uint i )		{ return (type *)QGList::takeAt(i); }
Packit 1c1d7e
    void  clear()			{ QGList::clear(); }
Packit 1c1d7e
Packit 1c1d7e
    // operations
Packit 1c1d7e
    void  sort()			{ QGList::sort(); }
Packit 1c1d7e
Packit 1c1d7e
    // search
Packit 1c1d7e
    int	  find( const type *d ) const	 { return const_cast<QList<type>*>(this)->QGList::find((QCollection::Item)d); }
Packit 1c1d7e
    int	  findRef( const type *d ) const { return const_cast<QList<type>*>(this)->QGList::findRef((QCollection::Item)d); }
Packit 1c1d7e
    uint  contains( const type *d ) const { return QGList::contains((QCollection::Item)d); }
Packit 1c1d7e
    uint  containsRef( const type *d ) const { return QGList::containsRef((QCollection::Item)d); }
Packit 1c1d7e
Packit 1c1d7e
    // element access
Packit 1c1d7e
    type *at( uint i ) const		{ return (type *)const_cast<QList<type>*>(this)->QGList::at(i); }
Packit 1c1d7e
    type *getFirst() const		{ return (type *)QGList::cfirst(); }
Packit 1c1d7e
    type *getLast()  const		{ return (type *)QGList::clast(); }
Packit 1c1d7e
Packit 1c1d7e
    // ownership
Packit 1c1d7e
    void setAutoDelete( bool enable )   { QGList::setAutoDelete(enable); }
Packit 1c1d7e
Packit 1c1d7e
private:
Packit 1c1d7e
    // new to be reimplemented methods
Packit 1c1d7e
    virtual int compareValues(const type *t1,const type *t2) const
Packit 1c1d7e
    { return const_cast<QList<type>*>(this)->QGList::compareItems((QCollection::Item)t1,(QCollection::Item)t2); }
Packit 1c1d7e
    virtual type *newValue(type *item) const
Packit 1c1d7e
    { return item; }
Packit 1c1d7e
    virtual void deleteValue(type *item) const
Packit 1c1d7e
    { if (del_item) delete item; }
Packit 1c1d7e
Packit 1c1d7e
    // reimplemented methods
Packit 1c1d7e
    virtual Item newItem( Item item)
Packit 1c1d7e
    { return (Item)newValue((type*)item); }
Packit 1c1d7e
    virtual void deleteItem( QCollection::Item item )
Packit 1c1d7e
    { deleteValue((type *)item); }
Packit 1c1d7e
    virtual int compareItems(QCollection::Item i1,QCollection::Item i2)
Packit 1c1d7e
    { return compareValues((const type*)i1,(const type*)i2); }
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
#if defined(Q_DELETING_VOID_UNDEFINED)
Packit 1c1d7e
template<> inline void QList<void>::deleteValue(void *) const
Packit 1c1d7e
{
Packit 1c1d7e
}
Packit 1c1d7e
#endif
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
template<class type> class Q_EXPORT QListIterator : public QGListIterator
Packit 1c1d7e
{
Packit 1c1d7e
public:
Packit 1c1d7e
    QListIterator(const QList<type> &l) :QGListIterator((QGList &)l) {}
Packit 1c1d7e
   ~QListIterator()	      {}
Packit 1c1d7e
    uint  count()   const     { return list->count(); }
Packit 1c1d7e
    bool  isEmpty() const     { return list->count() == 0; }
Packit 1c1d7e
    bool  atFirst() const     { return QGListIterator::atFirst(); }
Packit 1c1d7e
    bool  atLast()  const     { return QGListIterator::atLast(); }
Packit 1c1d7e
    type *toFirst()	      { return (type *)QGListIterator::toFirst(); }
Packit 1c1d7e
    type *toLast()	      { return (type *)QGListIterator::toLast(); }
Packit 1c1d7e
    operator type *() const   { return (type *)QGListIterator::get(); }
Packit 1c1d7e
    type *operator*()         { return (type *)QGListIterator::get(); }
Packit 1c1d7e
Packit 1c1d7e
    // No good, since QList<char> (ie. QStrList fails...
Packit 1c1d7e
    //
Packit 1c1d7e
    // MSVC++ gives warning
Packit 1c1d7e
    // Sunpro C++ 4.1 gives error
Packit 1c1d7e
    //    type *operator->()        { return (type *)QGListIterator::get(); }
Packit 1c1d7e
Packit 1c1d7e
    type *current()   const   { return (type *)QGListIterator::get(); }
Packit 1c1d7e
    type *operator()()	      { return (type *)QGListIterator::operator()();}
Packit 1c1d7e
    type *operator++()	      { return (type *)QGListIterator::operator++(); }
Packit 1c1d7e
    type *operator+=(uint j)  { return (type *)QGListIterator::operator+=(j);}
Packit 1c1d7e
    type *operator--()	      { return (type *)QGListIterator::operator--(); }
Packit 1c1d7e
    type *operator-=(uint j)  { return (type *)QGListIterator::operator-=(j);}
Packit 1c1d7e
    QListIterator<type>& operator=(const QListIterator<type>&it)
Packit 1c1d7e
			      { QGListIterator::operator=(it); return *this; }
Packit 1c1d7e
};
Packit 1c1d7e
Packit 1c1d7e
Packit 1c1d7e
#endif // QLIST_H