ConstCirculatorI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2012-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class ContainerType>
30 :
32  begin_(0),
33  end_(0),
34  iter_(0),
35  fulcrum_(0)
36 {}
37 
38 
39 template<class ContainerType>
41 (
42  const ContainerType& container
43 )
44 :
46  begin_(container.begin()),
47  end_(container.end()),
48  iter_(begin_),
50 {}
51 
52 
53 template<class ContainerType>
55 (
56  const const_iterator& begin,
57  const 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 (
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 {
106  {
107  operator++();
108  }
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>
169 void Foam::ConstCirculator<ContainerType>::operator=
170 (
172 )
173 {
174  // Check for assignment to self
175  if (this == &rhs)
176  {
178  << "Attempted assignment to self"
179  << abort(FatalError);
180  }
181 
182  begin_ = rhs.begin_;
183  end_ = rhs.end_;
184  iter_ = rhs.iter_;
185  fulcrum_ = rhs.fulcrum_;
186 }
187 
188 
189 template<class ContainerType>
192 {
193  ++iter_;
194  if (iter_ == end_)
195  {
196  iter_ = begin_;
197  }
198 
199  return *this;
200 }
201 
202 
203 template<class ContainerType>
206 {
208  ++(*this);
209  return tmp;
210 }
211 
212 
213 template<class ContainerType>
216 {
217  if (iter_ == begin_)
218  {
219  iter_ = end_;
220  }
221  --iter_;
222 
223  return *this;
224 }
225 
226 
227 template<class ContainerType>
230 {
232  --(*this);
233  return tmp;
234 }
235 
236 
237 template<class ContainerType>
238 bool Foam::ConstCirculator<ContainerType>::operator==
239 (
241 ) const
242 {
243  return
244  (
245  begin_ == c.begin_
246  && end_ == c.end_
247  && iter_ == c.iter_
248  && fulcrum_ == c.fulcrum_
249  );
250 }
251 
252 
253 template<class ContainerType>
254 bool Foam::ConstCirculator<ContainerType>::operator!=
255 (
257 ) const
258 {
259  return !(*this == c);
260 }
261 
262 
263 template<class ContainerType>
266 {
267  return *iter_;
268 }
269 
270 
271 template<class ContainerType>
274 {
275  return operator*();
276 }
277 
278 
279 template<class ContainerType>
281 Foam::ConstCirculator<ContainerType>::operator-
282 (
284 ) const
285 {
286  return iter_ - c.iter_;
287 }
288 
289 
290 // ************************************************************************* //
ContainerType::const_iterator end_
Iterator pointing to the end of the container.
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
ContainerType::difference_type difference_type
The type that can represent the difference between any two.
ContainerType::size_type size_type
The type that can represent the size of ContainerType.
direction
Direction type enumeration.
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
CirculatorBase()
Construct null.
const dimensionedScalar & c
Speed of light in a vacuum.
const_reference prev() const
Dereference the previous iterator and return.
~ConstCirculator()
Destructor.
ConstCirculator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
ContainerType::const_iterator iter_
Iterator.
size_type size() const
Return the range of the iterator.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
ConstCirculator()
Construct null.
ContainerType::const_iterator const_iterator
Random access iterator for traversing ContainerType.
ContainerType::const_iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
ContainerType::const_iterator begin_
Iterator pointing to the beginning of the container.
ConstCirculator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
Base class for circulators.
bool circulate(const CirculatorBase::direction dir=CirculatorBase::direction::none)
Circulate around the list in the given direction.
const_reference operator*() const
Dereference the iterator and return.
const_reference operator()() const
Dereference the iterator and return.
const_reference next() const
Dereference the next iterator and return.
ContainerType::const_reference const_reference
Type that can be used for storing into.
Walks over a container as if it were circular. The container must have the following members defined:...
A class for managing temporary objects.
Definition: PtrList.H:53
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.