Qore Programming Language  1.12.0
ConstListIterator Class Reference

For use on the stack only: iterates through elements of a const QoreListNode. More...

#include <QoreListNode.h>

Inherited by QoreFunctionalListOperator, QoreFunctionalMapListOperator, QoreFunctionalMapSelectListOperator, QoreFunctionalSelectListOperator, and QoreListIterator.

Collaboration diagram for ConstListIterator:

Public Member Methods

DLLEXPORT ConstListIterator (const QoreListNode &lst, size_t n_pos=-1)
 initializes the iterator to the position given or, if omitted, just before the first element More...
 
DLLEXPORT ConstListIterator (const QoreListNode *lst, size_t n_pos=-1)
 initializes the iterator to the position given or, if omitted, just before the first element More...
 
DLLLOCAL bool empty () const
 returns true if the list is empty
 
DLLEXPORT bool first () const
 returns true when the iterator is pointing to the first element in the list
 
DLLLOCAL const QoreListNodegetList () const
 returns the list
 
DLLEXPORT QoreValue getReferencedValue () const
 returns the referenced value of the list element More...
 
DLLEXPORT const QoreValue getValue () const
 returns a pointer to the value of the list element
 
DLLLOCAL size_t index () const
 returns the current iterator position in the list or -1 if not pointing at a valid element
 
DLLEXPORT bool last () const
 returns true when the iterator is pointing to the last element in the list
 
DLLLOCAL size_t max () const
 returns the number of elements in the list
 
DLLEXPORT bool next ()
 moves the iterator to the next element, returns true if the iterator is pointing to an element of the list More...
 
DLLEXPORT bool prev ()
 moves the iterator to the previous element, returns true if the iterator is pointing to an element of the list More...
 
DLLEXPORT void reset ()
 resets the iterator to its initial state
 
DLLEXPORT int set (size_t n_pos)
 sets the iterator to a specific position in the list More...
 
DLLLOCAL bool valid () const
 returns true if the iterator is pointing to a valid element
 

Detailed Description

For use on the stack only: iterates through elements of a const QoreListNode.

// iterate forward through the list
while (li.next()) {
QoreStringValueHelper str(li.getValue());
printf("%d: '%s'\n", li.index(), str->getBuffer());
}
For use on the stack only: iterates through elements of a const QoreListNode.
Definition: QoreListNode.h:563
this class is used to safely manage calls to AbstractQoreNode::getStringRepresentation() when a simpl...
Definition: QoreStringNode.h:309
// iterate backwards through the list
while (li.prev()) {
QoreStringValueHelper str(li.getValue());
printf("%d: '%s'\n", li.index(), str->getBuffer());
}
See also
ListIterator

Constructor & Destructor Documentation

◆ ConstListIterator() [1/2]

DLLEXPORT ConstListIterator::ConstListIterator ( const QoreListNode lst,
size_t  n_pos = -1 
)

initializes the iterator to the position given or, if omitted, just before the first element

Parameters
lstthe list to iterate
n_posthe starting position (-1 means just before the first element so that the initial call to next() or prev() will put the iterator on the first element)

◆ ConstListIterator() [2/2]

DLLEXPORT ConstListIterator::ConstListIterator ( const QoreListNode lst,
size_t  n_pos = -1 
)

initializes the iterator to the position given or, if omitted, just before the first element

Parameters
lstthe list to iterate
n_posthe starting position (-1 means just before the first element so that the initial call to next() or prev() will put the iterator on the first element)

Member Function Documentation

◆ getReferencedValue()

DLLEXPORT QoreValue ConstListIterator::getReferencedValue ( ) const

returns the referenced value of the list element

Since
Qore 0.9

◆ next()

DLLEXPORT bool ConstListIterator::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)

Returns
returns true if the iterator has been moved to point to a valid element of the list, false if there are no more elements to iterate

◆ prev()

DLLEXPORT bool ConstListIterator::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)

Returns
returns true if the iterator has been moved to point to a valid element of the list, false if there are no more elements to iterate
Note
after this function returns false, do not use the iterator until it points to a valid element, otherwise a crash will result

◆ set()

DLLEXPORT int ConstListIterator::set ( 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

Parameters
n_posthe position in the list to set (first element is position 0)
Returns
0 for OK, -1 for invalid position
Note
if this function returns -1, do not use the iterator until it points to a valid element, otherwise a crash will result

The documentation for this class was generated from the following file: