BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
CONCEPT/bidirectionalIterator.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_BIDIRECTIONALITERATOR_H
6 #define BALL_CONCEPT_BIDIRECTIONALITERATOR_H
7 
8 #ifndef BALL_CONCEPT_FORWARDITERATOR_H
10 #endif
11 
12 namespace BALL
13 {
14 
19 
22  template <typename Container, typename DataType, typename Position, typename Traits>
24  : public ConstForwardIterator<Container, DataType, Position, Traits>
25  {
26  public:
27 
31 
33  typedef std::bidirectional_iterator_tag iterator_category;
34  // convenience typedef
37 
41 
44 
47  : Base(iterator)
48  {
49  }
50 
54 
58 
62  BALL_INLINE void toBegin();
63 
65  BALL_INLINE bool isBegin() const { return Base::getTraits().isBegin(); }
66 
70  void toEnd();
71 
73  BALL_INLINE bool isEnd() const { return Base::getTraits().isEnd(); }
74 
78  void toRBegin();
79 
81  BALL_INLINE bool isRBegin() const { return Base::getTraits().isRBegin(); }
82 
86  void toREnd();
87 
89  BALL_INLINE bool isREnd() const { return Base::getTraits().isREnd(); }
90 
95 
100 
105 
110 
114  static ConstBidirectionalIterator begin(const Container& container);
115 
119  static ConstBidirectionalIterator end(const Container& container);
120 
124  static ConstBidirectionalIterator rbegin(const Container& container);
125 
129  static ConstBidirectionalIterator rend(const Container& container);
131 
132  protected:
133 
135  BALL_INLINE ConstBidirectionalIterator(const Container& container)
136  : Base(container)
137  {
138  }
139  };
141 
142  template <typename Container, typename DataType, typename Position, typename Traits>
145  {
146  BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to begin")
147  Base::getTraits().toBegin();
148  }
149 
150  template <typename Container, typename DataType, typename Position, typename Traits>
153  {
154  BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to end")
155  Base::getTraits().toEnd();
156  }
157 
158  template <typename Container, typename DataType, typename Position, typename Traits>
161  {
162  BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to reverse begin")
163  Base::getTraits().toRBegin();
164  }
165 
166  template <typename Container, typename DataType, typename Position, typename Traits>
169  {
170  BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot set unbound iterator to reverse end")
171  Base::getTraits().toREnd();
172  }
173 
174  template <typename Container, typename DataType, typename Position, typename Traits>
178  {
179  BALL_PRECONDITION_EXCEPTION(Base::getTraits().isValid(), "cannot increment an invalid iterator")
180  Base::getTraits().forward();
181  return *this;
182  }
183 
184  template <typename Container, typename DataType, typename Position, typename Traits>
188  {
189  BALL_PRECONDITION_EXCEPTION(Base::getTraits().isValid(), "cannot increment an invalid iterator")
190  ConstBidirectionalIterator iterator(*this);
191  ++(*this);
192  return iterator;
193  }
194 
195  template <typename Container, typename DataType, typename Position, typename Traits>
199  {
200  BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot decrement unbound iterator")
201  Base::getTraits().backward();
202  return *this;
203  }
204 
205  template <typename Container, typename DataType, typename Position, typename Traits>
209  {
210  BALL_PRECONDITION_EXCEPTION(!Base::getTraits().isSingular(), "cannot decrement an unbound iterator")
211  ConstBidirectionalIterator iterator(*this);
212  --(*this);
213  return iterator;
214  }
215 
216  template <typename Container, typename DataType, typename Position, typename Traits>
220  {
221  ConstBidirectionalIterator iterator(container);
222  iterator.toBegin();
223  return iterator;
224  }
225 
226  template <typename Container, typename DataType, typename Position, typename Traits>
230  {
231  ConstBidirectionalIterator iterator(container);
232  iterator.toEnd();
233  return iterator;
234  }
235 
236  template <typename Container, typename DataType, typename Position, typename Traits>
240  {
241  ConstBidirectionalIterator iterator(container);
242  iterator.toRBegin();
243  return iterator;
244  }
245 
246  template <typename Container, typename DataType, typename Position, typename Traits>
250  {
251  ConstBidirectionalIterator iterator(container);
252  iterator.toREnd();
253  return iterator;
254  }
255 
257  template <typename Container, typename DataType, typename Position, typename Traits>
259  : public ConstBidirectionalIterator<Container, DataType, Position, Traits>
260  {
261  public:
262 
266 
268  typedef DataType& reference;
270  typedef DataType* pointer;
271  // convenience typedef
274 
278 
281 
284 
285  : ConstBidirectionalIterator<Container, DataType, Position, Traits>(iterator)
286  {
287  }
288 
291 
293 
297 
299  BALL_INLINE reference operator * () const { return (reference)Base::getTraits().getData(); }
300 
302  BALL_INLINE pointer operator -> () const { return (pointer)&Base::getTraits().getData(); }
303 
308 
313 
318 
323 
327  static BidirectionalIterator begin(const Container& container);
328 
332  static BidirectionalIterator end(const Container& container);
333 
337  static BidirectionalIterator rbegin(const Container& container);
338 
342  static BidirectionalIterator rend(const Container& container);
344 
345  protected:
346 
348  BALL_INLINE BidirectionalIterator(const Container& container) ;
349  };
350 
351 
352  template <typename Container, typename DataType, typename Position, typename Traits>
354  BidirectionalIterator<Container, DataType, Position, Traits>&
356  {
357  Base::operator ++ ();
358  return *this;
359  }
360 
361  template <typename Container, typename DataType, typename Position, typename Traits>
365  {
366  BidirectionalIterator iterator(*this);
367  this->operator ++ ();
368  return iterator;
369  }
370 
371  template <typename Container, typename DataType, typename Position, typename Traits>
375  {
376  Base::operator -- ();
377  return *this;
378  }
379 
380  template <typename Container, typename DataType, typename Position, typename Traits>
384  {
385  BidirectionalIterator iterator(*this);
386  this->operator -- ();
387  return iterator;
388  }
389 
390  template <typename Container, typename DataType, typename Position, typename Traits>
394  {
395  BidirectionalIterator iterator(container);
396  iterator.toBegin();
397  return iterator;
398  }
399 
400  template <typename Container, typename DataType, typename Position, typename Traits>
404  {
405  BidirectionalIterator iterator(container);
406  iterator.toEnd();
407  return iterator;
408  }
409 
410  template <typename Container, typename DataType, typename Position, typename Traits>
414  {
415  BidirectionalIterator iterator(container);
416  iterator.toRBegin();
417  return iterator;
418  }
419 
420  template <typename Container, typename DataType, typename Position, typename Traits>
424  {
425  BidirectionalIterator iterator(container);
426  iterator.toREnd();
427  return iterator;
428  }
429 
430  template <typename Container, typename DataType, typename Position, typename Traits>
433 
434  : ConstBidirectionalIterator<Container, DataType, Position, Traits>(container)
435  {
436  }
437 
438 
439 } // namespace BALL
440 
441 #endif // BALL_CONCEPT_BIDIRECTIONALITERATOR_H