ConstCirculatorI.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 #include "error.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class ContainerType>
35 :
37  begin_(0),
38  end_(0),
39  iter_(0),
40  fulcrum_(0)
41 {}
42 
43 
44 template<class ContainerType>
46 (
47  const ContainerType& container
48 )
49 :
51  begin_(container.begin()),
52  end_(container.end()),
53  iter_(begin_),
54  fulcrum_(begin_)
55 {}
56 
57 
58 template<class ContainerType>
60 (
61  const const_iterator& begin,
62  const const_iterator& end
63 )
64 :
66  begin_(begin),
67  end_(end),
68  iter_(begin),
69  fulcrum_(begin)
70 {}
71 
72 
73 template<class ContainerType>
75 (
77 )
78 :
80  begin_(rhs.begin_),
81  end_(rhs.end_),
82  iter_(rhs.iter_),
83  fulcrum_(rhs.fulcrum_)
84 {}
85 
86 
87 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
88 
89 template<class ContainerType>
91 {}
92 
93 
94 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
95 
96 template<class ContainerType>
99 {
100  return end_ - begin_;
101 }
102 
103 
104 template<class ContainerType>
106 (
107  const CirculatorBase::direction dir
108 )
109 {
110  if (dir == CirculatorBase::CLOCKWISE)
111  {
112  operator++();
113  }
114  else if (dir == CirculatorBase::ANTICLOCKWISE)
115  {
116  operator--();
117  }
118 
119  return !(iter_ == fulcrum_);
120 }
121 
122 
123 template<class ContainerType>
125 {
126  fulcrum_ = iter_;
127 }
128 
129 
130 template<class ContainerType>
132 {
133  iter_ = fulcrum_;
134 }
135 
136 
137 template<class ContainerType>
140 {
141  return (iter_ - fulcrum_);
142 }
143 
144 
145 template<class ContainerType>
148 {
149  if (iter_ == end_ - 1)
150  {
151  return *begin_;
152  }
153 
154  return *(iter_ + 1);
155 }
156 
157 
158 template<class ContainerType>
161 {
162  if (iter_ == begin_)
163  {
164  return *(end_ - 1);
165  }
166 
167  return *(iter_ - 1);
168 }
169 
170 
171 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
172 
173 template<class ContainerType>
175 (
177 )
178 {
179  if (this == &rhs)
180  {
181  return; // Self-assignment is a no-op
182  }
183 
184  begin_ = rhs.begin_;
185  end_ = rhs.end_;
186  iter_ = rhs.iter_;
187  fulcrum_ = rhs.fulcrum_;
188 }
189 
190 
191 template<class ContainerType>
194 {
195  ++iter_;
196  if (iter_ == end_)
197  {
198  iter_ = begin_;
199  }
200 
201  return *this;
202 }
203 
204 
205 template<class ContainerType>
208 {
210  ++(*this);
211  return tmp;
212 }
213 
214 
215 template<class ContainerType>
218 {
219  if (iter_ == begin_)
220  {
221  iter_ = end_;
222  }
223  --iter_;
224 
225  return *this;
226 }
227 
228 
229 template<class ContainerType>
232 {
234  --(*this);
235  return tmp;
236 }
237 
238 
239 template<class ContainerType>
241 (
243 ) const
244 {
245  return
246  (
247  begin_ == c.begin_
248  && end_ == c.end_
249  && iter_ == c.iter_
250  && fulcrum_ == c.fulcrum_
251  );
252 }
253 
254 
255 template<class ContainerType>
257 (
259 ) const
260 {
261  return !(*this == c);
262 }
263 
264 
265 template<class ContainerType>
268 {
269  return *iter_;
270 }
271 
272 
273 template<class ContainerType>
276 {
277  return operator*();
278 }
279 
280 
281 template<class ContainerType>
284 (
286 ) const
287 {
288  return iter_ - c.iter_;
289 }
290 
291 
292 // ************************************************************************* //
Foam::ConstCirculator::begin_
ContainerType::const_iterator begin_
Definition: ConstCirculator.H:99
Foam::ConstCirculator::end_
ContainerType::const_iterator end_
Definition: ConstCirculator.H:102
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Definition: stdFoam.H:96
Foam::ConstCirculator::const_reference
ContainerType::const_reference const_reference
Definition: ConstCirculator.H:132
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:57
Foam::ConstCirculator
Walks over a container as if it were circular. The container must have the following members defined:
Definition: ConstCirculator.H:89
Foam::ConstCirculator::size_type
ContainerType::size_type size_type
Definition: ConstCirculator.H:121
Foam::ConstCirculator::setIteratorToFulcrum
void setIteratorToFulcrum()
Definition: ConstCirculatorI.H:124
Foam::ConstCirculator::difference_type
ContainerType::difference_type difference_type
Definition: ConstCirculator.H:125
Foam::ConstCirculator::~ConstCirculator
~ConstCirculator()
Definition: ConstCirculatorI.H:83
Foam::ConstCirculator::operator++
ConstCirculator< ContainerType > & operator++()
Definition: ConstCirculatorI.H:186
Foam::ConstCirculator::const_iterator
ContainerType::const_iterator const_iterator
Definition: ConstCirculator.H:128
Foam::ConstCirculator::fulcrum_
ContainerType::const_iterator fulcrum_
Definition: ConstCirculator.H:110
error.H
Foam::ConstCirculator::ConstCirculator
ConstCirculator()
Definition: ConstCirculatorI.H:27
Foam::ConstCirculator::size
size_type size() const
Definition: ConstCirculatorI.H:91
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Definition: stdFoam.H:129
Foam::ConstCirculator::nRotations
difference_type nRotations() const
Definition: ConstCirculatorI.H:132
Foam::ConstCirculator::operator()
const_reference operator()() const
Definition: ConstCirculatorI.H:268
Foam::CirculatorBase::direction
direction
Definition: CirculatorBase.H:47
Foam::CirculatorBase::CLOCKWISE
@ CLOCKWISE
Definition: CirculatorBase.H:50
Foam::ConstCirculator::operator*
const_reference operator*() const
Definition: ConstCirculatorI.H:260
Foam::ConstCirculator::iter_
ContainerType::const_iterator iter_
Definition: ConstCirculator.H:105
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::constant::universal::c
const dimensionedScalar c
Foam::ConstCirculator::setFulcrumToIterator
void setFulcrumToIterator()
Definition: ConstCirculatorI.H:117
Foam::ConstCirculator::next
const_reference next() const
Definition: ConstCirculatorI.H:140
Foam::CirculatorBase
Base class for circulators.
Definition: CirculatorBase.H:40
Foam::CirculatorBase::ANTICLOCKWISE
@ ANTICLOCKWISE
Definition: CirculatorBase.H:51
Foam::ConstCirculator::circulate
bool circulate(const CirculatorBase::direction dir=NONE)
Definition: ConstCirculatorI.H:99
Foam::ConstCirculator::prev
const_reference prev() const
Definition: ConstCirculatorI.H:153
Foam::ConstCirculator::operator--
ConstCirculator< ContainerType > & operator--()
Definition: ConstCirculatorI.H:210