All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
CirculatorI.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 :
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 {
103  {
104  operator++();
105  }
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  << "Attempted assignment to self"
176  << abort(FatalError);
177  }
178 
179  begin_ = rhs.begin_;
180  end_ = rhs.end_;
181  iter_ = rhs.iter_;
182  fulcrum_ = rhs.fulcrum_;
183 }
184 
185 
186 template<class ContainerType>
189 {
190  ++iter_;
191  if (iter_ == end_)
192  {
193  iter_ = begin_;
194  }
195 
196  return *this;
197 }
198 
199 
200 template<class ContainerType>
203 {
205  ++(*this);
206  return tmp;
207 }
208 
209 
210 template<class ContainerType>
213 {
214  if (iter_ == begin_)
215  {
216  iter_ = end_;
217  }
218  --iter_;
219 
220  return *this;
221 }
222 
223 
224 template<class ContainerType>
227 {
229  --(*this);
230  return tmp;
231 }
232 
233 
234 template<class ContainerType>
235 bool Foam::Circulator<ContainerType>::operator==
236 (
238 ) const
239 {
240  return
241  (
242  begin_ == c.begin_
243  && end_ == c.end_
244  && iter_ == c.iter_
245  && fulcrum_ == c.fulcrum_
246  );
247 }
248 
249 
250 template<class ContainerType>
251 bool Foam::Circulator<ContainerType>::operator!=
252 (
254 ) const
255 {
256  return !(*this == c);
257 }
258 
259 
260 template<class ContainerType>
263 {
264  return *iter_;
265 }
266 
267 
268 template<class ContainerType>
271 {
272  return operator*();
273 }
274 
275 
276 template<class ContainerType>
278 Foam::Circulator<ContainerType>::operator-
279 (
281 ) const
282 {
283  return iter_ - c.iter_;
284 }
285 
286 
287 // ************************************************************************* //
Circulator()
Construct null.
Definition: CirculatorI.H:29
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
Circulator< ContainerType > & operator--()
Prefix decrement. Decrements the iterator.
Definition: CirculatorI.H:212
ContainerType::iterator end_
Iterator pointing to the end of the container.
Definition: Circulator.H:88
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
ContainerType::iterator iterator
Random access iterator for traversing ContainerType.
Definition: Circulator.H:114
~Circulator()
Destructor.
Definition: CirculatorI.H:82
difference_type nRotations() const
Return the distance between the iterator and the fulcrum. This is.
Definition: CirculatorI.H:131
direction
Direction type enumeration.
void setFulcrumToIterator()
Set the fulcrum to the current position of the iterator.
Definition: CirculatorI.H:116
CirculatorBase()
Construct null.
size_type size() const
Return the range of the iterator.
Definition: CirculatorI.H:90
const dimensionedScalar c
Speed of light in a vacuum.
ContainerType::iterator fulcrum_
Iterator holding the location of the fulcrum (start and end) of.
Definition: Circulator.H:96
reference next() const
Dereference the next iterator and return.
Definition: CirculatorI.H:139
reference operator*() const
Dereference the iterator and return.
Definition: CirculatorI.H:262
ContainerType::size_type size_type
The type that can represent the size of ContainerType.
Definition: Circulator.H:107
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Circulator< ContainerType > & operator++()
Prefix increment. Increments the iterator.
Definition: CirculatorI.H:188
bool circulate(const CirculatorBase::direction dir=CirculatorBase::direction::none)
Circulate around the list in the given direction.
Definition: CirculatorI.H:98
Walks over a container as if it were circular. The container must have the following members defined:...
Definition: Circulator.H:75
reference operator()() const
Dereference the iterator and return.
Definition: CirculatorI.H:270
ContainerType::iterator iter_
Random access iterator for traversing ContainerType.
Definition: Circulator.H:91
reference prev() const
Dereference the previous iterator and return.
Definition: CirculatorI.H:152
Base class for circulators.
ContainerType::reference reference
Type that can be used for storing into.
Definition: Circulator.H:118
A class for managing temporary objects.
Definition: PtrList.H:53
ContainerType::iterator begin_
Iterator pointing to the beginning of the container.
Definition: Circulator.H:85