QMutableLinkedListIterator Class ReferenceThe QMutableLinkedListIterator class provides a Java-style non-const iterator for QLinkedList. Далее... #include <QMutableLinkedListIterator>
Открытые функции
Подробное описаниеThe QMutableLinkedListIterator class provides a Java-style non-const iterator for QLinkedList. QLinkedList has both Java-style iterators and STL-style iterators. Итераторы в стиле Java более высокоуровневые и простые в использовании, чем итераторы в стиле STL; с другой стороны, они несколько менее эффективны. QMutableLinkedListIterator<T> allows you to iterate over a QLinkedList<T> and modify the list. If you don't want to modify the list (or have a const QLinkedList), use the slightly faster QLinkedListIterator<T> instead. The QMutableLinkedListIterator constructor takes a QLinkedList as argument. After construction, the iterator is located at the very beginning of the list (before the first item). Вот, как последовательно перебрать все элементы: QLinkedList<float> list; ... QMutableLinkedListIterator<float> i(list); while (i.hasNext()) qDebug() << i.next(); The next() function returns the next item in the list and advances the iterator. В отличие от итераторов в стиле STL, итераторы в стиле Java указывают между элементами, а не на сами элементы. Первый вызов next() перемещает итератор в позицию между первым и вторым элементами и возвращает первый элемент; второй вызов next() перемещает итератор в позицию между вторым и третьим элементами, возвращая второй элемент; и т.д. Вот, как последовательно перебрать все элементы в обратном порядке: QMutableLinkedListIterator<float> i(list); i.toBack(); while (i.hasPrevious()) qDebug() << i.previous(); Если вы хотите найти все вхождения определённого значения, используйте findNext() или findPrevious() в цикле. If you want to remove items as you iterate over the list, use remove(). If you want to modify the value of an item, use setValue(). If you want to insert a new item in the list, use insert(). Пример: QMutableLinkedListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (val < 0) { i.setValue(-val); } else if (val == 0) { i.remove(); } } The example traverses a list, replacing negative numbers with their absolute values, and eliminating zeroes. Only one mutable iterator can be active on a given list at any time. Furthermore, no changes should be done directly to the list while the iterator is active (as opposed to through the iterator), since this could invalidate the iterator and lead to undefined behavior. See also QLinkedListIterator and QLinkedList::iterator. Описание функций-членовQMutableLinkedListIterator::QMutableLinkedListIterator ( QLinkedList<T> & list )Constructs an iterator for traversing list. The iterator is set to be at the front of the list (before the first item). Смотрите также operator=(). QMutableLinkedListIterator::~QMutableLinkedListIterator ()Destroys the iterator. Смотрите также operator=(). bool QMutableLinkedListIterator::findNext ( const T & value )Ищет вперед значение value, начиная с текущей позиции итератора. Возвращает true, если value найдено; в противном случае возвращает false. После вызова, если значение value было найдено, итератор устанавливается сразу после соответствующего элемента; в противном случае итератор устанавливается позади контейнера. Смотрите также findPrevious(). bool QMutableLinkedListIterator::findPrevious ( const T & value )Ищет назад значение value, начиная с текущей позиции итератора. Возвращает true, если value найдено; в противном случае возвращает false. После вызова, если значение value было найдено, итератор устанавливается сразу перед соответствующим элементом; в противном случае итератор устанавливается перед контейнером. Смотрите также findNext(). bool QMutableLinkedListIterator::hasNext () constВозвращает true, если есть хотя бы один элемент впереди итератора, т.е. итератор не позади контейнера; в противном случае возвращает false. Смотрите также hasPrevious() и next(). bool QMutableLinkedListIterator::hasPrevious () constВозвращает true, если есть хотя бы один элемент позади итератора, т.е. итератор не впереди контейнера; в противном случае возвращает false. Смотрите также hasNext() и previous(). void QMutableLinkedListIterator::insert ( const T & value )Inserts value at the current iterator position. After the call, the iterator is located just after the inserted item. See also remove() and setValue(). T & QMutableLinkedListIterator::next ()Returns a reference to the next item, and advances the iterator by one position. Вызов этой функции на итераторе, расположенном позади контейнера, приводит к неопределённым результатам. Смотрите также hasNext(), peekNext() и previous(). T & QMutableLinkedListIterator::peekNext () constReturns a reference to the next item, without moving the iterator. Вызов этой функции на итераторе, расположенном позади контейнера, приводит к неопределённым результатам. Смотрите также hasNext(), next() и peekPrevious(). T & QMutableLinkedListIterator::peekPrevious () constReturns a reference to the previous item, without moving the iterator. Вызов этой функции на итераторе, расположенном перед контейнером, приводит к неопределённым результатам. Смотрите также hasPrevious(), previous() и peekNext(). T & QMutableLinkedListIterator::previous ()Returns a reference to the previous item and moves the iterator back by one position. Вызов этой функции на итераторе, расположенном перед контейнером, приводит к неопределённым результатам. Смотрите также hasPrevious(), peekPrevious() и next(). void QMutableLinkedListIterator::remove ()Removes the last item that was jumped over using one of the traversal functions (next(), previous(), findNext(), findPrevious()). Пример: QMutableLinkedListIterator<int> i(list); while (i.hasNext()) { int val = i.next(); if (val < -32768 || val > 32767) i.remove(); } See also insert() and setValue(). void QMutableLinkedListIterator::setValue ( const T & value ) constReplaces the value of the last item that was jumped over using one of the traversal functions with value. The traversal functions are next(), previous(), findNext(), and findPrevious(). Пример: QMutableLinkedListIterator<double> i(list); while (i.hasNext()) { double val = i.next(); i.setValue(sqrt(val)); } See also value(), remove(), and insert(). void QMutableLinkedListIterator::toBack ()Перемещает итератор позади контейнера (после последнего элемента). Смотрите также toFront() и previous(). void QMutableLinkedListIterator::toFront ()Перемещает итератор впереди контейнера (перед первым элементом). Смотрите также toBack() и next(). const T & QMutableLinkedListIterator::value () constReturns the value of the last item that was jumped over using one of the traversal functions (next(), previous(), findNext(), findPrevious()). After a call to next() or findNext(), value() is equivalent to peekPrevious(). After a call to previous() or findPrevious(), value() is equivalent to peekNext(). Смотрите также setValue(). T & QMutableLinkedListIterator::value ()Это перегруженная функция. Returns a non-const reference to the value of the last item that was jumped over using one of the traversal functions. QMutableLinkedListIterator & QMutableLinkedListIterator::operator= ( QLinkedList<T> & list )Makes the iterator operate on list. The iterator is set to be at the front of the list (before the first item). |
Попытка перевода Qt документации. Если есть желание присоединиться, или если есть замечания или пожелания, то заходите на форум: Перевод Qt документации на русский язык... Люди внесшие вклад в перевод: Команда переводчиков |