Loading...
Searching...
No Matches
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_;
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>
114 return (end_ == begin_);
115}
116
117
118template<class Container, bool Const>
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();
148
149 return !(iter_ == fulcrum_);
150}
151
152
153template<class Container, bool Const>
158
159
160template<class Container, bool Const>
163 iter_ = fulcrum_;
164}
165
166
167template<class Container, bool Const>
171 return *iter_;
172}
173
174
175template<class Container, bool Const>
178{
179 if (iter_ == end_ - 1)
180 {
181 return *begin_;
182 }
184 return *(iter_ + 1);
185}
186
187
188template<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
203template<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
221template<class Container, bool Const>
224{
225 this->increment();
226 return *this;
228
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
249template<class Container, bool Const>
252{
253 auto old(*this);
254 this->decrement();
255 return old;
256}
257
259template<class Container, bool Const>
261(
263) const
264{
265 return this->equal(rhs);
266}
267
269template<class Container, bool Const>
271(
273) const
275 return !this->equal(rhs);
276}
278
279template<class Container, bool Const>
283 return *iter_;
285
286
287template<class Container, bool Const>
291 return *iter_;
292}
293
294
295template<class Container, bool Const>
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:114
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
bool circulate(const CirculatorBase::direction dir=CirculatorBase::NONE)
Circulate around the list in the given direction.
difference_type nRotations() const
The distance between the iterator and the fulcrum.
reference prev() const
Dereference the previous iterator.
reference operator*() const
Dereference the iterator. Same as curr().
std::conditional_t< Const, typename Container::const_reference, typename Container::reference > reference
The reference type (const/non-const).
Definition Circulator.H:142
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
size_type size() const
Return the range of the iterator pair.
reference operator()() const
Dereference the iterator. Same as curr().
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.
CirculatorIters< Container, Const > & operator--()
Prefix decrement the iterator.
bool equal(const CirculatorIters< Container, Const > &rhs)
Compare for equality.
Definition CirculatorI.H:26
reference curr() const
Dereference the current iterator.
CirculatorIters< Container, Const > & operator++()
Prefix increment the iterator.
reference next() const
Dereference the next iterator.
CirculatorIters()
Default construct.
Definition CirculatorI.H:66
typename Container::difference_type difference_type
The type that represents difference between iterator objects.
Definition Circulator.H:127
void increment()
Move iterator forward.
Definition CirculatorI.H:41
std::conditional_t< Const, typename Container::const_iterator, typename Container::iterator > iterator
The container iterator type (const/non-const).
Definition Circulator.H:132
void decrement()
Move iterator backward.
Definition CirculatorI.H:52
bool equal(const T &a, const T &b)
Compare two values for equality.
Definition label.H:180
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)