Go to the first, previous, next, last section, table of contents.


CNDLIterator -- Iterator of Doubly Linked List

SYNOPSIS

#include <CNCL/DLIterator.h>

TYPE

CN_DLITERATOR

BASE CLASSES

CNSLIterator

DERIVED CLASSES

None

RELATED CLASSES

CNDLList, CNDLObject

DESCRIPTION

CNDLIterator is an iterator to traverse a CNDLList doubly linked list.

Constructors:

CNDLIterator();
CNDLIterator(CNParam *param);
Initializes CNDLIterator.
CNDLIterator(const CNDLList *new_list);
CNDLIterator(const CNDLList &new_list);
Initializes CNDLIterator with linked list list. The iterator is reset to the first element in the list.

In addition to the member functions required by CNCL, CNDLIterator provides or defines more efficiently:

void reset(const CNDLList *new_list);
void reset(const CNDLList &new_list);
void reset();
Resets the iterator to a new list new_list and/or sets the iterator to the first element in the list.
CNDLObject *position()
CNDLObject *get_position()
Gets the current iterator position (node in the list). It returns a pointer to the node or NIL, if none is available.
void position(CNDLObject *pos)
void set_position(CNDLObject *pos)
Moves the iterator to the referenced node in the list.
CNObject *last_object();
CNObject *last();
Sets the iterator to the last element in the list. It returns the referenced object or NIL, if none is available.
CNObject *prev_object();
CNObject *prev();
CNObject *operator --();
CNObject *operator --(int);
Moves the iterator to the previous element in the list. It returns the current referenced object (the one BEFORE moving the iterator) or NIL, if none is available.

The following examples show how to use a CNDLIterator object to traverse a linked list:

Forward:

CNDLList list;

...

CNDLIterator trav(list);
CNObject *obj;

while(obj = trav++)
{
    // Do something with obj ...
}

Alternate forward:

for(trav.reset(list); obj=trav.object(); trav.next())
{
    // ...
}

Backward:

for(trav.last(); obj=trav.object(); trav--)
{
    // ...
}


Go to the first, previous, next, last section, table of contents.