Qmap iterator--QMAPITERATOR_QT

Source: Internet
Author: User
Qmapiterator Class

Qmap iterator, look at the time, by the way translated.

The Qmapiterator class provides a Java-style constant iterator.

Header:

#include <QMapIterator>

Qmake:

QT + Core

§ A list of public function members, including inherited members. Public functions

Qmapiterator (const Qmap<key, t> & map)

bool

FindNext (const T & value)

bool

FindPrevious (const T & value)

bool

Hasnext () const

bool

Hasprevious () const

Const Key &

Key () const

Item

Next ()

Item

PeekNext () const

Item

Peekprevious () const

Item

Previous ()

void

Toback ()

void

Tofront ()

Const T &

Value () const

Qmapiterator &

operator= (const Qmap<key, t> & map) Detailed description

The Qmapiterator class is Qmap and Qmultimap, providing a Java-style constant iterator.

Qmap has Java-style iterators and STL-style iterators. Java-style iterators are more advanced and useful than STL-style iterators, but they are less efficient than STL-style iterators.

Using Qmapiterator<key, t> an qmap (or a qmultimap) iteration. You need to use qmutablemapiterator when you need to be able to modify the map at iteration time.

The constructor of the Qmutablemapiterator iterator takes a qmap as an argument. When the construct is complete, the iterator is at the beginning of the map (before the first item in the table). The following code describes how to iterate through all the elements in sequence.


Qmap<int, Qwidget *> map;
Qmapiterator<int, Qwidget *> i (map);
while (I.hasnext ()) {
i.next ();
Qdebug () << i.key () << ":" << i.value ();
}

The next () function returns the next item in the map. The key () and value () functions return the keys and values (value) of the previous item

Unlike STL-style iterators, Java-style iterators are directed between projects rather than items in the map. The first call to next (), the iterator points to the first and second items, returns the first item, the second call to next (), the iterator points to the second and third items, returns the second item, and so on.

Here's how to reverse iterate through the element items in the map.

Qmapiterator<int, Qwidget *> i (map);
I.toback ();
while (I.hasprevious ()) {
i.previous ();
Qdebug () << i.key () << ":" << i.value ();
}

If you want to traverse a table, you can use FindNext () or findprevious () in the loop, for example:

Qmapiterator<int, Qwidget *> i (map);
I.toback ();
while (I.hasprevious ()) {
i.previous ();
Qdebug () << i.key () << ":" << i.value ();
}

Multiple iterators can be used on the same map. If the map is modified when a qmapiterator is used, the Qmapiterator continues to iterate according to the original table, and the modified item is ignored.

Also Qmutablemapiterator and Qmap::const_iterator. member functions detailed Qmapiterator:: Qmapiterator (const Qmap<key, t> & map)

Constructs an iterator for traversing map. The iterator is set to being at the front of the the map (before the "the").

also Operator= (). BOOL Qmapiterator:: FindNext (const T & value)

Searches for value starting from the current iterator position forward. Returns true if a (key, value) pair with value value is found; otherwise returns false.

After the call, if value was found, the iterator are positioned just after the matching item; Otherwise, the iterator is positioned in the back of the container.

also FindPrevious (). BOOL Qmapiterator:: findprevious (const T & value)

Searches for value starting from the current iterator position backward. Returns true if a (key, value) pair with value value is found; otherwise returns false.

After the call, if value was found, the iterator is positioned just before the matching item; Otherwise, the iterator is positioned at the front of the container.

also FindNext (). BOOL Qmapiterator:: Hasnext () const

Returns true if there is at least one item ahead of the iterator, i.e. the iterator was not in the back of the container; otherwise returnsfalse.

also Hasprevious () and Next (). BOOL Qmapiterator:: hasprevious () const

Returns true if there is at least one item behind the iterator, i.e. the iterator of the front; otherwise returnsfalse.

also Hasnext () and previous (). Const Key & Qmapiterator:: Key () const

Returns the key of the last item this is jumped over using one of the traversal functions (next (), previous (), FindNext () , FindPrevious ()).

After a call to next () or FindNext (), the key () is equivalent to Peekprevious (). Key (). After a call to previous () or findprevious (), the key () is equivalent to PeekNext (). Key ().

also value (). Item Qmapiterator:: Next ()

Returns the next item and advances the iterator by one position.

Call key () on the "return value" to obtain the item ' s key, and value () to obtain the value.

Calling this function on a iterator located at the "back of" container leads to undefined results.

also Hasnext (), PeekNext (), and previous (). Item qmapiterator:: PeekNext () const

Returns the next item without moving the iterator.

Call key () on the "return value" to obtain the item ' s key, and value () to obtain the value.

Calling this function on a iterator located at the "back of" container leads to undefined results.

also Hasnext (), Next (), and peekprevious (). Item qmapiterator:: peekprevious () const

Returns the previous item without moving the iterator.

Call key () on the "return value" to obtain the item ' s key, and value () to obtain the value.

Calling this function on a iterator located at the front of the container leads to undefined.

also Hasprevious (), Previous (), and PeekNext (). Item Qmapiterator:: Previous ()

Returns the previous item and moves the iterator back by one position.

Call key () on the "return value" to obtain the item ' s key, and value () to obtain the value.

Calling this function on a iterator located at the front of the container leads to undefined.

also Hasprevious (), peekprevious (), and Next (). void Qmapiterator:: Toback ()

Moves the iterator to the "back of" the container (after the last item).

also Tofront () and previous (). void Qmapiterator:: Tofront ()

Moves the iterator to the front of the container (before the "the").

also Toback () and Next (). Const T & Qmapiterator:: Value () const

Returns the value of the last item this is jumped over using one of the traversal functions (next (), previous (), FindNext (), FindPrevious ()).

After a call to next () or FindNext (), the value () is equivalent to Peekprevious (). Value (). After a call to previous () or findprevious (), the value () is equivalent to PeekNext (). Value ().

also key (). Qmapiterator & Qmapiterator:: operator= (const Qmap<key, t> & map)

Makes the iterator operate on map. The iterator is set to being at the front of the the map (before the "the").

also Tofront () and Toback ().

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.