Simpatico  v1.10
ListIterator.h
1 #ifndef UTIL_LIST_ITERATOR_H
2 #define UTIL_LIST_ITERATOR_H
3 
4 #include <util/containers/Node.h>
5 
6 namespace Util
7 {
8 
9  template <typename Data> class List;
10 
26  template <typename Data>
27  class ListIterator
28  {
29 
30  public:
31 
41  : current_(0)
42  {}
43 
52  explicit ListIterator(const List<Data>& 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  const Data& operator* () const
100  { return current_->data(); }
101 
107  Data& operator* ()
108  { return current_->data(); }
109 
115  const Data * operator -> () const
116  { return &(current_->data()); }
117 
123  Data* operator -> ()
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
ListIterator< Data > & operator++()
Go to the next element in a linked list.
Definition: ListIterator.h:136
ListIterator(const List< Data > &list)
Constructor for initialized iterator.
Definition: ListIterator.h:52
const Data & operator*() const
Get a const reference to the associated Data object.
Definition: ListIterator.h:99
const Data * operator->() const
Get a pointer to const to the associated Data object.
Definition: ListIterator.h:115
void begin(ListIterator< Data > &iterator) const
Set an iterator to the front of this List.
Definition: List.h:449
bool isBack() const
Is this the back of the List?
Definition: ListIterator.h:80
ListIterator()
Default constructor.
Definition: ListIterator.h:40
Utility classes for scientific computation.
Definition: accumulators.mod:1
bool isFront() const
Is this the front of the List?
Definition: ListIterator.h:88
Linked list class template.
Definition: List.h:32
Bidirectional iterator for a List.
Definition: List.h:20
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 Node, class template.
Definition: Node.h:22
void setCurrent(Node< Data > *nodePtr)
Point the iterator at a Node.
Definition: ListIterator.h:61