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_
Iterator pointing to the beginning of the container.
Definition: ConstCirculator.H:103
Foam::ConstCirculator::end_
ContainerType::const_iterator end_
Iterator pointing to the end of the container.
Definition: ConstCirculator.H:106
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
Foam::ConstCirculator::const_reference
ContainerType::const_reference const_reference
Type that can be used for storing into.
Definition: ConstCirculator.H:136
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:61
Foam::ConstCirculator
Walks over a container as if it were circular. The container must have the following members defined:
Definition: ConstCirculator.H:93
Foam::ConstCirculator::size_type
ContainerType::size_type size_type
The type that can represent the size of ContainerType.
Definition: ConstCirculator.H:125
Foam::ConstCirculator::setIteratorToFulcrum
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
Definition: ConstCirculatorI.H:131
Foam::ConstCirculator::difference_type
ContainerType::difference_type difference_type
The type that can represent the difference between any two.
Definition: ConstCirculator.H:129
Foam::ConstCirculator::~ConstCirculator
~ConstCirculator()
Destructor.
Definition: ConstCirculatorI.H:90
Foam::ConstCirculator::operator++
ConstCirculator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
Definition: ConstCirculatorI.H:193
Foam::ConstCirculator::const_iterator
ContainerType::const_iterator const_iterator
Random access iterator for traversing ContainerType.
Definition: ConstCirculator.H:132
Foam::ConstCirculator::fulcrum_
ContainerType::const_iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
Definition: ConstCirculator.H:114
error.H
Foam::ConstCirculator::ConstCirculator
ConstCirculator()
Construct null.
Definition: ConstCirculatorI.H:34
Foam::ConstCirculator::size
size_type size() const
Return the range of the iterator.
Definition: ConstCirculatorI.H:98
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::ConstCirculator::nRotations
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
Definition: ConstCirculatorI.H:139
Foam::ConstCirculator::operator()
const_reference operator()() const
Dereference the iterator and return.
Definition: ConstCirculatorI.H:275
Foam::CirculatorBase::direction
direction
Direction type enumeration.
Definition: CirculatorBase.H:53
Foam::CirculatorBase::CLOCKWISE
Definition: CirculatorBase.H:56
Foam::ConstCirculator::operator*
const_reference operator*() const
Dereference the iterator and return.
Definition: ConstCirculatorI.H:267
Foam::ConstCirculator::iter_
ContainerType::const_iterator iter_
Iterator.
Definition: ConstCirculator.H:109
Foam::operator*
tmp< faMatrix< Type > > operator*(const areaScalarField &, const faMatrix< Type > &)
Foam::constant::universal::c
const dimensionedScalar c
Speed of light in a vacuum.
Foam::ConstCirculator::setFulcrumToIterator
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
Definition: ConstCirculatorI.H:124
Foam::ConstCirculator::next
const_reference next() const
Dereference the next iterator and return.
Definition: ConstCirculatorI.H:147
Foam::CirculatorBase
Base class for circulators.
Definition: CirculatorBase.H:46
Foam::CirculatorBase::ANTICLOCKWISE
Definition: CirculatorBase.H:57
Foam::ConstCirculator::circulate
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
Definition: ConstCirculatorI.H:106
Foam::ConstCirculator::prev
const_reference prev() const
Dereference the previous iterator and return.
Definition: ConstCirculatorI.H:160
Foam::ConstCirculator::operator--
ConstCirculator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
Definition: ConstCirculatorI.H:217