CirculatorI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2012-2015 OpenFOAM Foundation
9  Copyright (C) 2019-2022 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
30 
31 template<class Container, bool Const>
33 (
35 )
36 {
37  return
38  (
39  begin_ == rhs.begin_
40  && end_ == rhs.end_
41  && iter_ == rhs.iter_
42  && fulcrum_ == rhs.fulcrum_
43  );
44 }
45 
46 
47 template<class Container, bool Const>
49 {
50  ++iter_;
51  if (iter_ == end_)
52  {
53  iter_ = begin_;
54  }
55 }
56 
57 
58 template<class Container, bool Const>
60 {
61  if (iter_ == begin_)
62  {
63  iter_ = end_;
64  }
65  --iter_;
66 }
67 
68 
69 
70 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71 
72 template<class Container, bool Const>
74 :
75  begin_(0),
76  end_(0),
77  iter_(0),
78  fulcrum_(0)
79 {}
80 
81 
82 template<class Container, bool Const>
84 (
85  const iterator& begin,
86  const iterator& end
87 )
88 :
89  begin_(begin),
90  end_(end),
91  iter_(begin_),
92  fulcrum_(begin_)
93 {}
94 
95 
96 template<class Container, bool Const>
98 (
100 )
101 :
102  begin_(rhs.begin_),
103  end_(rhs.end_),
104  iter_(rhs.iter_),
105  fulcrum_(rhs.fulcrum_)
106 {}
107 
108 
109 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
110 
111 template<class Container, bool Const>
113 {
114  return (end_ == begin_);
115 }
116 
117 
118 template<class Container, bool Const>
121 {
122  return (end_ - begin_);
123 }
124 
125 
126 template<class Container, bool Const>
129 {
130  return (iter_ - fulcrum_);
131 }
132 
133 
134 template<class Container, bool Const>
136 (
137  const CirculatorBase::direction dir
138 )
139 {
140  if (dir == CirculatorBase::CLOCKWISE)
141  {
142  increment();
143  }
144  else if (dir == CirculatorBase::ANTICLOCKWISE)
145  {
146  decrement();
147  }
148 
149  return !(iter_ == fulcrum_);
150 }
151 
152 
153 template<class Container, bool Const>
155 {
156  fulcrum_ = iter_;
157 }
158 
159 
160 template<class Container, bool Const>
162 {
163  iter_ = fulcrum_;
164 }
165 
166 
167 template<class Container, bool Const>
170 {
171  return *iter_;
172 }
173 
174 
175 template<class Container, bool Const>
178 {
179  if (iter_ == end_ - 1)
180  {
181  return *begin_;
182  }
184  return *(iter_ + 1);
185 }
186 
187 
188 template<class Container, bool Const>
191 {
192  if (iter_ == begin_)
193  {
194  return *(end_ - 1);
195  }
196 
197  return *(iter_ - 1);
198 }
199 
200 
201 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
202 
203 template<class Container, bool Const>
205 (
207 )
208 {
209  if (this == &rhs)
210  {
211  return; // Self-assignment is a no-op
212  }
213 
214  begin_ = rhs.begin_;
215  end_ = rhs.end_;
216  iter_ = rhs.iter_;
217  fulcrum_ = rhs.fulcrum_;
218 }
219 
220 
221 template<class Container, bool Const>
224 {
225  this->increment();
226  return *this;
227 }
228 
229 
230 template<class Container, bool Const>
233 {
234  auto old(*this);
235  this->increment();
236  return old;
237 }
238 
239 
240 template<class Container, bool Const>
243 {
244  this->decrement();
245  return *this;
246 }
247 
248 
249 template<class Container, bool Const>
252 {
253  auto old(*this);
254  this->decrement();
255  return old;
256 }
257 
258 
259 template<class Container, bool Const>
261 (
263 ) const
264 {
265  return this->equal(rhs);
266 }
267 
268 
269 template<class Container, bool Const>
271 (
273 ) const
274 {
275  return !this->equal(rhs);
276 }
277 
278 
279 template<class Container, bool Const>
282 {
283  return *iter_;
284 }
285 
286 
287 template<class Container, bool Const>
290 {
291  return *iter_;
292 }
293 
294 
295 template<class Container, bool Const>
298 (
300 ) const
301 {
302  return (iter_ - rhs.iter_);
303 }
304 
305 
306 // ************************************************************************* //
reference prev() const
Dereference the previous iterator.
Definition: CirculatorI.H:183
CirculatorIters< Container, Const > & operator--()
Prefix decrement the iterator.
Definition: CirculatorI.H:235
typename Container::difference_type difference_type
The type that represents difference between iterator objects.
Definition: Circulator.H:127
direction
Direction type enumeration.
Definition: Circulator.H:86
CirculatorIters()
Default construct.
Definition: CirculatorI.H:66
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
Definition: CirculatorI.H:147
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
Definition: CirculatorI.H:154
void decrement()
Move iterator backward.
Definition: CirculatorI.H:52
bool equal(const Matrix< Form1, Type > &A, const Matrix< Form2, Type > &B, const bool verbose=false, const label maxDiffs=10, const scalar relTol=1e-5, const scalar absTol=1e-8)
Compare matrix elements for absolute or relative equality.
Definition: MatrixTools.C:27
difference_type nRotations() const
The distance between the iterator and the fulcrum.
Definition: CirculatorI.H:121
reference curr() const
Dereference the current iterator.
Definition: CirculatorI.H:162
bool equal(const CirculatorIters< Container, Const > &rhs)
Compare for equality.
Definition: CirculatorI.H:26
reference operator()() const
Dereference the iterator. Same as curr()
Definition: CirculatorI.H:282
A pair of begin/end iterators used for implementing circular iteration.
Definition: Circulator.H:111
reference operator*() const
Dereference the iterator. Same as curr()
Definition: CirculatorI.H:274
CirculatorIters< Container, Const > & operator++()
Prefix increment the iterator.
Definition: CirculatorI.H:216
void increment()
Move iterator forward.
Definition: CirculatorI.H:41
size_type size() const
Return the range of the iterator pair.
Definition: CirculatorI.H:113
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:201
typename Container::size_type size_type
The type that can represent the size of Container.
Definition: Circulator.H:122
bool empty() const
True if begin/end iterators are identical.
Definition: CirculatorI.H:105
typename std::conditional< Const, typename Container::const_reference, typename Container::reference >::type reference
The reference type (const/non-const)
Definition: Circulator.H:147
bool circulate(const CirculatorBase::direction dir=CirculatorBase::NONE)
Circulate around the list in the given direction.
Definition: CirculatorI.H:129
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:168
reference next() const
Dereference the next iterator.
Definition: CirculatorI.H:170