BALL  1.4.2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
MATHS/LINALG/bidirectionalIterator.h
Go to the documentation of this file.
1 #ifndef BALL_LINALG_BIDIRECTIONALITERATOR_H
2 #define BALL_LINALG_BIDIRECTIONALITERATOR_H
3 
4 #ifndef BALL_LINALG_FORWARDITERATOR_H
6 #endif
7 
8 namespace BALL
9 {
10 
15 
18  template <typename Container, typename DataType, typename Position, typename Traits>
19  class ConstBidirectionalIterator
20  : public ConstForwardIterator<Container, DataType, Position, Traits>
21  {
22  public:
23 
27 
29  typedef std::bidirectional_iterator_tag iterator_category;
30  // convenience typedef
33 
37 
40 
43  : Base(iterator)
44  {
45  }
46 
50 
54 
58  void toBegin();
59 
61  bool isBegin() const { return Base::getTraits().isBegin(); }
62 
66  void toEnd();
67 
69  bool isEnd() const { return Base::getTraits().isEnd(); }
70 
74  void toRBegin();
75 
77  bool isRBegin() const { return Base::getTraits().isRBegin(); }
78 
82  void toREnd();
83 
85  bool isREnd() const { return Base::getTraits().isREnd(); }
86 
91 
96 
101 
106 
110  static ConstBidirectionalIterator begin(const Container& container);
111 
115  static ConstBidirectionalIterator end(const Container& container);
116 
120  static ConstBidirectionalIterator rbegin(const Container& container);
121 
125  static ConstBidirectionalIterator rend(const Container& container);
127 
128  protected:
129 
131  ConstBidirectionalIterator(const Container& container)
132  : Base(container)
133  {
134  }
135  };
137 
138  template <typename Container, typename DataType, typename Position, typename Traits>
140  {
141  if (Base::getTraits().isSingular())
142  {
143  Exception::SingularIterator e;
144  throw(e);
145  }
146  Base::getTraits().toBegin();
147  }
148 
149  template <typename Container, typename DataType, typename Position, typename Traits>
151  {
152  if (Base::getTraits().isSingular())
153  {
154  Exception::SingularIterator e;
155  throw(e);
156  }
157  Base::getTraits().toEnd();
158  }
159 
160  template <typename Container, typename DataType, typename Position, typename Traits>
162  {
163  if (Base::getTraits().isSingular())
164  {
165  Exception::SingularIterator e;
166  throw(e);
167  }
168  Base::getTraits().toRBegin();
169  }
170 
171  template <typename Container, typename DataType, typename Position, typename Traits>
173  {
174  if (Base::getTraits().isSingular())
175  {
176  Exception::SingularIterator e;
177  throw(e);
178  }
179  Base::getTraits().toREnd();
180  }
181 
182  template <typename Container, typename DataType, typename Position, typename Traits>
183  ConstBidirectionalIterator<Container, DataType, Position, Traits>&
185  {
186  if (!Base::getTraits().isValid())
187  {
188  Exception::InvalidIterator e;
189  throw(e);
190  }
191  Base::getTraits().forward();
192  return *this;
193  }
194 
195  template <typename Container, typename DataType, typename Position, typename Traits>
196  ConstBidirectionalIterator<Container, DataType, Position, Traits>
198  {
199  if (!Base::getTraits().isValid())
200  {
201  Exception::InvalidIterator e;
202  throw(e);
203  }
204  ConstBidirectionalIterator iterator(*this);
205  ++(*this);
206  return iterator;
207  }
208 
209  template <typename Container, typename DataType, typename Position, typename Traits>
210  ConstBidirectionalIterator<Container, DataType, Position, Traits>&
212  {
213  if (Base::getTraits().isSingular())
214  {
215  Exception::SingularIterator e;
216  throw(e);
217  }
218  Base::getTraits().backward();
219  return *this;
220  }
221 
222  template <typename Container, typename DataType, typename Position, typename Traits>
223  ConstBidirectionalIterator<Container, DataType, Position, Traits>
225  {
226  if (Base::getTraits().isSingular())
227  {
228  Exception::SingularIterator e;
229  throw(e);
230  }
231  ConstBidirectionalIterator iterator(*this);
232  --(*this);
233  return iterator;
234  }
235 
236  template <typename Container, typename DataType, typename Position, typename Traits>
237  ConstBidirectionalIterator<Container, DataType, Position, Traits>
239  {
240  ConstBidirectionalIterator iterator(container);
241  iterator.toBegin();
242  return iterator;
243  }
244 
245  template <typename Container, typename DataType, typename Position, typename Traits>
246  ConstBidirectionalIterator<Container, DataType, Position, Traits>
248  {
249  ConstBidirectionalIterator iterator(container);
250  iterator.toEnd();
251  return iterator;
252  }
253 
254  template <typename Container, typename DataType, typename Position, typename Traits>
255  ConstBidirectionalIterator<Container, DataType, Position, Traits>
257  {
258  ConstBidirectionalIterator iterator(container);
259  iterator.toRBegin();
260  return iterator;
261  }
262 
263  template <typename Container, typename DataType, typename Position, typename Traits>
264  ConstBidirectionalIterator<Container, DataType, Position, Traits>
266  {
267  ConstBidirectionalIterator iterator(container);
268  iterator.toREnd();
269  return iterator;
270  }
271 
273  template <typename Container, typename DataType, typename Position, typename Traits>
274  class BidirectionalIterator
275  : public ConstBidirectionalIterator<Container, DataType, Position, Traits>
276  {
277  public:
278 
282 
284  typedef DataType& reference;
286  typedef DataType* pointer;
287  // convenience typedef
290 
294 
297 
300  : ConstBidirectionalIterator<Container, DataType, Position, Traits>(iterator)
301  {
302  }
303 
306 
308 
312 
314  reference operator * () const { return (reference)Base::getTraits().getData(); }
315 
317  pointer operator -> () const { return (pointer)&Base::getTraits().getData(); }
318 
323 
328 
333 
338 
342  static BidirectionalIterator begin(const Container& container);
343 
347  static BidirectionalIterator end(const Container& container);
348 
352  static BidirectionalIterator rbegin(const Container& container);
353 
357  static BidirectionalIterator rend(const Container& container);
359 
360  protected:
361 
363  BidirectionalIterator(const Container& container);
364  };
365 
366 
367  template <typename Container, typename DataType, typename Position, typename Traits>
368  BidirectionalIterator<Container, DataType, Position, Traits>&
370  {
371  Base::operator ++ ();
372  return *this;
373  }
374 
375  template <typename Container, typename DataType, typename Position, typename Traits>
376  BidirectionalIterator<Container, DataType, Position, Traits>
378  {
379  BidirectionalIterator iterator(*this);
380  this->operator ++ ();
381  return iterator;
382  }
383 
384  template <typename Container, typename DataType, typename Position, typename Traits>
385  BidirectionalIterator<Container, DataType, Position, Traits>&
387  {
388  Base::operator -- ();
389  return *this;
390  }
391 
392  template <typename Container, typename DataType, typename Position, typename Traits>
393  BidirectionalIterator<Container, DataType, Position, Traits>
395  {
396  BidirectionalIterator iterator(*this);
397  this->operator -- ();
398  return iterator;
399  }
400 
401  template <typename Container, typename DataType, typename Position, typename Traits>
402  BidirectionalIterator<Container, DataType, Position, Traits>
404  {
405  BidirectionalIterator iterator(container);
406  iterator.toBegin();
407  return iterator;
408  }
409 
410  template <typename Container, typename DataType, typename Position, typename Traits>
411  BidirectionalIterator<Container, DataType, Position, Traits>
413  {
414  BidirectionalIterator iterator(container);
415  iterator.toEnd();
416  return iterator;
417  }
418 
419  template <typename Container, typename DataType, typename Position, typename Traits>
420  BidirectionalIterator<Container, DataType, Position, Traits>
422  {
423  BidirectionalIterator iterator(container);
424  iterator.toRBegin();
425  return iterator;
426  }
427 
428  template <typename Container, typename DataType, typename Position, typename Traits>
429  BidirectionalIterator<Container, DataType, Position, Traits>
431  {
432  BidirectionalIterator iterator(container);
433  iterator.toREnd();
434  return iterator;
435  }
436 
437  template <typename Container, typename DataType, typename Position, typename Traits>
439  : ConstBidirectionalIterator<Container, DataType, Position, Traits>(container)
440  {
441  }
442 
443 
444 } // namespace BALL
445 
446 #endif // BALL_KERNEL_BIDIRECTIONALITERATOR_H