BALL  1.4.1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
bidirectionalFilterIterator.h
Go to the documentation of this file.
1 #ifndef BALL_LINALG_BIDIRECTIONALFILTERITERATOR_H
2 #define BALL_LINALG_BIDIRECTIONALFILTERITERATOR_H
3 
4 #ifndef BALL_LINALG_FORWARDFILTERITERATOR_H
6 #endif
7 
8 namespace BALL
9 {
10 
15 
18  template <class Predicate, class IteratorBidirectional>
20  : public ConstForwardFilterIterator<Predicate, IteratorBidirectional>
21  {
22  public:
23 
27 
28 
30  typedef typename IteratorBidirectional::container_type Container;
32  typedef typename IteratorBidirectional::value_type DataType;
34  typedef typename IteratorBidirectional::difference_type Position;
36  typedef typename IteratorBidirectional::traits_type Traits;
38  typedef typename IteratorBidirectional::value_type value_type;
40  typedef typename IteratorBidirectional::difference_type difference_type;
42  typedef typename IteratorBidirectional::pointer pointer;
44  typedef typename IteratorBidirectional::reference reference;
46  typedef std::bidirectional_iterator_tag iterator_category;
47  // convenience typedef
50 
54 
57 
61  {
62  }
63 
66  : Base(iterator)
67  {
68  }
69 
73 
75  void setIterator(const IteratorBidirectional& iterator)
76  {
77  Base::iterator_ = iterator;
78 
79  if (isEnd())
80  {
81  Base::getTraits().backward();
82 
83  while (!isBegin() && !Base::predicate_(Base::getTraits().getData()))
84  Base::getTraits().backward();
85  return;
86  }
87 
88  while (!isEnd() && !Base::predicate_(Base::getTraits().getData()))
89  Base::getTraits().forward();
90  }
91 
95 
99  void toBegin();
100 
102  bool isBegin() const { return Base::getTraits().isBegin(); }
103 
107  void toEnd();
108 
110  bool isEnd() const { return Base::getTraits().isEnd(); }
111 
115  void toRBegin();
116 
118  bool isRBegin() const { return Base::getTraits().isRBegin(); }
119 
123  void toREnd();
124 
126  bool isREnd() const { return Base::getTraits().isREnd(); }
127 
132 
137 
142 
147 
151  static ConstBidirectionalFilterIterator begin(const Container& container);
152 
156  static ConstBidirectionalFilterIterator end(const Container& container);
157 
161  static ConstBidirectionalFilterIterator rbegin(const Container& container);
162 
166  static ConstBidirectionalFilterIterator rend(const Container& container);
168 
169  protected:
170 
173  : Base(container)
174  {
175  }
176  };
178 
179  template <class Predicate, class IteratorBidirectional>
181  {
182  if (Base::getTraits().isSingular())
183  {
185  throw(e);
186  }
187  Base::getTraits().toBegin();
188  }
189 
190  template <class Predicate, class IteratorBidirectional>
192  {
193  if (Base::getTraits().isSingular())
194  {
196  throw(e);
197  }
198  Base::getTraits().toEnd();
199  }
200 
201  template <class Predicate, class IteratorBidirectional>
203  {
204  if (Base::getTraits().isSingular())
205  {
207  throw(e);
208  }
209  Base::getTraits().toRBegin();
210  }
211 
212  template <class Predicate, class IteratorBidirectional>
214  {
215  if (Base::getTraits().isSingular())
216  {
218  throw(e);
219  }
220  Base::getTraits().toREnd();
221  }
222 
223  template <class Predicate, class IteratorBidirectional>
226  {
227  if (!Base::getTraits().isValid())
228  {
230  throw(e);
231  }
232  Base::getTraits().forward();
233 
234  while (!isEnd() && !Base::predicate_(Base::getTraits().getData()))
235  Base::getTraits().forward();
236  return *this;
237  }
238 
239  template <class Predicate, class IteratorBidirectional>
242  {
243  if (!Base::getTraits().isValid())
244  {
246  throw(e);
247  }
248  ConstBidirectionalFilterIterator iterator(*this);
249  ++(*this);
250  return iterator;
251  }
252 
253  template <class Predicate, class IteratorBidirectional>
256  {
257  if (Base::getTraits().isSingular())
258  {
260  throw(e);
261  }
262  Base::getTraits().backward();
263 
264  while (!isBegin() && !Base::predicate_(Base::getTraits().getData()))
265  Base::getTraits().backward();
266  return *this;
267  }
268 
269  template <class Predicate, class IteratorBidirectional>
272  {
273  if (Base::getTraits().isSingular())
274  {
276  throw(e);
277  }
278  ConstBidirectionalFilterIterator iterator(*this);
279  --(*this);
280  return iterator;
281  }
282 
283  template <class Predicate, class IteratorBidirectional>
286  {
287  ConstBidirectionalFilterIterator iterator(container);
288  iterator.toBegin();
289  return iterator;
290  }
291 
292  template <class Predicate, class IteratorBidirectional>
295  {
296  ConstBidirectionalFilterIterator iterator(container);
297  iterator.toEnd();
298  return iterator;
299  }
300 
301  template <class Predicate, class IteratorBidirectional>
304  {
305  ConstBidirectionalFilterIterator iterator(container);
306  iterator.toRBegin();
307  return iterator;
308  }
309 
310  template <class Predicate, class IteratorBidirectional>
313  {
314  ConstBidirectionalFilterIterator iterator(container);
315  iterator.toREnd();
316  return iterator;
317  }
318 
320  template <class Predicate, class IteratorBidirectional>
322  : public ConstBidirectionalFilterIterator<Predicate, IteratorBidirectional>
323  {
324  public:
325 
329 
331  typedef typename IteratorBidirectional::container_type Container;
333  typedef typename IteratorBidirectional::value_type DataType;
335  typedef typename IteratorBidirectional::difference_type Position;
337  typedef typename IteratorBidirectional::traits_type Traits;
339  typedef typename IteratorBidirectional::value_type value_type;
341  typedef typename IteratorBidirectional::difference_type difference_type;
343  typedef typename IteratorBidirectional::pointer pointer;
345  typedef typename IteratorBidirectional::reference reference;
346  // convenience typedef
349 
353 
356 
360  {
361  }
362 
366  {
367  }
368 
371 
373 
377 
379  reference operator * () const { return (reference)Base::getTraits().getData(); }
380 
382  pointer operator -> () const { return (pointer)&Base::getTraits().getData(); }
383 
388 
393 
398 
403 
407  static BidirectionalFilterIterator begin(const Container& container);
408 
412  static BidirectionalFilterIterator end(const Container& container);
413 
417  static BidirectionalFilterIterator rbegin(const Container& container);
418 
422  static BidirectionalFilterIterator rend(const Container& container);
424 
425  protected:
426 
428  BidirectionalFilterIterator(const Container& container);
429  };
430 
431 
432  template <class Predicate, class IteratorBidirectional>
433  BidirectionalFilterIterator<Predicate, IteratorBidirectional>&
435  {
436  Base::operator ++ ();
437  return *this;
438  }
439 
440  template <class Predicate, class IteratorBidirectional>
443  {
444  BidirectionalFilterIterator iterator(*this);
445  this->operator ++ ();
446  return iterator;
447  }
448 
449  template <class Predicate, class IteratorBidirectional>
452  {
453  Base::operator -- ();
454  return *this;
455  }
456 
457  template <class Predicate, class IteratorBidirectional>
460  {
461  BidirectionalFilterIterator iterator(*this);
462  this->operator -- ();
463  return iterator;
464  }
465 
466  template <class Predicate, class IteratorBidirectional>
469  {
470  BidirectionalFilterIterator iterator(container);
471  iterator.toBegin();
472  return iterator;
473  }
474 
475  template <class Predicate, class IteratorBidirectional>
478  {
479  BidirectionalFilterIterator iterator(container);
480  iterator.toEnd();
481  return iterator;
482  }
483 
484  template <class Predicate, class IteratorBidirectional>
487  {
488  BidirectionalFilterIterator iterator(container);
489  iterator.toRBegin();
490  return iterator;
491  }
492 
493  template <class Predicate, class IteratorBidirectional>
496  {
497  BidirectionalFilterIterator iterator(container);
498  iterator.toREnd();
499  return iterator;
500  }
501 
502  template <class Predicate, class IteratorBidirectional>
505  {
506  }
507 
508 
509 } // namespace BALL
510 
511 #endif // BALL_KERNEL_BIDIRECTIONALFILTERITERATOR_H