VPTissue Reference Manual
CircularIteratorImpl.h
Go to the documentation of this file.
1 #ifndef CONTAINER_CIRCULAR_ITERATOR_IMPL_H_
2 #define CONTAINER_CIRCULAR_ITERATOR_IMPL_H_
3 /*
4  * Copyright 2011-2016 Universiteit Antwerpen
5  *
6  * Licensed under the EUPL, Version 1.1 or as soon they will be approved by
7  * the European Commission - subsequent versions of the EUPL (the "Licence");
8  * You may not use this work except in compliance with the Licence.
9  * You may obtain a copy of the Licence at: http://ec.europa.eu/idabc/eupl5
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the Licence is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the Licence for the specific language governing
15  * permissions and limitations under the Licence.
16  */
21 #include <iterator>
22 
23 namespace SimPT_Sim {
24 namespace Container {
25 
26 namespace Impl_ {
37 template<typename T, typename V, typename P = V*, typename R = V&>
38 class CircularIterator: public std::iterator<std::bidirectional_iterator_tag,
39  V, typename T::difference_type, P, R>
40 {
41 public:
42  // ==================================================================
43  // Member types (in addition to those introduced by the std::iterator
44  // base class (i.e. value_type, difference_type, pointer, reference,
45  // iterator_category).
46  // ==================================================================
48  using base_type = T;
49 
56  CircularIterator(base_type b, base_type e, base_type i)
57  : m_begin(b), m_end(e), m_it(i)
58  {
59  }
60 
65  base_type get() const
66  {
67  return m_it;
68  }
69 
74  explicit operator base_type() const
75  {
76  return m_it;
77  }
78 
83  type& operator=(const base_type& i)
84  {
85  m_it = i;
86  return *this;
87  }
88 
94  typename type::reference operator*() const
95  {
96  return (*m_it);
97  }
98 
104  typename type::pointer operator->() const
105  {
106  return &(operator*());
107  }
108 
115  {
116  ++m_it;
117  if (m_it == m_end) {
118  m_it = m_begin;
119  }
120  return (*this);
121  }
122 
129  {
130  type t(*this);
131  ++(*this);
132  return t;
133  }
134 
141  {
142  if (m_it == m_begin) {
143  m_it = m_end;
144  }
145  --m_it;
146  return (*this);
147  }
148 
155  {
156  type t(*this);
157  --(*this);
158  return t;
159  }
160 
167  bool operator==(const type& rhs) const
168  {
169  return (m_it == rhs.m_it);
170  }
171 
172 
179  bool operator==(const base_type& rhs) const
180  {
181  return (m_it == rhs);
182  }
183 
190  bool operator!=(const type& rhs) const
191  {
192  return !operator==(rhs);
193  }
194 
201  bool operator!=(const base_type& rhs) const
202  {
203  return !operator==(rhs);
204  }
205 
206 protected:
207  base_type m_begin;
208  base_type m_end;
209  base_type m_it;
210 };
211 
212 } // namespace
213 } // namespace
214 } // namespace
215 
216 #endif // end-of-include-guard
CircularIterator(base_type b, base_type e, base_type i)
Constructor requires range and start value.
Implementation of a circular iterator.
bool operator==(const base_type &rhs) const
Equality test of the pointing iterator only, not of the range iterators.
type & operator++()
Pre-increment operator works circularly: at the end of the range it jumps back to the beginning and k...
bool operator!=(const type &rhs) const
Inequality test of the pointing iterator only, not of the range iterators.
type operator++(int)
Post-increment operator works circularly: at the end of the range it jumps back to the beginning and ...
see the online C++11 documentation
bool operator==(const type &rhs) const
Equality test of the pointing iterator only, not of the range iterators.
Namespace for the core simulator.
type & operator--()
Pre-decrement operator works circularly: at the beginning of the range it jumps to the end and keeps ...
bool operator!=(const base_type &rhs) const
Inequality test of the pointing iterator only, not of the range iterators.
type::pointer operator->() const
Structure dereferencing operator.
type & operator=(const base_type &i)
Assignment operator from base type to circularized iterator.
type operator--(int)
Post-decrement operator works circularly: at the beginning of the range it jumps to the end and keeps...
type::reference operator*() const
Dereferencing operator.