MorphoGraphX  2.0-1-227
CircIterator.hpp
Go to the documentation of this file.
1 //
2 // This file is part of MorphoGraphX - http://www.MorphoGraphX.org
3 // Copyright (C) 2012-2015 Richard S. Smith and collaborators.
4 //
5 // If you use MorphoGraphX in your work, please cite:
6 // http://dx.doi.org/10.7554/eLife.05864
7 //
8 // MorphoGraphX is free software, and is licensed under under the terms of the
9 // GNU General (GPL) Public License version 2.0, http://www.gnu.org/licenses.
10 //
11 #ifndef CIRC_ITERATOR_H
12 #define CIRC_ITERATOR_H
13 
14 #include <Config.hpp>
15 
16 #include <iterator>
17 
18 namespace mgx {
24  template <typename ForwardIterator> class CircIterator {
25  public:
26  typedef std::forward_iterator_tag iterator_category;
27  typedef typename std::iterator_traits<ForwardIterator>::value_type value_type;
28  typedef typename std::iterator_traits<ForwardIterator>::difference_type difference_type;
30  typedef typename std::iterator_traits<ForwardIterator>::reference reference;
31 
33 
34  CircIterator(const ForwardIterator& f, const ForwardIterator& l, const ForwardIterator& c)
35  : first(f), last(l), init(c), cur(c) {}
36 
37  CircIterator(const ForwardIterator& f, const ForwardIterator& l)
38  : first(f), last(l), init(l), cur(l) {}
39 
41  : first(copy.first), last(copy.last), init(copy.init), cur(copy.cur) {}
42 
44  {
45  ++cur;
46  if(cur == last)
47  cur = first;
48  if(cur == init)
49  cur = last;
50  return *this;
51  }
52 
54  {
55  CircIterator temp(*this);
56  this->operator++();
57  return temp;
58  }
59 
61  return *cur;
62  }
64  return cur.operator->();
65  }
66 
67  bool operator==(const ForwardIterator& other) const {
68  return cur == other;
69  }
70 
71  bool operator==(const CircIterator& other) const {
72  return cur == other.cur;
73  }
74 
75  bool operator!=(const ForwardIterator& other) const {
76  return cur != other;
77  }
78 
79  bool operator!=(const CircIterator& other) const {
80  return cur != other.cur;
81  }
82 
83  ForwardIterator base() const {
84  return cur;
85  }
86 
87  protected:
88  ForwardIterator first, last, init, cur;
89  };
90 }
91 #endif
mgx::CircIterator::base
ForwardIterator base() const
Definition: CircIterator.hpp:83
mgx::CircIterator::operator!=
bool operator!=(const ForwardIterator &other) const
Definition: CircIterator.hpp:75
mgx::CircIterator::CircIterator
CircIterator(const ForwardIterator &f, const ForwardIterator &l)
Definition: CircIterator.hpp:37
mgx::CircIterator::init
ForwardIterator init
Definition: CircIterator.hpp:88
mgx::CircIterator::operator!=
bool operator!=(const CircIterator &other) const
Definition: CircIterator.hpp:79
mgx::CircIterator::operator++
CircIterator operator++(int)
Definition: CircIterator.hpp:53
mgx::CircIterator::cur
ForwardIterator cur
Definition: CircIterator.hpp:88
mgx::CircIterator::pointer
std::iterator_traits< ForwardIterator >::pointer pointer
Definition: CircIterator.hpp:29
mgx::CircIterator::first
ForwardIterator first
Definition: CircIterator.hpp:88
mgx::CircIterator::operator++
CircIterator & operator++()
Definition: CircIterator.hpp:43
mgx::ForAll::pointer
T * pointer(const T &)
Definition: VVGraph.hpp:89
mgx
Distributed matrix library.
Definition: Assert.hpp:26
mgx::CircIterator::operator*
reference operator*()
Definition: CircIterator.hpp:60
mgx::CircIterator::operator==
bool operator==(const ForwardIterator &other) const
Definition: CircIterator.hpp:67
mgx::CircIterator::CircIterator
CircIterator()
Definition: CircIterator.hpp:32
mgx::CircIterator::CircIterator
CircIterator(const CircIterator &copy)
Definition: CircIterator.hpp:40
mgx::CircIterator::iterator_category
std::forward_iterator_tag iterator_category
Definition: CircIterator.hpp:26
mgx::CircIterator::operator==
bool operator==(const CircIterator &other) const
Definition: CircIterator.hpp:71
mgx::CircIterator::last
ForwardIterator last
Definition: CircIterator.hpp:88
mgx::CircIterator::difference_type
std::iterator_traits< ForwardIterator >::difference_type difference_type
Definition: CircIterator.hpp:28
mgx::CircIterator
Definition: CircIterator.hpp:24
mgx::CircIterator::operator->
pointer operator->()
Definition: CircIterator.hpp:63
mgx::CircIterator::CircIterator
CircIterator(const ForwardIterator &f, const ForwardIterator &l, const ForwardIterator &c)
Definition: CircIterator.hpp:34
mgx::CircIterator::reference
std::iterator_traits< ForwardIterator >::reference reference
Definition: CircIterator.hpp:30
mgx::CircIterator::value_type
std::iterator_traits< ForwardIterator >::value_type value_type
Definition: CircIterator.hpp:27