All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
DLListBaseI.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 \*---------------------------------------------------------------------------*/
25 
26 #include "error.H"
27 
28 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29 
31 :
32  prev_(0),
33  next_(0)
34 {}
35 
36 
38 :
39  first_(0),
40  last_(0),
41  nElmts_(0)
42 {}
43 
44 
46 :
47  first_(a),
48  last_(a),
49  nElmts_(1)
50 {
51  a->prev_ = a;
52  a->next_ = a;
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
57 
59 {}
60 
61 
62 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
63 
65 {
66  return prev_ != 0 && next_ != 0;
67 }
68 
69 
71 {
72  prev_ = 0;
73  next_ = 0;
74 }
75 
76 
78 {
79  return nElmts_;
80 }
81 
82 
83 inline bool Foam::DLListBase::empty() const
84 {
85  return !nElmts_;
86 }
87 
88 
91 {
92  if (!nElmts_)
93  {
95  << "list is empty"
96  << abort(FatalError);
97  }
98  return first_;
99 }
100 
101 
102 inline const Foam::DLListBase::link*
104 {
105  if (!nElmts_)
106  {
108  << "list is empty"
109  << abort(FatalError);
110  }
111  return first_;
112 }
113 
114 
117 {
118  if (!nElmts_)
119  {
121  << "list is empty"
122  << abort(FatalError);
123  }
124  return last_;
125 }
126 
127 
128 inline const Foam::DLListBase::link*
130 {
131  if (!nElmts_)
132  {
134  << "list is empty"
135  << abort(FatalError);
136  }
137  return last_;
138 }
139 
140 
142 {
143  first_ = 0;
144  last_ = 0;
145  nElmts_ = 0;
146 }
147 
148 
150 {
151  first_ = lst.first_;
152  last_ = lst.last_;
153  nElmts_ = lst.nElmts_;
154 
155  lst.clear();
156 }
157 
158 
161 (
163 )
164 {
165  return remove(it.curElmt_);
166 }
167 
168 
171 (
172  DLListBase::iterator& oldIter,
173  DLListBase::link* newLink
174 )
175 {
176  return replace(oldIter.curElmt_, newLink);
177 }
178 
179 
180 // * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
181 
182 inline Foam::DLListBase::iterator::iterator(DLListBase& s, link* elmt)
183 :
184  curList_(s),
185  curElmt_(elmt),
186  curLink_(*curElmt_)
187 {}
188 
189 
190 inline Foam::DLListBase::iterator::iterator(DLListBase& s)
191 :
192  curList_(s),
193  curElmt_(nullptr),
194  curLink_()
195 {}
196 
197 
199 {
200  curElmt_ = iter.curElmt_;
201  curLink_ = iter.curLink_;
202 }
203 
204 
205 inline bool Foam::DLListBase::iterator::operator==(const iterator& iter) const
206 {
207  return curElmt_ == iter.curElmt_;
208 }
209 
210 
211 inline bool Foam::DLListBase::iterator::operator!=(const iterator& iter) const
212 {
213  return curElmt_ != iter.curElmt_;
214 }
215 
216 
219 {
220  return *curElmt_;
221 }
222 
223 
226 {
227  // Check if the curElmt_ is the last element (if it points to itself)
228  // or if the list is empty because the last element may have been removed
229  if (curLink_.next_ == curElmt_ || curList_.last_ == 0)
230  {
231  curElmt_ = 0;
232  }
233  else
234  {
235  curElmt_ = curLink_.next_;
236  curLink_ = *curElmt_;
237  }
238 
239  return *this;
240 }
241 
242 
245 {
246  iterator tmp = *this;
247  ++*this;
248  return tmp;
249 }
250 
251 
254 {
255  if (size())
256  {
257  return iterator(*this, first());
258  }
259  else
260  {
261  return endIter_;
262  }
263 }
264 
265 
267 {
268  return endIter_;
269 }
270 
271 
272 // * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
273 
275 (
276  const DLListBase& s,
277  const link* elmt
278 )
279 :
280  curList_(s),
281  curElmt_(elmt)
282 {}
283 
284 
286 :
287  curList_(iter.curList_),
288  curElmt_(iter.curElmt_)
289 {}
290 
291 
292 inline void Foam::DLListBase::const_iterator::operator=
293 (
294  const const_iterator& iter
295 )
296 {
297  curElmt_ = iter.curElmt_;
298 }
299 
300 
301 inline bool Foam::DLListBase::const_iterator::operator==
302 (
303  const const_iterator& iter
304 ) const
305 {
306  return curElmt_ == iter.curElmt_;
307 }
308 
309 
310 inline bool Foam::DLListBase::const_iterator::operator!=
311 (
312  const const_iterator& iter
313 ) const
314 {
315  return curElmt_ != iter.curElmt_;
316 }
317 
318 
319 inline const Foam::DLListBase::link&
321 {
322  return *curElmt_;
323 }
324 
325 
328 {
329  if (curElmt_ == curList_.last_)
330  {
331  curElmt_ = 0;
332  }
333  else
334  {
335  curElmt_ = curElmt_->next_;
336  }
337 
338  return *this;
339 }
340 
341 
344 {
345  const_iterator tmp = *this;
346  ++*this;
347  return tmp;
348 }
349 
350 
353 {
354  if (size())
355  {
356  return const_iterator(*this, first());
357  }
358  else
359  {
360  return endConstIter_;
361  }
362 }
363 
364 
367 {
368  return endConstIter_;
369 }
370 
371 
374 {
375  return this->cbegin();
376 }
377 
378 
381 {
382  return endConstIter_;
383 }
384 
385 
386 // * * * * * * * * * * STL const_reverse_iterator * * * * * * * * * * * * * //
387 
389 (
390  const DLListBase& s,
391  const link* elmt
392 )
393 :
394  curList_(s),
395  curElmt_(elmt)
396 {}
397 
398 
399 inline void Foam::DLListBase::const_reverse_iterator::operator=
400 (
401  const const_reverse_iterator& iter
402 )
403 {
404  curElmt_ = iter.curElmt_;
405 }
406 
407 
408 inline bool Foam::DLListBase::const_reverse_iterator::operator==
409 (
410  const const_reverse_iterator& iter
411 ) const
412 {
413  return curElmt_ == iter.curElmt_;
414 }
415 
416 
417 inline bool Foam::DLListBase::const_reverse_iterator::operator!=
418 (
419  const const_reverse_iterator& iter
420 ) const
421 {
422  return curElmt_ != iter.curElmt_;
423 }
424 
425 
426 inline const Foam::DLListBase::link&
428 {
429  return *curElmt_;
430 }
431 
432 
435 {
436  if (curElmt_ == curList_.first_)
437  {
438  curElmt_ = 0;
439  }
440  else
441  {
442  curElmt_ = curElmt_->prev_;
443  }
444 
445  return *this;
446 }
447 
448 
451 {
452  const_reverse_iterator tmp = *this;
453  ++*this;
454  return tmp;
455 }
456 
457 
460 {
461  if (size())
462  {
463  return const_reverse_iterator(*this, last());
464  }
465  else
466  {
467  return endConstRevIter_;
468  }
469 }
470 
471 
474 {
475  return endConstRevIter_;
476 }
477 
478 
481 {
482  return this->crbegin();
483 }
484 
485 
488 {
489  return endConstRevIter_;
490 }
491 
492 
493 // ************************************************************************* //
const_reverse_iterator & operator++()
Definition: DLListBaseI.H:434
void operator=(const iterator &)
Definition: DLListBaseI.H:198
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:306
Base doubly-linked list.
Definition: DLListBase.H:50
const_reverse_iterator(const DLListBase &, const link *)
Construct for a given DLListBase and link.
Definition: DLListBaseI.H:389
link * remove(link *)
Remove and return element.
Definition: DLListBase.C:199
const const_reverse_iterator & crend() const
Definition: DLListBaseI.H:473
bool empty() const
Return true if the list is empty.
Definition: DLListBaseI.H:83
link * replace(link *oldLink, link *newLink)
Replace oldLink with newLink and return element.
Definition: DLListBase.C:232
bool operator!=(const iterator &) const
Definition: DLListBaseI.H:211
iterator begin()
Definition: DLListBaseI.H:253
const_iterator & operator++()
Definition: DLListBaseI.H:327
link * last()
Return last entry.
Definition: DLListBaseI.H:116
const_reverse_iterator crbegin() const
Definition: DLListBaseI.H:459
const_reverse_iterator rbegin() const
Definition: DLListBaseI.H:480
label size() const
Return number of elements in list.
Definition: DLListBaseI.H:77
~DLListBase()
Destructor.
Definition: DLListBaseI.H:58
An STL-conforming const_reverse_iterator.
Definition: DLListBase.H:276
const const_iterator & cend() const
Definition: DLListBaseI.H:366
bool operator==(const iterator &) const
Definition: DLListBaseI.H:205
link * first()
Return first entry.
Definition: DLListBaseI.H:90
An STL-conforming const_iterator.
Definition: DLListBase.H:232
An STL-conforming iterator.
Definition: DLListBase.H:182
errorManip< error > abort(error &err)
Definition: errorManip.H:131
friend class const_reverse_iterator
Definition: DLListBase.H:93
const const_reverse_iterator & rend() const
Definition: DLListBaseI.H:487
const iterator & end()
Definition: DLListBaseI.H:266
DLListBase()
Null construct.
Definition: DLListBaseI.H:37
void transfer(DLListBase &)
Transfer the contents of the argument into this List.
Definition: DLListBaseI.H:149
const_iterator cbegin() const
Definition: DLListBaseI.H:352
void clear()
Clear the list.
Definition: DLListBaseI.H:141
A class for managing temporary objects.
Definition: PtrList.H:53
const_iterator(const DLListBase &, const link *)
Construct for a given DLListBase and link.
Definition: DLListBaseI.H:275