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-------------------------------------------------------------------------------
11License
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
31template<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
47template<class Container, bool Const>
49{
50 ++iter_;
51 if (iter_ == end_)
52 {
53 iter_ = begin_;
54 }
55}
56
57
58template<class Container, bool Const>
60{
61 if (iter_ == begin_)
62 {
63 iter_ = end_;
64 }
65 --iter_;
66}
67
68
69
70// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
71
72template<class Container, bool Const>
74:
75 begin_(0),
76 end_(0),
77 iter_(0),
78 fulcrum_(0)
79{}
80
81
82template<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
96template<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
111template<class Container, bool Const>
113{
114 return (end_ == begin_);
115}
116
117
118template<class Container, bool Const>
121{
122 return (end_ - begin_);
123}
124
125
126template<class Container, bool Const>
129{
130 return (iter_ - fulcrum_);
131}
132
133
134template<class Container, bool Const>
136(
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
153template<class Container, bool Const>
155{
156 fulcrum_ = iter_;
157}
158
159
160template<class Container, bool Const>
163 iter_ = fulcrum_;
164}
166
167template<class Container, bool Const>
170{
171 return *iter_;
172}
173
174
175template<class Container, bool Const>
178{
179 if (iter_ == end_ - 1)
180 {
181 return *begin_;
183
184 return *(iter_ + 1);
185}
186
187
188template<class Container, bool Const>
192 if (iter_ == begin_)
193 {
194 return *(end_ - 1);
196
197 return *(iter_ - 1);
198}
200
201// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
202
203template<class Container, bool Const>
207)
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
221template<class Container, bool Const>
225 this->increment();
226 return *this;
227}
229
230template<class Container, bool Const>
233{
234 auto old(*this);
235 this->increment();
236 return old;
237}
238
239
240template<class Container, bool Const>
243{
244 this->decrement();
245 return *this;
246}
247
248
249template<class Container, bool Const>
252{
253 auto old(*this);
254 this->decrement();
255 return old;
256}
258
259template<class Container, bool Const>
261(
263) const
265 return this->equal(rhs);
266}
267
268
269template<class Container, bool Const>
271(
273) const
274{
275 return !this->equal(rhs);
276}
277
278
279template<class Container, bool Const>
282{
283 return *iter_;
284}
285
286
287template<class Container, bool Const>
290{
291 return *iter_;
292}
293
294
295template<class Container, bool Const>
298(
300) const
301{
302 return (iter_ - rhs.iter_);
303}
304
305
306// ************************************************************************* //
direction
Direction type enumeration.
Definition: Circulator.H:87
A pair of begin/end iterators used for implementing circular iteration.
Definition: Circulator.H:110
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
Definition: CirculatorI.H:154
bool circulate(const CirculatorBase::direction dir=CirculatorBase::NONE)
Definition: CirculatorI.H:136
difference_type nRotations() const
The distance between the iterator and the fulcrum.
Definition: CirculatorI.H:128
reference prev() const
Dereference the previous iterator.
Definition: CirculatorI.H:190
reference operator*() const
Dereference the iterator. Same as curr()
Definition: CirculatorI.H:281
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
Definition: CirculatorI.H:161
typename std::conditional< Const, typename Container::const_reference, typename Container::reference >::type reference
The reference type (const/non-const)
Definition: Circulator.H:135
size_type size() const
Return the range of the iterator pair.
Definition: CirculatorI.H:120
reference operator()() const
Dereference the iterator. Same as curr()
Definition: CirculatorI.H:289
typename Container::size_type size_type
The type that can represent the size of Container.
Definition: Circulator.H:116
bool empty() const
True if begin/end iterators are identical.
Definition: CirculatorI.H:112
CirculatorIters< Container, Const > & operator--()
Prefix decrement the iterator.
Definition: CirculatorI.H:242
bool equal(const CirculatorIters< Container, Const > &rhs)
Compare for equality.
Definition: CirculatorI.H:33
reference curr() const
Dereference the current iterator.
Definition: CirculatorI.H:169
CirculatorIters< Container, Const > & operator++()
Prefix increment the iterator.
Definition: CirculatorI.H:223
reference next() const
Dereference the next iterator.
Definition: CirculatorI.H:177
CirculatorIters()
Default construct.
Definition: CirculatorI.H:73
typename Container::difference_type difference_type
The type that represents difference between iterator objects.
Definition: Circulator.H:119
typename std::conditional< Const, typename Container::const_iterator, typename Container::iterator >::type iterator
The container iterator type (const/non-const)
Definition: Circulator.H:127
void increment()
Move iterator forward.
Definition: CirculatorI.H:48
void decrement()
Move iterator backward.
Definition: CirculatorI.H:59
bool equal(const T &s1, const T &s2)
Compare two values for equality.
Definition: doubleFloat.H:46