BALL  1.4.79
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
forwardIterator.h
Go to the documentation of this file.
1 // -*- Mode: C++; tab-width: 2; -*-
2 // vi: set ts=2:
3 //
4 
5 #ifndef BALL_CONCEPT_FORWARDITERATOR_H
6 #define BALL_CONCEPT_FORWARDITERATOR_H
7 
8 #ifndef BALL_CONCEPT_BASEITERATOR_H
10 #endif
11 
12 namespace BALL
13 {
14 
20 
23  template <typename Container, typename DataType, typename Position, typename Traits>
25  : public BaseIterator<Container, DataType, Position, Traits>
26  {
27  public:
28 
32 
34  typedef std::forward_iterator_tag iterator_category;
35  // convenience typedef
38 
42 
45 
48  : BaseIterator<Container, DataType, Position, Traits>(iterator)
49  {
50  }
51 
54 
56 
62  {
64  return *this;
65  }
66 
70 
74 
78  BALL_INLINE void toBegin();
79 
81  BALL_INLINE bool isBegin() const;
82 
86  BALL_INLINE void toEnd();
87 
89  BALL_INLINE bool isEnd() const;
90 
94  static ConstForwardIterator begin(const Container& container);
95 
99  static ConstForwardIterator end(const Container& container);
100 
105  {
106  BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
107  Base::getTraits().forward();
108  return *this;
109  }
110 
115  {
116  BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
117  ConstForwardIterator tmp(*this);
118  ++(*this);
119  return tmp;
120  }
121 
123 
124  protected:
125 
127  BALL_INLINE ConstForwardIterator(const Container& container)
128  : BaseIterator<Container, DataType, Position, Traits>(container)
129  {
130  }
131  };
133 
134  template <typename Container, typename DataType, typename Position, typename Traits>
137  {
138  BALL_PRECONDITION_EXCEPTION(!Base::isSingular(), "cannot move singular iterator to begin")
139  Base::getTraits().toBegin();
140  }
141 
142  template <typename Container, typename DataType, typename Position, typename Traits>
146  {
148  iterator.toBegin();
149  return iterator;
150  }
151 
152  template <typename Container, typename DataType, typename Position, typename Traits>
155 
156  {
157  if (Base::getTraits().isSingular())
158  {
159  return false;
160  }
161  return Base::getTraits().isBegin();
162  }
163 
164  template <typename Container, typename DataType, typename Position, typename Traits>
167  {
168  BALL_PRECONDITION_EXCEPTION(!Base::isSingular(), "cannot move singular iterator to end")
169  Base::getTraits().toEnd();
170  }
171 
172  template <typename Container, typename DataType, typename Position, typename Traits>
176  {
177  ConstForwardIterator iterator(container);
178  iterator.toEnd();
179  return iterator;
180  }
181 
182  template <typename Container, typename DataType, typename Position, typename Traits>
185 
186  {
187  if (Base::isSingular())
188  {
189  return false;
190  }
191  return Base::getTraits().isEnd();
192  }
193 
196  template <typename Container, typename DataType, typename Position, typename Traits>
198  : public ConstForwardIterator<Container, DataType, Position, Traits>
199  {
200  public:
201 
205 
207  typedef DataType& reference;
209  typedef DataType* pointer;
210  // convenience typedef
213 
217 
220 
223  : ConstForwardIterator<Container, DataType, Position, Traits>(iterator)
224  {
225  }
226 
230 
236  {
238  return *this;
239  }
240 
242  BALL_INLINE void swap(ForwardIterator& iterator) { std::swap(Base::getTraits(), iterator.getTraits()); }
244 
248 
252  static ForwardIterator begin(const Container& container);
253 
257  static ForwardIterator end(const Container& container);
258 
261  {
262  return (reference)Base::getTraits().getData();
263  }
264 
267  {
268  return (pointer)&Base::getTraits().getData();
269  }
270 
275  {
276  BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
277  Base::getTraits().forward();
278  return *this;
279  }
280 
285  {
286  BALL_PRECONDITION_EXCEPTION(Base::isValid(), "cannot increment invalid iterator")
287  ForwardIterator tmp(*this);
288  ++(*this);
289  return tmp;
290  }
291 
293 
294  protected:
295 
297  BALL_INLINE ForwardIterator(const Container& container)
298  : Base(container)
299  {
300  }
301  };
302 
303 
304  template <typename Container, typename DataType, typename Position, typename Traits>
306  ForwardIterator<Container, DataType, Position, Traits>
308  {
309  ForwardIterator iterator(container);
310  iterator.toBegin();
311  return iterator;
312  }
313 
314  template <typename Container, typename DataType, typename Position, typename Traits>
318  {
319  ForwardIterator iterator(container);
320  iterator.toEnd();
321  return iterator;
322  }
323 
324 
325 } // namespace BALL
326 
327 #endif // BALL_CONCEPT_FORWARDITERATOR_H
BALL_INLINE reference operator*() const
BaseIterator< Container, DataType, Position, Traits > Base
ConstForwardIterator< Container, DataType, Position, Traits > Base
BALL_INLINE ConstForwardIterator()
Default constructor.
BALL_INLINE ConstForwardIterator & operator++()
BALL_INLINE ForwardIterator()
BALL_INLINE ConstForwardIterator & operator=(const ConstForwardIterator &iterator)
BALL_INLINE ~ForwardIterator()
const DataType * pointer
Definition: baseIterator.h:78
#define BALL_PRECONDITION_EXCEPTION(condition, message)
Definition: debug.h:89
static ConstForwardIterator end(const Container &container)
const DataType & reference
Definition: baseIterator.h:80
BALL_INLINE ConstForwardIterator(const ConstForwardIterator &iterator)
Copy constructor.
BALL_INLINE pointer operator->() const
BALL_INLINE ForwardIterator(const ForwardIterator &iterator)
BALL_INLINE void swap(ForwardIterator &iterator)
#define BALL_INLINE
Definition: debug.h:15
BALL_INLINE void toBegin()
BALL_INLINE bool isValid() const
Definition: baseIterator.h:175
BALL_INLINE ~ConstForwardIterator()
BALL_INLINE void swap(ConstForwardIterator &iterator)
BALL_INLINE void toEnd()
BALL_INLINE const Traits & getTraits() const
Get a constant reference to the traits of this iterator.
Definition: baseIterator.h:130
BALL_INLINE ConstForwardIterator(const Container &container)
BALL_INLINE ForwardIterator & operator=(const ForwardIterator &iterator)
static ForwardIterator end(const Container &container)
std::forward_iterator_tag iterator_category
BALL_INLINE ForwardIterator & operator++()
BALL_INLINE BaseIterator & operator=(const BaseIterator &iterator)
Definition: baseIterator.h:109
static ConstForwardIterator begin(const Container &container)
BALL_INLINE ForwardIterator(const Container &container)
BALL_INLINE bool isEnd() const
Check whether the iterator points behind the last item of the container.
BALL_INLINE bool isBegin() const
Check whether the iterator points to the first item of the container.
static ForwardIterator begin(const Container &container)