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 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class ContainerType>
33 :
35  begin_(0),
36  end_(0),
37  iter_(0),
38  fulcrum_(0)
39 {}
40 
41 
42 template<class ContainerType>
44 :
46  begin_(container.begin()),
47  end_(container.end()),
48  iter_(begin_),
49  fulcrum_(begin_)
50 {}
51 
52 
53 template<class ContainerType>
55 (
56  const iterator& begin,
57  const iterator& end
58 )
59 :
61  begin_(begin),
62  end_(end),
63  iter_(begin),
64  fulcrum_(begin)
65 {}
66 
67 
68 template<class ContainerType>
70 (
71  const Circulator<ContainerType>& rhs
72 )
73 :
75  begin_(rhs.begin_),
76  end_(rhs.end_),
77  iter_(rhs.iter_),
78  fulcrum_(rhs.fulcrum_)
79 {}
80 
81 
82 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
83 
84 template<class ContainerType>
86 {}
87 
88 
89 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
90 
91 template<class ContainerType>
94 {
95  return end_ - begin_;
96 }
97 
98 
99 template<class ContainerType>
101 (
102  const CirculatorBase::direction dir
103 )
104 {
105  if (dir == CirculatorBase::CLOCKWISE)
106  {
107  operator++();
108  }
109  else if (dir == CirculatorBase::ANTICLOCKWISE)
110  {
111  operator--();
112  }
113 
114  return !(iter_ == fulcrum_);
115 }
116 
117 
118 template<class ContainerType>
120 {
121  fulcrum_ = iter_;
122 }
123 
124 
125 template<class ContainerType>
127 {
128  iter_ = fulcrum_;
129 }
130 
131 
132 template<class ContainerType>
135 {
136  return (iter_ - fulcrum_);
137 }
138 
139 
140 template<class ContainerType>
143 {
144  if (iter_ == end_ - 1)
145  {
146  return *begin_;
147  }
148 
149  return *(iter_ + 1);
150 }
151 
152 
153 template<class ContainerType>
156 {
157  if (iter_ == begin_)
158  {
159  return *(end_ - 1);
160  }
161 
162  return *(iter_ - 1);
163 }
164 
165 
166 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
167 
168 template<class ContainerType>
170 (
171  const Circulator<ContainerType>& rhs
172 )
173 {
174  if (this == &rhs)
175  {
176  return; // Self-assignment is a no-op
177  }
178 
179  begin_ = rhs.begin_;
180  end_ = rhs.end_;
181  iter_ = rhs.iter_;
182  fulcrum_ = rhs.fulcrum_;
183 }
184 
185 
186 template<class ContainerType>
189 {
190  ++iter_;
191  if (iter_ == end_)
192  {
193  iter_ = begin_;
194  }
195 
196  return *this;
197 }
198 
199 
200 template<class ContainerType>
203 {
205  ++(*this);
206  return tmp;
207 }
208 
209 
210 template<class ContainerType>
213 {
214  if (iter_ == begin_)
215  {
216  iter_ = end_;
217  }
218  --iter_;
219 
220  return *this;
221 }
222 
223 
224 template<class ContainerType>
227 {
229  --(*this);
230  return tmp;
231 }
232 
233 
234 template<class ContainerType>
236 (
238 ) const
239 {
240  return
241  (
242  begin_ == c.begin_
243  && end_ == c.end_
244  && iter_ == c.iter_
245  && fulcrum_ == c.fulcrum_
246  );
247 }
248 
249 
250 template<class ContainerType>
252 (
254 ) const
255 {
256  return !(*this == c);
257 }
258 
259 
260 template<class ContainerType>
263 {
264  return *iter_;
265 }
266 
267 
268 template<class ContainerType>
271 {
272  return operator*();
273 }
274 
275 
276 template<class ContainerType>
279 (
281 ) const
282 {
283  return iter_ - c.iter_;
284 }
285 
286 
287 // ************************************************************************* //
Foam::Circulator::operator*
reference operator*() const
Dereference the iterator and return.
Definition: CirculatorI.H:262
Foam::Circulator::circulate
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
Definition: CirculatorI.H:101
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
Foam::Circulator::size_type
ContainerType::size_type size_type
The type that can represent the size of ContainerType.
Definition: Circulator.H:109
Foam::Circulator::fulcrum_
ContainerType::iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
Definition: Circulator.H:98
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::Circulator::setFulcrumToIterator
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
Definition: CirculatorI.H:119
Foam::Circulator
Walks over a container as if it were circular. The container must have the following members defined:
Definition: Circulator.H:77
Foam::Circulator::operator++
Circulator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
Definition: CirculatorI.H:188
Foam::Circulator::difference_type
ContainerType::difference_type difference_type
The type that can represent the difference between any two.
Definition: Circulator.H:113
Foam::Circulator::iterator
ContainerType::iterator iterator
Random access iterator for traversing ContainerType.
Definition: Circulator.H:116
Foam::Circulator::prev
reference prev() const
Dereference the previous iterator and return.
Definition: CirculatorI.H:155
Foam::Circulator::operator()
reference operator()() const
Dereference the iterator and return.
Definition: CirculatorI.H:270
Foam::Circulator::Circulator
Circulator()
Construct null.
Definition: CirculatorI.H:32
Foam::Circulator::reference
ContainerType::reference reference
Type that can be used for storing into.
Definition: Circulator.H:120
Foam::Circulator::iter_
ContainerType::iterator iter_
Random access iterator for traversing ContainerType.
Definition: Circulator.H:93
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::Circulator::next
reference next() const
Dereference the next iterator and return.
Definition: CirculatorI.H:142
Foam::CirculatorBase::direction
direction
Direction type enumeration.
Definition: CirculatorBase.H:53
Foam::CirculatorBase::CLOCKWISE
Definition: CirculatorBase.H:56
Foam::Circulator::~Circulator
~Circulator()
Destructor.
Definition: CirculatorI.H:85
Foam::Circulator::nRotations
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
Definition: CirculatorI.H:134
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::Circulator::size
size_type size() const
Return the range of the iterator.
Definition: CirculatorI.H:93
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::Circulator::end_
ContainerType::iterator end_
Iterator pointing to the end of the container.
Definition: Circulator.H:90
Foam::CirculatorBase
Base class for circulators.
Definition: CirculatorBase.H:46
Foam::CirculatorBase::ANTICLOCKWISE
Definition: CirculatorBase.H:57
Foam::Circulator::begin_
ContainerType::iterator begin_
Iterator pointing to the beginning of the container.
Definition: Circulator.H:87
Foam::Circulator::setIteratorToFulcrum
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
Definition: CirculatorI.H:126
Foam::Circulator::operator--
Circulator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
Definition: CirculatorI.H:212