PSCF v1.1
Public Member Functions | List of all members
Util::ListIterator< Data > Class Template Reference

Bidirectional iterator for a List. More...

#include <ListIterator.h>

Public Member Functions

 ListIterator ()
 Default constructor. More...
 
 ListIterator (List< Data > const &list)
 Constructor for initialized iterator. More...
 
void setCurrent (Node< Data > *nodePtr)
 Point the iterator at a Node. More...
 
bool isEnd () const
 Has the end of the list been reached? More...
 
bool isBack () const
 Is this the back of the List? More...
 
bool isFront () const
 Is this the front of the List? More...
 

Operators

Data const & operator* () const
 Get a const reference to the associated Data object. More...
 
Data & operator* ()
 Get the associated Data object. More...
 
Data const * operator-> () const
 Get a pointer to const to the associated Data object. More...
 
Data * operator-> ()
 Get a pointer to the associated Data object. More...
 
ListIterator< Data > & operator++ ()
 Go to the next element in a linked list. More...
 
ListIterator< Data > & operator-- ()
 Go to the previous element in a linked list. More...
 

Detailed Description

template<typename Data>
class Util::ListIterator< Data >

Bidirectional iterator for a List.

A ListIterator provides bidirectional input/output access to a linked list, similar to an STL bidirectional iterator. An * operator returns a reference to an associated Data object. The ++ and – operators change the current pointer to the next or prev element in a list.

The isEnd() method returns true if either end of the list has already been passed by a previous ++ or – operation. When isEnd() is true, the iterator is no longer usable, since it no longer points to a Node and cannot be incremented or decremented.

Definition at line 27 of file ListIterator.h.

Constructor & Destructor Documentation

◆ ListIterator() [1/2]

template<typename Data >
Util::ListIterator< Data >::ListIterator ( )
inline

Default constructor.

Creates a "dead" iterator, for which isEnd()==true. Before it can be used, such an iterator must be initialized by either the ListIterator<Data>::setCurrent() method or the List<Data>::begin() method of an associated List.

Definition at line 40 of file ListIterator.h.

◆ ListIterator() [2/2]

template<typename Data >
Util::ListIterator< Data >::ListIterator ( List< Data > const &  list)
inlineexplicit

Constructor for initialized iterator.

Creates an iterator that points to the front of a List. Calls List<Data>::begin(*this) internally.

Parameters
listparent List

Definition at line 52 of file ListIterator.h.

References Util::List< Data >::begin().

Member Function Documentation

◆ setCurrent()

template<typename Data >
void Util::ListIterator< Data >::setCurrent ( Node< Data > *  nodePtr)
inline

Point the iterator at a Node.

Parameters
nodePtrpointer to current Node in a List, or null.

Definition at line 61 of file ListIterator.h.

Referenced by Util::List< Data >::begin().

◆ isEnd()

template<typename Data >
bool Util::ListIterator< Data >::isEnd ( ) const
inline

Has the end of the list been reached?

Return true if the current pointer is null, indicating that the previous increment or decrement passed an end of the list.

Returns
true if current node is null, false otherwise.

Definition at line 72 of file ListIterator.h.

◆ isBack()

template<typename Data >
bool Util::ListIterator< Data >::isBack ( ) const
inline

Is this the back of the List?

Returns
true if current node is the back Node, false otherwise.

Definition at line 80 of file ListIterator.h.

◆ isFront()

template<typename Data >
bool Util::ListIterator< Data >::isFront ( ) const
inline

Is this the front of the List?

Returns
true if current node is the front Node, false otherwise.

Definition at line 88 of file ListIterator.h.

◆ operator*() [1/2]

template<typename Data >
Data const & Util::ListIterator< Data >::operator* ( ) const
inline

Get a const reference to the associated Data object.

Returns
const reference to the associated Data object

Definition at line 99 of file ListIterator.h.

◆ operator*() [2/2]

template<typename Data >
Data & Util::ListIterator< Data >::operator* ( )
inline

Get the associated Data object.

Returns
reference to associated Data object

Definition at line 107 of file ListIterator.h.

◆ operator->() [1/2]

template<typename Data >
Data const * Util::ListIterator< Data >::operator-> ( ) const
inline

Get a pointer to const to the associated Data object.

Returns
pointer to associated Data object

Definition at line 115 of file ListIterator.h.

◆ operator->() [2/2]

template<typename Data >
Data * Util::ListIterator< Data >::operator-> ( )
inline

Get a pointer to the associated Data object.

Returns
pointer to associated Data object

Definition at line 123 of file ListIterator.h.

◆ operator++()

template<typename Data >
ListIterator< Data > & Util::ListIterator< Data >::operator++ ( )
inline

Go to the next element in a linked list.

This method assigns the current pointer to the address of the next Node in the list, and then returns *this. If there is no next Node, the current pointer is set null, and any subsequent call to isEnd() will return true.

Returns
this ListIterator, after modification.

Definition at line 136 of file ListIterator.h.

◆ operator--()

template<typename Data >
ListIterator< Data > & Util::ListIterator< Data >::operator-- ( )
inline

Go to the previous element in a linked list.

This method assigns the current Node to the previous in the List, and returns a reference to *this.

Returns
this ListIterator

Definition at line 150 of file ListIterator.h.


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