QValueListIterator(3qt)

NAME
QValueListIterator - Iterator for

#include <qvaluelist.h>

  Public Members
QValueListIterator ()
QValueListIterator ( NodePtr p )
QValueListIterator ( const QValueListIterator<T> & it )
bool operator== ( const QValueListIterator<T> & it ) const
bool operator!= ( const QValueListIterator<T> & it ) const
const T& operator* () const
T& operator* ()
QValueListIterator<T>& operator++ ()
QValueListIterator<T> operator++ ( int )
QValueListIterator<T>& operator-- ()
QValueListIterator<T> operator-- ( int )

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.

SEE ALSO
http://doc.trolltech.com/qvaluelistiterator.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports make our job much simpler. Thank you.

In case of content or formattting problems with this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qvaluelistiterator.3qt) and the Qt version (2.3.5).