Loading...
Searching...
No Matches
UILList.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::UILList
29
30Description
31 Template class for intrusive linked lists.
32
33SourceFiles
34 UILList.C
35 UILListIO.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_UILList_H
40#define Foam_UILList_H
41
42#include "label.H"
43#include "uLabel.H"
44#include "stdFoam.H"
45
46// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
47
48namespace Foam
49{
51// Forward Declarations
52template<class LListBase, class T> class UILList;
53
54template<class LListBase, class T>
55Ostream& operator<<
56(
57 Ostream& os,
58 const UILList<LListBase, T>& lst
59);
60
61
62/*---------------------------------------------------------------------------*\
63 Class UILList Declaration
64\*---------------------------------------------------------------------------*/
65
66template<class LListBase, class T>
67class UILList
68:
69 public LListBase
70{
71public:
72
73 // STL type definitions
74
75 //- Type of values stored
76 typedef T value_type;
77
78 //- Pointer for value_type
79 typedef T* pointer;
80
81 //- Const pointer for value_type
82 typedef const T* const_pointer;
84 //- Reference for value_type
85 typedef T& reference;
86
87 //- Const reference for value_type
88 typedef const T& const_reference;
89
90 //- The type that can represent the container size
91 typedef label size_type;
92
93 //- The difference between iterator objects
94 typedef label difference_type;
95
96
97 // Forward Declarations (iterators)
99 class iterator;
100 class const_iterator;
101
102 using base_iterator = typename LListBase::iterator;
103 using const_base_iterator = typename LListBase::const_iterator;
104
105
106 // Constructors
107
108 //- Default construct
109 UILList() = default;
110
111 //- Construct and add initial item pointer
112 explicit UILList(T* item)
113 {
114 this->push_front(item);
115 }
116
117 //- Construct as copy
118 UILList(const UILList<LListBase, T>& list);
119
121 // Member Functions
122
123 //- The first entry in the list
124 T* front()
126 return static_cast<T*>(LListBase::front());
127 }
128
129 //- The first entry in the list (const access)
130 const T* front() const
131 {
132 return static_cast<const T*>(LListBase::front());
134
135 //- The last entry in the list
136 T* back()
137 {
138 return static_cast<T*>(LListBase::back());
139 }
140
141 //- The last entry in the list (const access)
142 const T* back() const
143 {
144 return static_cast<const T*>(LListBase::back());
145 }
146
147
148 //- Remove and return head
150 {
151 return static_cast<T*>(LListBase::removeHead());
152 }
153
154 //- Remove and return element
155 T* remove(T* item)
156 {
157 return static_cast<T*>(LListBase::remove(item));
158 }
159
160 //- Remove and return item specified by iterator
161 T* remove(iterator& iter)
162 {
163 return static_cast<T*>(LListBase::remove(iter));
164 }
166
167 // Member Operators
168
169 //- Copy assignment
170 void operator=(const UILList<LListBase, T>& lst);
171
172 //- Equality. True both lists are element-wise equal
173 // (using value_type::operator==). Takes linear time.
174 bool operator==(const UILList<LListBase, T>& lst) const;
175
176 //- The opposite of the equality operation. Takes linear time.
177 bool operator!=(const UILList<LListBase, T>& lst) const;
178
179
180 // IOstream Operators
181
182 //- Write UILList with line-breaks when length exceeds shortLen.
183 // Using '0' suppresses line-breaks entirely.
184 Ostream& writeList(Ostream& os, const label shortLen=0) const;
185
186 //- Write UILList to Ostream with line breaks,
187 //- as per writeList() with shortLen=-1
189 (
191 const UILList<LListBase, T>& lst
192 );
193
194
195 // STL iterator
196
197 //- A non-const iterator
198 class iterator
199 :
200 public base_iterator
202 public:
203
205 :
206 base_iterator(iter)
207 {}
209 //- Return the address of the object being referenced
210 pointer get() const
211 {
212 return static_cast<T*>(base_iterator::get_node());
214
215 reference operator*() const
216 {
217 return *(this->get());
218 }
219
220 pointer operator->() const
221 {
222 return this->get();
224
225 reference operator()() const
226 {
227 return operator*();
228 }
230 iterator& operator++()
231 {
232 this->next();
233 return *this;
234 }
235 };
236
237
238 // STL const_iterator
239
240 //- A const_iterator
242 :
244 {
245 public:
246
247 //- Construct from base const_iterator
249 :
251 {}
252
253 //- Construct from base iterator
257 {}
258
259 //- Return the address of the object being referenced
261 {
262 return static_cast<const T*>(const_base_iterator::get_node());
263 }
264
266 {
267 return *(this->get());
268 }
269
270 const_pointer operator->() const
271 {
272 return this->get();
273 }
274
275 const_reference operator()() const
276 {
277 return operator*();
278 }
279
281 {
282 this->next();
283 return *this;
284 }
285 };
286
287
288 // STL reverse_iterator
289
290 //- A reverse_iterator, for LListBase classes that support
291 //- reverse iteration
292 class reverse_iterator
293 :
294 public base_iterator
295 {
296 public:
301 {}
302
303 //- Return the address of the object being referenced
304 pointer get() const
306 return static_cast<T*>(base_iterator::get_node());
307 }
308
309 reference operator*() const
310 {
311 return *(this->get());
312 }
314 pointer operator->() const
315 {
316 return this->get();
317 }
319 reference operator()() const
320 {
321 return operator*();
322 }
325 {
326 this->prev(); // Only if base iterator is bidirectional
327 return *this;
329 };
330
331
332 // STL const_reverse_iterator
334 //- A const_reverse_iterator, for LListBase classes that support
335 //- reverse iteration
337 :
339 {
340 public:
341
343 :
345 {}
346
347 //- Return the address of the object being referenced
348 const_pointer get() const
349 {
350 return static_cast<const T*>(const_base_iterator::get_node());
351 }
352
354 {
355 return *(this->get());
356 }
357
358 const_pointer operator->() const
359 {
360 return this->get();
362
363 const_reference operator()() const
364 {
365 return operator*();
370 this->prev(); // Only if base iterator is bidirectional
371 return *this;
372 }
373 };
374
375
376 //- Iterator to first item in list with non-const access
377 inline iterator begin()
378 {
379 return LListBase::template iterator_first<base_iterator>();
380 }
382 //- Iterator to first item in list with const access
383 inline const_iterator cbegin() const
384 {
385 return LListBase::template iterator_first<const_base_iterator>();
386 }
387
388 //- Iterator to last item in list with non-const access
389 inline reverse_iterator rbegin()
390 {
391 return LListBase::template iterator_last<base_iterator>();
392 }
393
394 //- Iterator to last item in list with const access
396 {
397 return LListBase::template iterator_last<const_base_iterator>();
398 }
399
400 //- Iterator to first item in list with const access
401 inline const_iterator begin() const
402 {
403 return LListBase::cbegin();
404 }
405
406 //- Iterator to last item in list with const access
407 inline const_reverse_iterator rbegin() const
408 {
409 return crbegin();
410 }
411
412
413 //- End of list for forward iterators
414 inline const iterator& end()
415 {
416 return LListBase::template iterator_end<iterator>();
417 }
418
419 //- End of list for forward iterators
420 inline const const_iterator& cend() const
421 {
422 return LListBase::template iterator_end<const_iterator>();
423 }
425 //- End of list for reverse iterators
426 inline const reverse_iterator& rend()
427 {
428 return LListBase::template iterator_rend<reverse_iterator>();
430
431 //- End of list for reverse iterators
432 inline const const_reverse_iterator& crend() const
433 {
434 return LListBase::template iterator_rend<const_reverse_iterator>();
435 }
436
437 //- End of list for forward iterators
438 inline const const_iterator& end() const
439 {
440 return cend();
441 }
442
443 //- End of list for reverse iterators
444 inline const const_reverse_iterator& rend() const
445 {
446 return crend();
447 }
449
450 // Housekeeping
451
452 //- The first entry in the list
453 //FOAM_DEPRECATED_FOR(2022-10, "front()")
454 T* first() { return front(); }
455
456 //- The first entry in the list (const access)
457 //FOAM_DEPRECATED_FOR(2022-10, "front()")
458 const T* first() const { return front(); }
459
460 //- The last entry in the list
461 //FOAM_DEPRECATED_FOR(2022-10, "back()")
462 T* last() { return back(); }
463
464 //- The last entry in the list (const access)
465 //FOAM_DEPRECATED_FOR(2022-10, "back()")
466 const T* last() const { return back(); }
467};
468
469
470// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
471
472} // End namespace Foam
473
474// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
475
476#ifdef NoRepository
477 #include "UILList.C"
478 #include "UILListIO.C"
479#endif
481// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482
483#endif
484
485// ************************************************************************* //
IteratorType iterator_first() const
Return iterator to first item or end-iterator if list is empty.
Definition DLListBaseI.H:42
static const IteratorType & iterator_end()
Factory method to return an iterator end.
Definition DLListBaseI.H:28
IteratorType iterator_last() const
Return iterator to last item or end-iterator if list is empty.
Definition DLListBaseI.H:57
static const IteratorType & iterator_rend()
Factory method to return an iterator reverse end.
Definition DLListBaseI.H:35
void push_front(link *item)
Add at front of list.
Definition DLListBase.C:27
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
A const_iterator.
Definition UILList.H:291
const_pointer operator->() const
Definition UILList.H:323
const_reference operator()() const
Definition UILList.H:328
const_pointer get() const
Return the address of the object being referenced.
Definition UILList.H:313
const_iterator(base_iterator iter)
Construct from base iterator.
Definition UILList.H:305
const_iterator & operator++()
Definition UILList.H:333
const_iterator(const_base_iterator iter)
Construct from base const_iterator.
Definition UILList.H:297
const_reference operator*() const
Definition UILList.H:318
A const_reverse_iterator, for LListBase classes that support reverse iteration.
Definition UILList.H:398
const_pointer operator->() const
Definition UILList.H:419
const_reference operator()() const
Definition UILList.H:424
const_reverse_iterator(const_base_iterator iter)
Definition UILList.H:401
const_pointer get() const
Return the address of the object being referenced.
Definition UILList.H:409
const_reverse_iterator & operator++()
Definition UILList.H:429
const_reference operator*() const
Definition UILList.H:414
A non-const iterator.
Definition UILList.H:244
reference operator()() const
Definition UILList.H:270
reference operator*() const
Definition UILList.H:260
iterator & operator++()
Definition UILList.H:275
pointer get() const
Return the address of the object being referenced.
Definition UILList.H:255
iterator(base_iterator iter)
Definition UILList.H:247
pointer operator->() const
Definition UILList.H:265
A reverse_iterator, for LListBase classes that support reverse iteration.
Definition UILList.H:350
reference operator()() const
Definition UILList.H:376
reverse_iterator & operator++()
Definition UILList.H:381
reference operator*() const
Definition UILList.H:366
reverse_iterator(base_iterator iter)
Definition UILList.H:353
pointer get() const
Return the address of the object being referenced.
Definition UILList.H:361
Template class for intrusive linked lists.
Definition UILList.H:65
typename LListBase::iterator base_iterator
Definition UILList.H:111
label size_type
The type that can represent the container size.
Definition UILList.H:98
const iterator & end()
End of list for forward iterators.
Definition UILList.H:489
label difference_type
The difference between iterator objects.
Definition UILList.H:103
const T * last() const
The last entry in the list (const access).
Definition UILList.H:563
UILList()=default
Default construct.
T value_type
Type of values stored.
Definition UILList.H:73
const_iterator begin() const
Iterator to first item in list with const access.
Definition UILList.H:472
const const_iterator & end() const
End of list for forward iterators.
Definition UILList.H:521
typename LListBase::const_iterator const_base_iterator
Definition UILList.H:112
const T * first() const
The first entry in the list (const access).
Definition UILList.H:549
T * front()
The first entry in the list.
Definition UILList.H:141
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition UILList.H:448
const const_iterator & cend() const
End of list for forward iterators.
Definition UILList.H:497
const T * const_pointer
Const pointer for value_type.
Definition UILList.H:83
void operator=(const UILList< LListBase, T > &lst)
Copy assignment.
Definition UILList.C:39
T * pointer
Pointer for value_type.
Definition UILList.H:78
const_reverse_iterator crbegin() const
Iterator to last item in list with const access.
Definition UILList.H:464
const reverse_iterator & rend()
End of list for reverse iterators.
Definition UILList.H:505
T * back()
The last entry in the list.
Definition UILList.H:157
T & reference
Reference for value_type.
Definition UILList.H:88
bool operator==(const UILList< LListBase, T > &lst) const
Equality. True both lists are element-wise equal.
Definition UILList.C:52
const const_reverse_iterator & crend() const
End of list for reverse iterators.
Definition UILList.H:513
T * remove(T *item)
Remove and return element.
Definition UILList.H:182
const T * back() const
The last entry in the list (const access).
Definition UILList.H:165
T * first()
The first entry in the list.
Definition UILList.H:542
bool operator!=(const UILList< LListBase, T > &lst) const
The opposite of the equality operation. Takes linear time.
Definition UILList.C:77
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write UILList with line-breaks when length exceeds shortLen.
Definition UILListIO.C:30
reverse_iterator rbegin()
Iterator to last item in list with non-const access.
Definition UILList.H:456
const const_reverse_iterator & rend() const
End of list for reverse iterators.
Definition UILList.H:529
iterator begin()
Iterator to first item in list with non-const access.
Definition UILList.H:440
const T * front() const
The first entry in the list (const access).
Definition UILList.H:149
friend Ostream & operator(Ostream &os, const UILList< LListBase, T > &lst)
Write UILList to Ostream with line breaks, as per writeList() with shortLen=-1.
T * last()
The last entry in the list.
Definition UILList.H:556
T * removeHead()
Remove and return head.
Definition UILList.H:174
UILList(T *item)
Construct and add initial item pointer.
Definition UILList.H:125
T * remove(iterator &iter)
Remove and return item specified by iterator.
Definition UILList.H:190
const_reverse_iterator rbegin() const
Iterator to last item in list with const access.
Definition UILList.H:480
const T & const_reference
Const reference for value_type.
Definition UILList.H:93
UILList(const UILList< LListBase, T > &list)
Construct as copy.
Definition UILList.C:27
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Includes some common C++ headers, defines global macros and templates used in multiple places by Open...