PSCF v1.1
ListIterator.h
1#ifndef UTIL_LIST_ITERATOR_H
2#define UTIL_LIST_ITERATOR_H
3
4#include <util/containers/Node.h>
5
6namespace Util
7{
8
9 template <typename Data> class List;
10
26 template <typename Data>
28 {
29
30 public:
31
41 : current_(0)
42 {}
43
52 explicit ListIterator(List<Data> const & list)
53 : current_(0)
54 { list.begin(*this); }
55
61 void setCurrent(Node<Data> *nodePtr)
62 { current_ = nodePtr; }
63
72 bool isEnd() const
73 { return (current_ == 0); }
74
80 bool isBack() const
81 { return (current_->next() == 0); }
82
88 bool isFront() const
89 { return (current_->previous() == 0); }
90
92
93
99 Data const & operator* () const
100 { return current_->data(); }
101
108 { return current_->data(); }
109
115 Data const * operator -> () const
116 { return &(current_->data()); }
117
124 { return &(current_->data()); }
125
137 {
138 current_ = current_->next();
139 return *this;
140 }
141
151 {
152 current_ = current_->prev();
153 return *this;
154 }
155
157
158 private:
159
161 Node<Data>* current_;
162
163 };
164
165}
166#endif
Bidirectional iterator for a List.
Definition: ListIterator.h:28
ListIterator< Data > & operator++()
Go to the next element in a linked list.
Definition: ListIterator.h:136
Data const & operator*() const
Get a const reference to the associated Data object.
Definition: ListIterator.h:99
Data const * operator->() const
Get a pointer to const to the associated Data object.
Definition: ListIterator.h:115
ListIterator()
Default constructor.
Definition: ListIterator.h:40
bool isBack() const
Is this the back of the List?
Definition: ListIterator.h:80
void setCurrent(Node< Data > *nodePtr)
Point the iterator at a Node.
Definition: ListIterator.h:61
ListIterator(List< Data > const &list)
Constructor for initialized iterator.
Definition: ListIterator.h:52
bool isFront() const
Is this the front of the List?
Definition: ListIterator.h:88
bool isEnd() const
Has the end of the list been reached?
Definition: ListIterator.h:72
ListIterator< Data > & operator--()
Go to the previous element in a linked list.
Definition: ListIterator.h:150
Linked list class template.
Definition: List.h:33
void begin(ListIterator< Data > &iterator) const
Set an iterator to the front of this List.
Definition: List.h:449
Linked List Node, class template.
Definition: Node.h:23
Utility classes for scientific computation.
Definition: accumulators.mod:1