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