HomeHome

ClassesAnnotated - TreeFunctionsHomeStructure

QValueListIterator Class Reference


The QValueListIterator class provides an iterator for QValueList. More...

#include <qvaluelist.h>

List of all member functions.

Public Members


Detailed Description

The QValueListIterator class provides an iterator for QValueList.

You can not create an iterator by yourself. Instead you have to ask a list to give you one. An iterator has only the size of a pointer. On 32 bit machines that means 4 bytes otherwise 8 bytes. That makes them very fast. In fact they resemble the semantics of pointers as good as possible and they are almost as fast as usual pointers.

Example:

    #include <qvaluelist.h>
    #include <qstring.h>
    #include <stdio.h>

    class Employee
    {
    public:
        Employee(): s(0) {}
        Employee( const QString& name, int salary )
            : n(name), s(salary)
        {}

        QString     name()   const              { return n; }
        int         salary() const              { return s; }
        void        setSalary( int salary )     { s = salary; }
    private:
        QString     n;
        int         s;
    };

    void main()
        {
            typedef QValueList<Employee> EmployeeList;
            EmployeeList list;          // list of Employee

            list.append( Employee("Bill", 50000) );
            list.append( Employee("Steve",80000) );
            list.append( Employee("Ron",  60000) );

            Employee joe( "Joe", 50000 );
            list.append( joe );
            joe.setSalary( 4000 );

            EmployeeList::Iterator it;
            for( it = list.begin(); it != list.end(); ++it )
                printf( "%s earns %d\n", (*it).name().latin1(), (*it).salary() );
        }

Program output:

        Bill earns 50000
        Steve earns 80000
        Ron earns 60000
        Joe earns 50000

In contrast to QList there are no built in functions in QValueList to traverse the list. The only way to do this is to use iterators. QValueList is highly optimized for performance and memory usage. On the other hand that means that you have to be a bit more careful by what you are doing. QValueList does not know about all its iterators and the iterators dont even know to which list they belong. That makes things fast and slim but a bit dangerous because it is up to you to make sure that iterators you are using are still valid. QListIterator will be able to give warnings while QValueListIterator may end up in an undefined state.

For every Iterator there is a ConstIterator. When accessing a QValueList in a const environment or if the reference or pointer to the list is itself const, then you have to use the ConstIterator. Its semantics are the same, but it returns only const references to the item it points to.

See also QValueList and QValueListConstIterator.


Member Function Documentation

QValueListIterator::QValueListIterator ()

Creates un uninitialized iterator.

QValueListIterator::QValueListIterator ( NodePtr p )

Internal function.

QValueListIterator::QValueListIterator ( const QValueListIterator<T> & it )

Constructs a copy of the iterator it.

bool QValueListIterator::operator!= ( const QValueListIterator<T> & it ) const

Compares both iterators and returns TRUE if they point to different items.

T& QValueListIterator::operator* ()

Asterix operator. Returns a reference to the current iterator item.

const T& QValueListIterator::operator* () const

Asterix operator. Returns a reference to the current iterator item.

QValueListIterator<T> QValueListIterator::operator++ ( int )

Postfix ++ makes the succeeding item current and returns an iterator pointing to the new current item. The iterator can not check wether it reached the end of the list. Incrementing the iterator as returned by end() causes undefined results.

QValueListIterator<T>& QValueListIterator::operator++ ()

Prefix ++ makes the succeeding item current and returns an iterator pointing to the new current item. The iterator can not check wether it reached the end of the list. Incrementing the iterator as returned by end() causes undefined results.

QValueListIterator<T> QValueListIterator::operator-- ( int )

Postfix -- makes the previous item current and returns an iterator pointing to the new current item. The iterator can not check wether it reached the beginning of the list. Decrementing the iterator as returned by begin() causes undefined results.

QValueListIterator<T>& QValueListIterator::operator-- ()

Prefix -- makes the previous item current and returns an iterator pointing to the new current item. The iterator can not check wether it reached the beginning of the list. Decrementing the iterator as returned by begin() causes undefined results.

bool QValueListIterator::operator== ( const QValueListIterator<T> & it ) const

Compares both iterators and returns TRUE if they point to the same item.


Search the documentation, FAQ, qt-interest archive and more (uses www.trolltech.com):


This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.


Copyright © 2000 TrolltechTrademarks
Qt version 2.2.1