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 | 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 :
43  begin_(container.begin()),
44  end_(container.end()),
45  iter_(begin_),
47 {}
48 
49 
50 template<class ContainerType>
52 (
53  const iterator& begin,
54  const iterator& end
55 )
56 :
58  begin_(begin),
59  end_(end),
60  iter_(begin),
61  fulcrum_(begin)
62 {}
63 
64 
65 template<class ContainerType>
67 (
68  const Circulator<ContainerType>& rhs
69 )
70 :
72  begin_(rhs.begin_),
73  end_(rhs.end_),
74  iter_(rhs.iter_),
75  fulcrum_(rhs.fulcrum_)
76 {}
77 
78 
79 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
80 
81 template<class ContainerType>
83 {}
84 
85 
86 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
87 
88 template<class ContainerType>
91 {
92  return end_ - begin_;
93 }
94 
95 
96 template<class ContainerType>
98 (
100 )
101 {
102  if (dir == CirculatorBase::CLOCKWISE)
103  {
104  operator++();
105  }
106  else if (dir == CirculatorBase::ANTICLOCKWISE)
107  {
108  operator--();
109  }
110 
111  return !(iter_ == fulcrum_);
112 }
113 
114 
115 template<class ContainerType>
117 {
118  fulcrum_ = iter_;
119 }
120 
121 
122 template<class ContainerType>
124 {
125  iter_ = fulcrum_;
126 }
127 
128 
129 template<class ContainerType>
132 {
133  return (iter_ - fulcrum_);
134 }
135 
136 
137 template<class ContainerType>
140 {
141  if (iter_ == end_ - 1)
142  {
143  return *begin_;
144  }
145 
146  return *(iter_ + 1);
147 }
148 
149 
150 template<class ContainerType>
153 {
154  if (iter_ == begin_)
155  {
156  return *(end_ - 1);
157  }
158 
159  return *(iter_ - 1);
160 }
161 
162 
163 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
164 
165 template<class ContainerType>
166 void Foam::Circulator<ContainerType>::operator=
167 (
168  const Circulator<ContainerType>& rhs
169 )
170 {
171  // Check for assignment to self
172  if (this == &rhs)
173  {
175  (
176  "Foam::Circulator<ContainerType>::operator="
177  "(const Foam::Circulator<ContainerType>&)"
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::Circulator<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::Circulator<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::Circulator<ContainerType>::operator-
282 (
284 ) const
285 {
286  return iter_ - c.iter_;
287 }
288 
289 
290 // ************************************************************************* //
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
Definition: CirculatorI.H:131
CirculatorBase()
Construct null.
size_type size() const
Return the range of the iterator.
Definition: CirculatorI.H:90
~Circulator()
Destructor.
Definition: CirculatorI.H:82
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
Definition: CirculatorI.H:116
ContainerType::iterator iter_
Random access iterator for traversing ContainerType.
Definition: Circulator.H:91
ContainerType::iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
Definition: Circulator.H:96
direction
Direction type enumeration.
reference prev() const
Dereference the previous iterator and return.
Definition: CirculatorI.H:152
Circulator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
Definition: CirculatorI.H:215
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Circulator()
Construct null.
Definition: CirculatorI.H:29
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
Circulator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
Definition: CirculatorI.H:191
ContainerType::iterator end_
Iterator pointing to the end of the container.
Definition: Circulator.H:88
ContainerType::difference_type difference_type
The type that can represent the difference between any two.
Definition: Circulator.H:111
void setIteratorToFulcrum()
Set the iterator to the current position of the fulcrum.
Definition: CirculatorI.H:123
error FatalError
Base class for circulators.
const dimensionedScalar c
Speed of light in a vacuum.
reference operator()() const
Dereference the iterator and return.
Definition: CirculatorI.H:273
ContainerType::iterator begin_
Iterator pointing to the beginning of the container.
Definition: Circulator.H:85
ContainerType::size_type size_type
The type that can represent the size of ContainerType.
Definition: Circulator.H:107
reference next() const
Dereference the next iterator and return.
Definition: CirculatorI.H:139
ContainerType::reference reference
Type that can be used for storing into.
Definition: Circulator.H:118
reference operator*() const
Dereference the iterator and return.
Definition: CirculatorI.H:265
ContainerType::iterator iterator
Random access iterator for traversing ContainerType.
Definition: Circulator.H:114
bool circulate(const CirculatorBase::direction dir=NONE)
Circulate around the list in the given direction.
Definition: CirculatorI.H:98
A class for managing temporary objects.
Definition: PtrList.H:118
Walks over a container as if it were circular. The container must have the following members defined:...
Definition: Circulator.H:75