CopperSpice API  1.9.2
QFlatMapIterator< Key, Val, C > Class Template Reference

The QFlatMapIterator class provides a Java style const iterator for QFlatMap. More...

Public Methods

 QFlatMapIterator (const QFlatMap< Key, Val, C > &flatmap)
 
 ~QFlatMapIterator () = default
 
bool findNext (const Val &value)
 
bool findPrevious (const Val &value)
 
bool hasNext () const
 
bool hasPrevious () const
 
const Key & key () const
 
Item next ()
 
QFlatMapIterator & operator= (const QFlatMap< Key, Val, C > &flatmap)
 
Item peekNext () const
 
Item peekPrevious () const
 
Item previous ()
 
void toBack ()
 
void toFront ()
 
const Val & value () const
 

Detailed Description

template<class Key, class Val, class C = qMapCompare<Key>>
class QFlatMapIterator< Key, Val, C >

The QFlatMapIterator class provides a Java style const iterator for QFlatMap. QFlatMap has both Java style iterators and STL style iterators.

After construction the iterator is located at the very beginning of the map, before the first item. The following code shows how to iterate over all the elements sequentially.

while (iter.hasNext()) {
iter.next();
qDebug() << iter.key() << ": " << iter.value();
}

The next() method returns the next item in the flat map and advances the iterator. The key() and value() methods return the (key, value) pair of the last item that was jumped over.

Unlike STL style iterators, Java style iterators point between items rather than directly at items. The first call to next() advances the iterator to the position between the first and second item, and returns the first item; the second call to next() advances the iterator to the position between the second and third item, and so on.

Here is how to iterate over the elements in reverse order:

iter.toBack();
while (iter.hasPrevious()) {
iter.previous();
qDebug() << iter.key() << ": " << iter.value();
}

If you want to find all occurrences of a particular value use findNext() or findPrevious().

while (iter.findNext(widget)) {
qDebug() << "Found widget " << widget << " under key " << iter.key();
}
See also
QMutableMapIterator

Constructor & Destructor Documentation

template<class Key , class Val , class C = qMapCompare<Key>>
QFlatMapIterator< Key, Val, C >::QFlatMapIterator ( const QFlatMap< Key, Val, C > &  flatmap)
inline

Constructs an iterator for traversing flatmap. The iterator is set to the beginning of the flat map before the first item.

See also
operator=()
template<class Key , class Val , class C = qMapCompare<Key>>
QFlatMapIterator< Key, Val, C >::~QFlatMapIterator ( )
default

Destroys the iterator.

See also
operator=()

Method Documentation

template<class Key , class Val , class C = qMapCompare<Key>>
bool QFlatMapIterator< Key, Val, C >::findNext ( const Val &  value)
inline

Searches for value starting from the current iterator position and moving forward. Returns true if a (key, value) pair with the specified value is found, otherwise it returns false. If value is found the iterator is positioned just after the matching item, otherwise the iterator is positioned at the end of the container.

See also
findPrevious()
template<class Key , class Val , class C = qMapCompare<Key>>
bool QFlatMapIterator< Key, Val, C >::findPrevious ( const Val &  value)
inline

Searches for value starting from the current iterator position and moving backward. Returns true if a (key, value) pair with the specified value is found, otherwise it returns false. If value was found the iterator is positioned just before the matching item. Otherwise the iterator is positioned at the beginning of the container.

See also
findNext()
template<class Key , class Val , class C = qMapCompare<Key>>
bool QFlatMapIterator< Key, Val, C >::hasNext ( ) const
inline

Returns true if there is at least one item after the iterator, otherwise returns false.

See also
hasPrevious(), next()
template<class Key , class Val , class C = qMapCompare<Key>>
bool QFlatMapIterator< Key, Val, C >::hasPrevious ( ) const
inline

Returns true if there is at least one item before the iterator, otherwise returns false.

See also
hasNext(), previous()
template<class Key , class Val , class C = qMapCompare<Key>>
const Key & QFlatMapIterator< Key, Val, C >::key ( ) const
inline

Returns a reference for the key of the last item that was jumped over using one of the traversal methods next(), previous(), findNext(), findPrevious(). After a call to next() or findNext(), key() is equivalent to peekPrevious().key(). After a call to previous() or findPrevious(), key() is equivalent to peekNext().key().

See also
value()
template<class Key , class Val , class C = qMapCompare<Key>>
Item QFlatMapIterator< Key, Val, C >::next ( )
inline

Returns the next item and advances the iterator by one position. Call key() on the return value to obtain the key or call value() to obtain the value.

Calling this method on an iterator located at the end of the container causes undefined behavior.

See also
hasNext(), previous(), peekNext()
template<class Key , class Val , class C = qMapCompare<Key>>
QFlatMapIterator & QFlatMapIterator< Key, Val, C >::operator= ( const QFlatMap< Key, Val, C > &  flatmap)
inline

Sets the iterator to the beginning of the flatmap before the first item.

See also
toFront(), toBack()
template<class Key , class Val , class C = qMapCompare<Key>>
Item QFlatMapIterator< Key, Val, C >::peekNext ( ) const
inline

Returns the next item without moving the iterator. Call key() on the return value to obtain the key or call value() to obtain the value.

Calling this method on an iterator located at the end of the container causes undefined behavior.

See also
hasNext(), next(), peekPrevious()
template<class Key , class Val , class C = qMapCompare<Key>>
Item QFlatMapIterator< Key, Val, C >::peekPrevious ( ) const
inline

Returns the next item and advances the iterator by one position. Call key() on the return value to obtain the key or call value() to obtain the value.

Calling this method on an iterator located at the beginning of the container causes undefined behavior..

See also
hasPrevious(), previous(), peekNext()
template<class Key , class Val , class C = qMapCompare<Key>>
Item QFlatMapIterator< Key, Val, C >::previous ( )
inline

Returns the previous item and moves the iterator back by one position. Call key() on the return value to obtain the key or call value() to obtain the value.

Calling this method on an iterator located at the beginning of the container causes undefined behavior..

See also
hasPrevious(), peekPrevious(), next()
template<class Key , class Val , class C = qMapCompare<Key>>
void QFlatMapIterator< Key, Val, C >::toBack ( )
inline

Moves the iterator to the end of the container after the last item.

See also
toFront(), previous()
template<class Key , class Val , class C = qMapCompare<Key>>
void QFlatMapIterator< Key, Val, C >::toFront ( )
inline

Moves the iterator to the beginning of the container before the first item.

See also
toBack(), next()
template<class Key , class Val , class C = qMapCompare<Key>>
const Val & QFlatMapIterator< Key, Val, C >::value ( ) const
inline

Returns a reference for the value of the last item that was jumped over using one of the traversal methods next(), previous(), findNext(), findPrevious(). After a call to next() or findNext(), value() is equivalent to peekPrevious().value(). After a call to previous() or findPrevious(), value() is equivalent to peekNext().value().

See also
key()