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 | Copyright (C) 2012-2015 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 {
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>
169 void Foam::ConstCirculator<ContainerType>::operator=
170 (
172 )
173 {
174  // Check for assignment to self
175  if (this == &rhs)
176  {
178  (
179  "Foam::ConstCirculator<ContainerType>::operator="
180  "(const Foam::ConstCirculator<ContainerType>&)"
181  ) << "Attempted assignment to self"
182  << abort(FatalError);
183  }
184 
185  begin_ = rhs.begin_;
186  end_ = rhs.end_;
187  iter_ = rhs.iter_;
188  fulcrum_ = rhs.fulcrum_;
189 }
190 
191 
192 template<class ContainerType>
195 {
196  ++iter_;
197  if (iter_ == end_)
198  {
199  iter_ = begin_;
200  }
201 
202  return *this;
203 }
204 
205 
206 template<class ContainerType>
209 {
211  ++(*this);
212  return tmp;
213 }
214 
215 
216 template<class ContainerType>
219 {
220  if (iter_ == begin_)
221  {
222  iter_ = end_;
223  }
224  --iter_;
225 
226  return *this;
227 }
228 
229 
230 template<class ContainerType>
233 {
235  --(*this);
236  return tmp;
237 }
238 
239 
240 template<class ContainerType>
241 bool Foam::ConstCirculator<ContainerType>::operator==
242 (
244 ) const
245 {
246  return
247  (
248  begin_ == c.begin_
249  && end_ == c.end_
250  && iter_ == c.iter_
251  && fulcrum_ == c.fulcrum_
252  );
253 }
254 
255 
256 template<class ContainerType>
257 bool Foam::ConstCirculator<ContainerType>::operator!=
258 (
260 ) const
261 {
262  return !(*this == c);
263 }
264 
265 
266 template<class ContainerType>
269 {
270  return *iter_;
271 }
272 
273 
274 template<class ContainerType>
277 {
278  return operator*();
279 }
280 
281 
282 template<class ContainerType>
284 Foam::ConstCirculator<ContainerType>::operator-
285 (
287 ) const
288 {
289  return iter_ - c.iter_;
290 }
291 
292 
293 // ************************************************************************* //
ContainerType::const_iterator end_
Iterator pointing to the end of the container.
ConstCirculator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
CirculatorBase()
Construct null.
Walks over a container as if it were circular. The container must have the following members defined:...
ContainerType::const_iterator const_iterator
Random access iterator for traversing ContainerType.
direction
Direction type enumeration.
size_type size() const
Return the range of the iterator.
const_reference operator()() const
Dereference the iterator and return.
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
const_reference operator*() const
Dereference the iterator and return.
~ConstCirculator()
Destructor.
ConstCirculator()
Construct null.
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
ContainerType::const_iterator iter_
Iterator.
ContainerType::const_iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
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.
ConstCirculator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
ContainerType::const_reference const_reference
Type that can be used for storing into.
error FatalError
Base class for circulators.
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
const dimensionedScalar c
Speed of light in a vacuum.
ContainerType::const_iterator begin_
Iterator pointing to the beginning of the container.
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
const_reference next() const
Dereference the next iterator and return.
A class for managing temporary objects.
Definition: PtrList.H:118
const_reference prev() const
Dereference the previous iterator and return.