LPtrList.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::LPtrList
29
30Description
31 Template class for non-intrusive linked PtrLists.
32
33SourceFiles
34 LPtrList.C
35 LPtrListIO.C
36
37\*---------------------------------------------------------------------------*/
38
39#ifndef Foam_LPtrList_H
40#define Foam_LPtrList_H
41
42#include "LList.H"
43
44// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45
46namespace Foam
47{
48
49// Forward Declarations
50
51template<class LListBase, class T> class LPtrList;
52
53template<class LListBase, class T>
54Istream& operator>>
55(
56 Istream& is,
58);
59
60template<class LListBase, class T>
61Ostream& operator<<
62(
63 Ostream& os,
64 const LPtrList<LListBase, T>& list
65);
66
67
68/*---------------------------------------------------------------------------*\
69 Class LPtrList Declaration
70\*---------------------------------------------------------------------------*/
71
72template<class LListBase, class T>
73class LPtrList
74:
75 public LList<LListBase, T*>
76{
77 // Private Member Functions
78
79 //- Read from Istream using given Istream constructor class
80 template<class INew>
81 void readIstream(Istream& is, const INew& inew);
82
83
84public:
85
86 // STL type definitions
87
88 //- Pointer for LPtrList::value_type objects.
89 typedef T* pointer;
90
91 //- Const pointer for LPtrList::value_type objects.
92 typedef const T* const_pointer;
93
94 //- Reference for LPtrList::value_type objects.
95 typedef T& reference;
96
97 //- Const reference for LPtrList::value_type objects.
98 typedef const T& const_reference;
99
100
101 // Forward declaration of STL iterators
102
103 class iterator;
104 class const_iterator;
108
109 //- The parent list storage
111
112
113 // Constructors
114
115 //- Default construct
116 LPtrList() = default;
117
118 //- Construct and add initial item pointer
119 explicit LPtrList(T* item)
120 {
121 this->prepend(item);
122 }
123
124 //- Copy construct by using 'clone()' for each element
125 LPtrList(const LPtrList& lst);
126
127 //- Move construct
128 LPtrList(LPtrList&& lst);
129
130 //- Construct from Istream using given Istream constructor class
131 template<class INew>
132 LPtrList(Istream& is, const INew& inew);
133
134 //- Construct from Istream using default Istream constructor class
135 explicit LPtrList(Istream& is);
136
137
138 //- Destructor
139 ~LPtrList();
140
141
142 // Member Functions
143
144 //- The first entry in the list
145 T& first()
146 {
147 return *(parent_type::first());
148 }
149
150 //- The first entry in the list (const access)
151 const T& first() const
152 {
153 return *(parent_type::first());
154 }
155
156 //- The last entry in the list
157 T& last()
158 {
159 return *(parent_type::last());
160 }
161
162 //- The last entry in the list (const access)
163 const T& last() const
164 {
165 return *(parent_type::last());
166 }
167
168
169 //- Remove the head element from the list and delete the pointer
170 bool eraseHead();
171
172 //- Clear the contents of the list
173 void clear();
174
175 //- Transfer the contents of the argument into this List
176 //- and annul the argument list.
178
179
180 // Member operators
181
182 //- Copy assign by using 'clone()' for each element
183 void operator=(const LPtrList<LListBase, T>& lst);
184
185 //- Move assign
187
188
189 // STL iterator
190
191 //- An STL-conforming iterator
192 class iterator
193 :
195 {
196 public:
199 :
200 parent_type::iterator(iter)
201 {}
202
203 //- Return the address of the object being referenced
204 pointer get() const
205 {
207 }
209 reference operator*() const
210 {
211 return *(this->get());
212 }
214 pointer operator->() const
215 {
216 return this->get();
217 }
219 reference operator()() const
220 {
221 return operator*();
222 }
223 };
224
225
226 // STL const_iterator
227
228 //- An STL-conforming const_iterator
229 class const_iterator
230 :
232 {
233 public:
236 :
238 {}
241 :
243 {}
244
245 //- Return the address of the object being referenced
246 const_pointer get() const
247 {
249 }
252 {
253 return *(this->get());
254 }
256 const_pointer operator->() const
257 {
258 return this->get();
259 }
261 const_reference operator()() const
262 {
263 return operator*();
264 }
265 };
266
267
268 // STL reverse_iterator
269
270 //- A reverse_iterator, for base classes that support
271 //- reverse iteration
272 class reverse_iterator
273 :
275 {
276 public:
279 :
281 {}
282
283 //- Return the address of the object being referenced
284 pointer get() const
285 {
287 }
289 reference operator*() const
290 {
291 return *(this->get());
292 }
294 pointer operator->() const
295 {
296 return this->get();
297 }
299 reference operator()() const
300 {
301 return operator*();
302 }
303 };
304
305
306 // STL const_reverse_iterator
307
308 //- A const_reverse_iterator, for base classes that support
309 //- reverse iteration
311 :
313 {
314 public:
317 :
319 {}
320
321 //- Return the address of the object being referenced
322 const_pointer get() const
323 {
325 }
328 {
329 return *(this->get());
330 }
332 const_pointer operator->() const
333 {
334 return this->get();
335 }
337 const_reference operator()() const
338 {
339 return operator*();
340 }
341 };
342
343
344 //- Iterator to first item in list with non-const access
345 inline iterator begin()
346 {
347 return LListBase::template iterator_first<base_iterator>();
348 }
349
350 //- Iterator to first item in list with const access
351 inline const_iterator cbegin() const
352 {
353 return LListBase::template iterator_first<const_base_iterator>();
354 }
355
356 //- Iterator to last item in list with non-const access
357 inline reverse_iterator rbegin()
358 {
359 return LListBase::template iterator_last<base_iterator>();
360 }
361
362 //- Iterator to last item in list with const access
363 inline const_reverse_iterator crbegin() const
364 {
365 return LListBase::template iterator_last<const_base_iterator>();
366 }
367
368 //- Iterator to first item in list with const access
369 inline const_iterator begin() const
370 {
371 return LListBase::cbegin();
372 }
373
374 //- Iterator to last item in list with const access
375 inline const_reverse_iterator rbegin() const
376 {
377 return crbegin();
378 }
379
380
381 //- End of list for forward iterators
382 inline const iterator& end()
383 {
384 return LListBase::template iterator_end<iterator>();
385 }
386
387 //- End of list for forward iterators
388 inline const const_iterator& cend() const
389 {
390 return LListBase::template iterator_end<const_iterator>();
391 }
392
393 //- End of list for reverse iterators
394 inline const reverse_iterator& rend()
395 {
396 return LListBase::template iterator_rend<reverse_iterator>();
397 }
398
399 //- End of list for reverse iterators
400 inline const const_reverse_iterator& crend() const
401 {
402 return LListBase::template iterator_rend<const_reverse_iterator>();
403 }
404
405 //- End of list for forward iterators
406 inline const const_iterator& end() const
407 {
408 return cend();
409 }
410
411 //- End of list for reverse iterators
412 inline const const_reverse_iterator& rend() const
413 {
414 return crend();
415 }
416
417
418 // IOstream operators
420 friend Istream& operator>> <LListBase, T>
421 (
422 Istream& is,
424 );
426 friend Ostream& operator<< <LListBase, T>
427 (
428 Ostream& os,
429 const LPtrList<LListBase, T>& list
430 );
431};
432
433
434// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
435
436} // End namespace Foam
437
438// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
439
440#ifdef NoRepository
441 #include "LPtrList.C"
442 #include "LPtrListIO.C"
443#endif
444
445// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
446
447#endif
448
449// ************************************************************************* //
Forward iterator with non-const access.
Definition: HashTable.H:720
iterator()=default
Default construct (end iterator)
this_type::reference reference
Definition: HashTable.H:732
this_type::pointer pointer
Definition: HashTable.H:731
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
Template class for non-intrusive linked lists.
Definition: LList.H:79
void prepend(const T * &elem)
Add copy at front of list.
Definition: LList.H:233
reference last()
The last entry in the list.
Definition: LList.H:220
reference first()
The first entry in the list.
Definition: LList.H:208
An STL-conforming const_iterator.
Definition: LPtrList.H:231
const_pointer operator->() const
Definition: LPtrList.H:255
const_reference operator()() const
Definition: LPtrList.H:260
const_pointer get() const
Return the address of the object being referenced.
Definition: LPtrList.H:245
const_iterator(base_iterator iter)
Definition: LPtrList.H:239
const_iterator(const_base_iterator iter)
Definition: LPtrList.H:234
const_reference operator*() const
Definition: LPtrList.H:250
const_pointer operator->() const
Definition: LPtrList.H:331
const_reference operator()() const
Definition: LPtrList.H:336
const_reverse_iterator(const_base_iterator iter)
Definition: LPtrList.H:315
const_pointer get() const
Return the address of the object being referenced.
Definition: LPtrList.H:321
const_reference operator*() const
Definition: LPtrList.H:326
An STL-conforming iterator.
Definition: LPtrList.H:194
reference operator()() const
Definition: LPtrList.H:218
reference operator*() const
Definition: LPtrList.H:208
pointer get() const
Return the address of the object being referenced.
Definition: LPtrList.H:203
iterator(base_iterator iter)
Definition: LPtrList.H:197
pointer operator->() const
Definition: LPtrList.H:213
reference operator()() const
Definition: LPtrList.H:298
reference operator*() const
Definition: LPtrList.H:288
reverse_iterator(base_iterator iter)
Definition: LPtrList.H:277
pointer get() const
Return the address of the object being referenced.
Definition: LPtrList.H:283
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:75
typename LListBase::iterator base_iterator
Definition: LPtrList.H:105
LPtrList(LPtrList &&lst)
Move construct.
const iterator & end()
End of list for forward iterators.
Definition: LPtrList.H:381
T & first()
The first entry in the list.
Definition: LPtrList.H:144
const_iterator begin() const
Iterator to first item in list with const access.
Definition: LPtrList.H:368
const const_iterator & end() const
End of list for forward iterators.
Definition: LPtrList.H:405
typename LListBase::const_iterator const_base_iterator
Definition: LPtrList.H:106
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition: LPtrList.H:350
bool eraseHead()
Remove the head element from the list and delete the pointer.
Definition: LPtrList.C:66
const const_iterator & cend() const
End of list for forward iterators.
Definition: LPtrList.H:387
const T * const_pointer
Const pointer for LPtrList::value_type objects.
Definition: LPtrList.H:91
LPtrList(const LPtrList &lst)
Copy construct by using 'clone()' for each element.
void operator=(const LPtrList< LListBase, T > &lst)
Copy assign by using 'clone()' for each element.
Definition: LPtrList.C:99
T * pointer
Pointer for LPtrList::value_type objects.
Definition: LPtrList.H:88
const T & last() const
The last entry in the list (const access)
Definition: LPtrList.H:162
const_reverse_iterator crbegin() const
Iterator to last item in list with const access.
Definition: LPtrList.H:362
const reverse_iterator & rend()
End of list for reverse iterators.
Definition: LPtrList.H:393
T & reference
Reference for LPtrList::value_type objects.
Definition: LPtrList.H:94
const T & first() const
The first entry in the list (const access)
Definition: LPtrList.H:150
LPtrList(T *item)
Construct and add initial item pointer.
Definition: LPtrList.H:118
const const_reverse_iterator & crend() const
End of list for reverse iterators.
Definition: LPtrList.H:399
LList< LListBase, T * > parent_type
The parent list storage.
Definition: LPtrList.H:109
void transfer(LPtrList< LListBase, T > &lst)
Definition: LPtrList.C:89
void clear()
Clear the contents of the list.
Definition: LPtrList.C:75
reverse_iterator rbegin()
Iterator to last item in list with non-const access.
Definition: LPtrList.H:356
const const_reverse_iterator & rend() const
End of list for reverse iterators.
Definition: LPtrList.H:411
iterator begin()
Iterator to first item in list with non-const access.
Definition: LPtrList.H:344
LPtrList()=default
Default construct.
~LPtrList()
Destructor.
Definition: LPtrList.C:57
T & last()
The last entry in the list.
Definition: LPtrList.H:156
const_reverse_iterator rbegin() const
Iterator to last item in list with const access.
Definition: LPtrList.H:374
const T & const_reference
Const reference for LPtrList::value_type objects.
Definition: LPtrList.H:97
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A const_iterator for iterating across on values.
Definition: bitSet.H:505
edgeFaceCirculator cbegin() const
friend forceSuSp operator*(const forceSuSp &susp1, const forceSuSp &susp2)
Addition.
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.