Loading...
Searching...
No Matches
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(
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;
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 (iterators)
102
103 class iterator;
104 class const_iterator;
105
106 using base_iterator = typename LListBase::iterator;
107 using const_base_iterator = typename LListBase::const_iterator;
108
109 //- The parent list storage
113 // Constructors
114
115 //- Default construct
116 LPtrList() = default;
118 //- Construct and add initial item pointer
119 explicit LPtrList(T* item)
120 {
121 this->push_front(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. Calls clear()
139 ~LPtrList();
140
141
142 // Member Functions
144 //- The first entry in the list
145 T& front()
146 {
147 return *(parent_type::front());
148 }
150 //- The first entry in the list (const access)
151 const T& front() const
152 {
153 return *(parent_type::front());
155
156 //- The last entry in the list
157 T& back()
158 {
159 return *(parent_type::back());
161
162 //- The last entry in the list (const access)
163 const T& back() const
164 {
165 return *(parent_type::back());
166 }
167
168 //- Emplace construct new element at front of list. Return reference.
169 template<class... Args>
170 T& emplace_front(Args&&... args)
171 {
172 T* ptr = new T(std::forward<Args>(args)...);
173 this->push_front(ptr);
174 return *ptr; // OR: return *(parent_type::front());
175 }
177 //- Emplace construct new element at back of list. Return reference.
178 template<class... Args>
179 T& emplace_back(Args&&... args)
180 {
181 T* ptr = new T(std::forward<Args>(args)...);
182 this->push_back(ptr);
183 return *ptr; // OR: return *(parent_type::back());
185
186 //- Remove first element(s) from the list (deletes pointers)
187 void pop_front(label n = 1);
188
189 //- Clear the contents of the list
190 void clear();
191
192 //- Transfer the contents of the argument into this List
193 //- and annul the argument list.
195
196
197 // Member Operators
198
199 //- Copy assign by using 'clone()' for each element
200 void operator=(const LPtrList<LListBase, T>& lst);
202 //- Move assign
204
205
206 // STL iterator
207
208 //- An STL-conforming iterator
209 class iterator
210 :
213 public:
214
216 :
218 {}
219
220 //- Return the address of the object being referenced
221 pointer get() const
223 return parent_type::iterator::operator*();
224 }
225
226 reference operator*() const
228 return *(this->get());
229 }
230
231 pointer operator->() const
232 {
233 return this->get();
234 }
235
236 reference operator()() const
237 {
238 return operator*();
239 }
240 };
242
243 // STL const_iterator
244
245 //- An STL-conforming const_iterator
246 class const_iterator
247 :
249 {
250 public:
251
253 :
254 parent_type::const_iterator(iter)
255 {}
256
258 :
260 {}
261
262 //- Return the address of the object being referenced
263 const_pointer get() const
264 {
265 return parent_type::const_iterator::operator*();
266 }
267
269 {
270 return *(this->get());
271 }
272
273 const_pointer operator->() const
274 {
275 return this->get();
276 }
277
278 const_reference operator()() const
279 {
280 return operator*();
281 }
282 };
284
285 // STL reverse_iterator
286
287 //- A reverse_iterator, for base classes that support
288 //- reverse iteration
289 class reverse_iterator
290 :
291 public parent_type::reverse_iterator
292 {
293 public:
294
296 :
298 {}
299
300 //- Return the address of the object being referenced
301 pointer get() const
302 {
303 return parent_type::reverse_iterator::operator*();
304 }
305
307 {
308 return *(this->get());
309 }
310
311 pointer operator->() const
312 {
313 return this->get();
315
316 reference operator()() const
317 {
318 return operator*();
320 };
321
322
323 // STL const_reverse_iterator
325 //- A const_reverse_iterator, for base classes that support
326 //- reverse iteration
328 :
329 public parent_type::const_reverse_iterator
330 {
331 public:
332
334 :
335 parent_type::const_reverse_iterator(iter)
336 {}
337
338 //- Return the address of the object being referenced
339 const_pointer get() const
340 {
341 return parent_type::const_reverse_iterator::operator*();
343
345 {
346 return *(this->get());
347 }
349 const_pointer operator->() const
350 {
351 return this->get();
352 }
353
354 const_reference operator()() const
355 {
356 return operator*();
357 }
358 };
359
360
361 //- Iterator to first item in list with non-const access
362 inline iterator begin()
363 {
364 return LListBase::template iterator_first<base_iterator>();
365 }
367 //- Iterator to first item in list with const access
368 inline const_iterator cbegin() const
369 {
370 return LListBase::template iterator_first<const_base_iterator>();
372
373 //- Iterator to last item in list with non-const access
374 inline reverse_iterator rbegin()
375 {
376 return LListBase::template iterator_last<base_iterator>();
377 }
378
379 //- Iterator to last item in list with const access
380 inline const_reverse_iterator crbegin() const
381 {
382 return LListBase::template iterator_last<const_base_iterator>();
383 }
385 //- Iterator to first item in list with const access
386 inline const_iterator begin() const
387 {
388 return LListBase::cbegin();
389 }
391 //- Iterator to last item in list with const access
392 inline const_reverse_iterator rbegin() const
393 {
394 return crbegin();
395 }
396
397
398 //- End of list for forward iterators
399 inline const iterator& end()
400 {
401 return LListBase::template iterator_end<iterator>();
402 }
404 //- End of list for forward iterators
405 inline const const_iterator& cend() const
406 {
407 return LListBase::template iterator_end<const_iterator>();
409
410 //- End of list for reverse iterators
411 inline const reverse_iterator& rend()
412 {
413 return LListBase::template iterator_rend<reverse_iterator>();
414 }
415
416 //- End of list for reverse iterators
417 inline const const_reverse_iterator& crend() const
418 {
419 return LListBase::template iterator_rend<const_reverse_iterator>();
420 }
421
422 //- End of list for forward iterators
423 inline const const_iterator& end() const
424 {
425 return cend();
426 }
427
428 //- End of list for reverse iterators
429 inline const const_reverse_iterator& rend() const
430 {
431 return crend();
432 }
433
434
435 // IOstream operators
436
437 friend Istream& operator>> <LListBase, T>
438 (
441 );
442
444 (
445 Ostream& os,
446 const LPtrList<LListBase, T>& list
447 );
448
449
450 // Housekeeping
451
452 //- The first entry in the list
453 //FOAM_DEPRECATED_FOR(2022-10, "front()")
454 T& first() { return front(); }
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(); }
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 "LPtrList.C"
478 #include "LPtrListIO.C"
479#endif
481// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
482
483#endif
484
485// ************************************************************************* //
label n
A helper class when constructing from an Istream or dictionary.
Definition INew.H:47
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition Istream.H:60
An STL-conforming const_iterator.
Definition LList.H:461
An STL-conforming iterator.
Definition LList.H:413
void push_front(const T &elem)
Definition LList.H:283
void push_back(const T &elem)
Definition LList.H:299
An STL-conforming const_iterator.
Definition LPtrList.H:298
const_pointer operator->() const
Definition LPtrList.H:324
const_reference operator()() const
Definition LPtrList.H:329
const_pointer get() const
Return the address of the object being referenced.
Definition LPtrList.H:314
const_iterator(base_iterator iter)
Definition LPtrList.H:306
const_iterator(const_base_iterator iter)
Definition LPtrList.H:301
const_reference operator*() const
Definition LPtrList.H:319
A const_reverse_iterator, for base classes that support reverse iteration.
Definition LPtrList.H:387
const_pointer operator->() const
Definition LPtrList.H:408
const_reference operator()() const
Definition LPtrList.H:413
const_reverse_iterator(const_base_iterator iter)
Definition LPtrList.H:390
const_pointer get() const
Return the address of the object being referenced.
Definition LPtrList.H:398
const_reference operator*() const
Definition LPtrList.H:403
An STL-conforming iterator.
Definition LPtrList.H:257
reference operator()() const
Definition LPtrList.H:283
reference operator*() const
Definition LPtrList.H:273
pointer get() const
Return the address of the object being referenced.
Definition LPtrList.H:268
iterator(base_iterator iter)
Definition LPtrList.H:260
pointer operator->() const
Definition LPtrList.H:278
A reverse_iterator, for base classes that support reverse iteration.
Definition LPtrList.H:345
reference operator()() const
Definition LPtrList.H:371
reference operator*() const
Definition LPtrList.H:361
reverse_iterator(base_iterator iter)
Definition LPtrList.H:348
pointer get() const
Return the address of the object being referenced.
Definition LPtrList.H:356
Template class for non-intrusive linked PtrLists.
Definition LPtrList.H:71
typename LListBase::iterator base_iterator
Definition LPtrList.H:111
void pop_front(label n=1)
Remove first element(s) from the list (deletes pointers).
Definition LPtrList.C:59
LPtrList(LPtrList &&lst)
Move construct.
T & emplace_front(Args &&... args)
Emplace construct new element at front of list. Return reference.
Definition LPtrList.H:201
const iterator & end()
End of list for forward iterators.
Definition LPtrList.H:472
T & first()
The first entry in the list.
Definition LPtrList.H:540
friend Ostream & operator(Ostream &os, const LPtrList< LListBase, T > &list)
const_iterator begin() const
Iterator to first item in list with const access.
Definition LPtrList.H:455
const const_iterator & end() const
End of list for forward iterators.
Definition LPtrList.H:504
typename LListBase::const_iterator const_base_iterator
Definition LPtrList.H:112
const T & front() const
The first entry in the list (const access).
Definition LPtrList.H:176
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition LPtrList.H:431
T & emplace_back(Args &&... args)
Emplace construct new element at back of list. Return reference.
Definition LPtrList.H:212
T & back()
The last entry in the list.
Definition LPtrList.H:184
LPtrList(Istream &is)
Construct from Istream using default Istream constructor class.
Definition LPtrListIO.C:124
void operator=(LPtrList< LListBase, T > &&lst)
Move assign.
Definition LPtrList.C:106
const const_iterator & cend() const
End of list for forward iterators.
Definition LPtrList.H:480
const T * const_pointer
Const pointer for LPtrList::value_type objects.
Definition LPtrList.H:93
LPtrList(const LPtrList &lst)
Copy construct by using 'clone()' for each element.
LPtrList(Istream &is, const INew &inew)
Construct from Istream using given Istream constructor class.
Definition LPtrListIO.C:117
void operator=(const LPtrList< LListBase, T > &lst)
Copy assign by using 'clone()' for each element.
Definition LPtrList.C:94
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:561
const_reverse_iterator crbegin() const
Iterator to last item in list with const access.
Definition LPtrList.H:447
const T & back() const
The last entry in the list (const access).
Definition LPtrList.H:192
const reverse_iterator & rend()
End of list for reverse iterators.
Definition LPtrList.H:488
T & reference
Reference for LPtrList::value_type objects.
Definition LPtrList.H:98
const T & first() const
The first entry in the list (const access).
Definition LPtrList.H:547
T & front()
The first entry in the list.
Definition LPtrList.H:168
LPtrList(T *item)
Construct and add initial item pointer.
Definition LPtrList.H:130
const const_reverse_iterator & crend() const
End of list for reverse iterators.
Definition LPtrList.H:496
LList< LListBase, T * > parent_type
The parent list storage.
Definition LPtrList.H:117
void transfer(LPtrList< LListBase, T > &lst)
Transfer the contents of the argument into this List and annul the argument list.
Definition LPtrList.C:84
void clear()
Clear the contents of the list.
Definition LPtrList.C:76
reverse_iterator rbegin()
Iterator to last item in list with non-const access.
Definition LPtrList.H:439
const const_reverse_iterator & rend() const
End of list for reverse iterators.
Definition LPtrList.H:512
iterator begin()
Iterator to first item in list with non-const access.
Definition LPtrList.H:423
LPtrList()=default
Default construct.
~LPtrList()
Destructor. Calls clear().
Definition LPtrList.C:50
T & last()
The last entry in the list.
Definition LPtrList.H:554
const_reverse_iterator rbegin() const
Iterator to last item in list with const access.
Definition LPtrList.H:463
const T & const_reference
Const reference for LPtrList::value_type objects.
Definition LPtrList.H:103
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)