Gobelijn API documentation  - generated for commit a0cbea7
 All Classes Namespaces Files Functions Variables Typedefs Friends Macros Pages
CircularIteratorImpl.h
Go to the documentation of this file.
1 #pragma once
2 /*
3  * This file is part of the gobelijn software.
4  * Gobelijn is free software: you can redistribute it and/or modify it
5  * under the terms of the GNU General Public License as published by the
6  * Free Software Foundation, either version 3 of the License, or any later
7  * version. Gobelijn is distributed in the hope that it will be useful, but
8  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
9  * or FITNESS FOR A PARTICULAR PURPOSE.
10  * See the GNU General Public License for details. You should have received
11  * a copy of the GNU General Public License along with the software. If not,
12  * see <http://www.gnu.org/licenses/>.
13  *
14  * Copyright 2012, Jan Broeckhove, CoMP research group, Universiteit Antwerpen.
15  */
20 #include <iterator>
21 
22 namespace UA_CoMP {
23 namespace Container {
24 
25 namespace Impl_ {
36 template <typename T, typename V, typename P = V*, typename R = V&>
37 class CircularIterator : public std::iterator<std::bidirectional_iterator_tag, V, typename T::difference_type, P, R>
38 {
39 public:
40  // ==================================================================
41  // Member types (in addition to those introduced by the std::iterator
42  // base class (i.e. value_type, difference_type, pointer, reference,
43  // iterator_category).
44  // ==================================================================
46  using base_type = T;
47 
55 
60  base_type get() const { return m_it; }
61 
66  explicit operator base_type() const { return m_it; }
67 
73  {
74  m_it = i;
75  return *this;
76  }
77 
83  typename type::reference operator*() const { return (*m_it); }
84 
90  typename type::pointer operator->() const { return &(operator*()); }
91 
98  {
99  ++m_it;
100  if (m_it == m_end) {
101  m_it = m_begin;
102  }
103  return (*this);
104  }
105 
112  {
113  type t(*this);
114  ++(*this);
115  return t;
116  }
117 
124  {
125  if (m_it == m_begin) {
126  m_it = m_end;
127  }
128  --m_it;
129  return (*this);
130  }
131 
138  {
139  type t(*this);
140  --(*this);
141  return t;
142  }
143 
150  bool operator==(const type& rhs) const { return (m_it == rhs.m_it); }
151 
158  bool operator==(const base_type& rhs) const { return (m_it == rhs); }
159 
166  bool operator!=(const type& rhs) const { return !operator==(rhs); }
167 
174  bool operator!=(const base_type& rhs) const { return !operator==(rhs); }
175 
176 protected:
180 };
181 } // namespace Impl_
182 } // namespace Container
183 } // namespace UA_CoMP
Implementation of a circular iterator.
type & operator=(const base_type &i)
Assignment operator from base type to circularized iterator.
type::pointer operator->() const
Structure dereferencing operator.
bool operator==(const type &rhs) const
Equality test of the pointing iterator only, not of the range iterators.
bool operator==(const base_type &rhs) const
Equality 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 ...
type & operator++()
Pre-increment operator works circularly: at the end of the range it jumps back to the beginning and k...
type::reference operator*() const
Dereferencing operator.
type & operator--()
Pre-decrement operator works circularly: at the beginning of the range it jumps to the end and keeps ...
bool operator!=(const type &rhs) const
Inequality test of the pointing iterator only, not of the range iterators.
type operator--(int)
Post-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.
CircularIterator(base_type b, base_type e, base_type i)
Constructor requires range and start value.