#include <QoreListNode.h>
Public Member Functions | |
DLLEXPORT | ListIterator (QoreListNode *lst, qore_size_t n_pos=-1) |
initializes the iterator to the position given or, if omitted, just before the first element | |
DLLEXPORT bool | next () |
moves the iterator to the next element, returns true if the iterator is pointing to an element of the list | |
DLLEXPORT bool | prev () |
moves the iterator to the previous element, returns true if the iterator is pointing to an element of the list | |
DLLEXPORT int | set (qore_size_t n_pos) |
sets the iterator to a specific position in the list | |
DLLEXPORT AbstractQoreNode * | getValue () const |
returns a pointer to the value of the list element | |
DLLEXPORT AbstractQoreNode ** | getValuePtr () const |
returns a pointer to a pointer of the value of the list element, so it can be changed externally | |
DLLEXPORT AbstractQoreNode * | getReferencedValue () const |
returns the current value with an incremented reference count | |
DLLEXPORT bool | first () const |
returns true when the iterator is pointing to the first element in the list | |
DLLEXPORT bool | last () const |
returns true when the iterator is pointing to the last element in the list | |
DLLLOCAL qore_size_t | index () const |
returns the current iterator position in the list |
// iterate forward through the list ListIterator li(l); while (li.next()) { QoreStringValueHelper str(li.getValue()); printf("%d: '%s'\n", li.index(), str->getBuffer()); }
// iterate backwards through the list ListIterator li(l); while (li.prev()) { QoreStringValueHelper str(li.getValue()); printf("%d: '%s'\n", li.index(), str->getBuffer()); }
DLLEXPORT ListIterator::ListIterator | ( | QoreListNode * | lst, | |
qore_size_t | n_pos = -1 | |||
) |
DLLEXPORT bool ListIterator::next | ( | ) |
moves the iterator to the next element, returns true if the iterator is pointing to an element of the list
if the iterator is on the last element, it moves to an invalid position before the first element and returns false note that a subsequent call to next() after it returns false will move the iterator to the first element again (assuming there is at least one element in the list)
DLLEXPORT bool ListIterator::prev | ( | ) |
moves the iterator to the previous element, returns true if the iterator is pointing to an element of the list
if the iterator is on the first element, it moves to an invalid position before the first element and returns false note that a subsequent call to prev() after it returns false will move the iterator to the last element again (assuming there is at least one element in the list)
DLLEXPORT int ListIterator::set | ( | qore_size_t | n_pos | ) |
sets the iterator to a specific position in the list
In the case an invalid position is given (element not present in the list), the iterator will not be pointing to a valid element in the list
n_pos | the position in the list to set (first element is position 0) |