SLListBaseI.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) 2011-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 Description
25  Base singly-linked list.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "error.H"
30 
31 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
32 
34 :
35  next_(0)
36 {}
37 
38 
40 :
41  next_(p)
42 {}
43 
44 
46 :
47  last_(0),
48  nElmts_(0)
49 {}
50 
51 
53 :
54  last_(a->next_ = a),
55  nElmts_(1)
56 {}
57 
58 
59 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
60 
62 {}
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
68 {
69  return nElmts_;
70 }
71 
72 
73 inline bool Foam::SLListBase::empty() const
74 {
75  return !nElmts_;
76 }
77 
78 
81 {
82  if (!nElmts_)
83  {
85  << "list is empty"
86  << abort(FatalError);
87  }
88  return last_->next_;
89 }
90 
91 
92 inline const Foam::SLListBase::link*
94 {
95  if (!nElmts_)
96  {
98  << "list is empty"
99  << abort(FatalError);
100  }
101  return last_->next_;
102 }
103 
104 
107 {
108  if (!nElmts_)
109  {
111  << "list is empty"
112  << abort(FatalError);
113  }
114  return last_;
115 }
116 
117 
118 inline const Foam::SLListBase::link*
120 {
121  if (!nElmts_)
122  {
124  << "list is empty"
125  << abort(FatalError);
126  }
127  return last_;
128 }
129 
130 
132 {
133  last_ = 0;
134  nElmts_ = 0;
135 }
136 
137 
139 {
140  last_ = lst.last_;
141  nElmts_ = lst.nElmts_;
142 
143  lst.clear();
144 }
145 
146 
148 (
150 )
151 {
152  return remove(it.curElmt_);
153 }
154 
155 
156 // * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
157 
158 inline Foam::SLListBase::iterator::iterator(SLListBase& s, link* elmt)
159 :
160  curList_(s),
161  curElmt_(elmt),
162  curLink_(*curElmt_)
163 {}
164 
165 
166 inline Foam::SLListBase::iterator::iterator(SLListBase& s)
167 :
168  curList_(s),
169  curElmt_(nullptr),
170  curLink_()
171 {}
172 
173 
175 {
176  curElmt_ = iter.curElmt_;
177  curLink_ = iter.curLink_;
178 }
179 
180 
181 inline bool Foam::SLListBase::iterator::operator==(const iterator& iter) const
182 {
183  return curElmt_ == iter.curElmt_;
184 }
185 
186 
187 inline bool Foam::SLListBase::iterator::operator!=(const iterator& iter) const
188 {
189  return curElmt_ != iter.curElmt_;
190 }
191 
192 
194 {
195  return *curElmt_;
196 }
197 
198 
200 {
201  if (curElmt_ == curList_.last_ || curList_.last_ == 0)
202  {
203  curElmt_ = 0;
204  }
205  else
206  {
207  curElmt_ = curLink_.next_;
208  curLink_ = *curElmt_;
209  }
210 
211  return *this;
212 }
213 
214 
217 {
218  iterator tmp = *this;
219  ++*this;
220  return tmp;
221 }
222 
223 
226 {
227  if (size())
228  {
229  return iterator(*this, first());
230  }
231  else
232  {
233  return endIter_;
234  }
235 }
236 
237 
238 inline const Foam::SLListBase::iterator&
240 {
241  return endIter_;
242 }
243 
244 
245 // * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
246 
248 (
249  const SLListBase& s,
250  const link* elmt
251 )
252 :
253  curList_(s),
254  curElmt_(elmt)
255 {}
256 
257 
259 :
260  curList_(iter.curList_),
261  curElmt_(iter.curElmt_)
262 {}
263 
264 
265 inline void Foam::SLListBase::const_iterator::operator=
266 (
267  const const_iterator& iter
268 )
269 {
270  curElmt_ = iter.curElmt_;
271 }
272 
273 
274 inline bool Foam::SLListBase::const_iterator::operator==
275 (
276  const const_iterator& iter
277 ) const
278 {
279  return curElmt_ == iter.curElmt_;
280 }
281 
282 
283 inline bool Foam::SLListBase::const_iterator::operator!=
284 (
285  const const_iterator& iter
286 ) const
287 {
288  return curElmt_ != iter.curElmt_;
289 }
290 
291 
292 inline const Foam::SLListBase::link&
294 {
295  return *curElmt_;
296 }
297 
298 
301 {
302  if (curElmt_ == curList_.last_)
303  {
304  curElmt_ = 0;
305  }
306  else
307  {
308  curElmt_ = curElmt_->next_;
309  }
310 
311  return *this;
312 }
313 
314 
317 {
318  const_iterator tmp = *this;
319  ++*this;
320  return tmp;
321 }
322 
323 
326 {
327  if (size())
328  {
329  return const_iterator(*this, first());
330  }
331  else
332  {
333  return endConstIter_;
334  }
335 }
336 
337 
340 {
341  return endConstIter_;
342 }
343 
344 
347 {
348  return this->cbegin();
349 }
350 
351 
354 {
355  return endConstIter_;
356 }
357 
358 
359 // ************************************************************************* //
link * first()
Return first entry.
Definition: SLListBaseI.H:80
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Base singly-linked list.
Definition: SLListBase.H:50
void clear()
Clear the list.
Definition: SLListBaseI.H:131
void transfer(SLListBase &)
Transfer the contents of the argument into this List.
Definition: SLListBaseI.H:138
An STL-conforming const_iterator.
Definition: SLListBase.H:215
SLListBase()
Null construct.
Definition: SLListBaseI.H:45
const_iterator cbegin() const
Definition: SLListBaseI.H:325
label size() const
Return number of elements in list.
Definition: SLListBaseI.H:67
const const_iterator & cend() const
Definition: SLListBaseI.H:339
const_iterator & operator++()
Definition: SLListBaseI.H:300
errorManip< error > abort(error &err)
Definition: errorManip.H:131
bool operator!=(const iterator &) const
Definition: SLListBaseI.H:187
const iterator & end()
Definition: SLListBaseI.H:239
iterator begin()
Definition: SLListBaseI.H:225
void operator=(const iterator &)
Definition: SLListBaseI.H:174
bool empty() const
Return true if the list is empty.
Definition: SLListBaseI.H:73
const_iterator(const SLListBase &, const link *)
Construct for a given SLListBase and link.
Definition: SLListBaseI.H:248
volScalarField & p
A class for managing temporary objects.
Definition: PtrList.H:53
link * remove(link *)
Definition: SLListBase.C:104
~SLListBase()
Destructor.
Definition: SLListBaseI.H:61
An STL-conforming iterator.
Definition: SLListBase.H:165
bool operator==(const iterator &) const
Definition: SLListBaseI.H:181
link * last()
Return last entry.
Definition: SLListBaseI.H:106