class iterator
This is the built-in iterator class.
Iterators are used to sequentially navigate over lists and examine their items. To create an iterator for a list, you can just initialize an iterator variable with a list object:
list myList = new list(); myList.add("hello", "Hello World!"); for( iterator it = myList; it.valid; it.next() ) { println(it.value); }
Constructors
iterator (list) | Constructs a new iterator for the specified list. |
iterator (const iterator) | Copy-constructs a new iterator from an existing one. |
Methods
delete () | Deletes the item currently referenced by the iterator. |
first () | Moves the iterator to the beginning of the list. |
insert (const var, var) | Inserts a new item at the iterator's current position in the list. |
last () | Moves the iterator to the end of the list. |
next () | Moves the iterator to the next item in the list. |
prev () | Moves the iterator to the previous item in the list. |
Properties
int isFirst () | Returns true if the iterator is currently referencing the first item in the list. |
int isLast () | Returns true if the iterator is currently referencing the last item in the list. |
const var key () | Returns the currently referenced item's key. |
int valid () | Returns true if the iterator is currently valid. |
var value () | Returns the currently referenced item's value. |
value (var) | Sets the currently referenced item's value. |
Reference
method iterator (list) |
method iterator (const iterator) |
Copy-constructs a new iterator from an existing one. The new iterator will reference the same item from the same list as the specified iterator. |
method delete () |
Deletes the item currently referenced by the iterator. The item will not be deleted right away, but will be marked for deletion. It will get deleted once the iterator moves to a different item. If the iterator is currently invalid, this call has no effect. |
method first () |
method insert (const var key, var value) |
Inserts a new item at the iterator's current position in the list. If the iterator is currently invalid, this call has no effect. |
method last () |
method next () |
method prev () |
Moves the iterator to the previous item in the list. If there is no previous item, the iterator will become invalid. |
accessor int isFirst () |
Returns true if the iterator is currently referencing the first item in the list. |
accessor int isLast () |
Returns true if the iterator is currently referencing the last item in the list. |
accessor const var key () |
Returns the currently referenced item's key. If the iterator is currently invalid, returns null. |
accessor int valid () |
Returns true if the iterator is currently valid. If the iterator has moved beyond the beginning or end of the list, it will become invalid and this property will return false. |
accessor var value () |
Returns the currently referenced item's value. If the iterator is currently invalid, returns null. |
accessor value (var value) |
Sets the currently referenced item's value. If the iterator is currently invalid, this call has no effect. |