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 
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
249  {
251  }
252 
254  {
255  return *(this->get());
256  }
257 
259  {
260  return this->get();
261  }
262 
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 
292  {
293  return *(this->get());
294  }
295 
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
325  {
327  }
328 
330  {
331  return *(this->get());
332  }
333 
335  {
336  return this->get();
337  }
338 
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,
425  LPtrList<LListBase, T>& list
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
Definition: LPtrList.H:348
Foam::LPtrList::begin
iterator begin()
Definition: LPtrList.H:342
Foam::LPtrList::const_base_iterator
typename LListBase::const_iterator const_base_iterator
Definition: LPtrList.H:104
Foam::LPtrList::first
const T & first() const
Definition: LPtrList.H:148
Foam::LPtrList::rend
const const_reverse_iterator & rend() const
Definition: LPtrList.H:409
Foam::LList::first
reference first()
Definition: LList.H:195
Foam::LPtrList::reverse_iterator::get
pointer get() const
Definition: LPtrList.H:281
Foam::LPtrList::last
const T & last() const
Definition: LPtrList.H:160
Foam::LList::const_iterator::operator*
const_reference operator*() const
Definition: LList.H:383
Foam::LPtrList::const_reference
const typedef T & const_reference
Definition: LPtrList.H:95
Foam::LPtrList::last
T & last()
Definition: LPtrList.H:154
Foam::LPtrList::end
const const_iterator & end() const
Definition: LPtrList.H:403
Foam::LPtrList::const_iterator::const_iterator
const_iterator(const_base_iterator iter)
Definition: LPtrList.H:232
Foam::LPtrList::iterator::operator->
pointer operator->() const
Definition: LPtrList.H:211
Foam::LList::reverse_iterator
Definition: LList.H:416
Foam::LPtrList::const_reverse_iterator
Definition: LPtrList.H:307
Foam::LPtrList::iterator::iterator
iterator(base_iterator iter)
Definition: LPtrList.H:195
Foam::LPtrList::reverse_iterator::operator->
pointer operator->() const
Definition: LPtrList.H:291
Foam::LPtrList::const_iterator
Definition: LPtrList.H:226
Foam::LList::reverse_iterator::operator*
reference operator*() const
Definition: LList.H:428
Foam::LList::const_reverse_iterator
Definition: LList.H:456
Foam::LList::iterator
Definition: LList.H:321
Foam::LPtrList::const_reverse_iterator::operator->
const_pointer operator->() const
Definition: LPtrList.H:329
Foam::LPtrList::reference
T & reference
Definition: LPtrList.H:92
Foam::LPtrList::const_reverse_iterator::operator()
const_reference operator()() const
Definition: LPtrList.H:334
Foam::LPtrList::rbegin
reverse_iterator rbegin()
Definition: LPtrList.H:354
Foam::LPtrList::const_iterator::operator->
const_pointer operator->() const
Definition: LPtrList.H:253
Foam::LPtrList::base_iterator
typename LListBase::iterator base_iterator
Definition: LPtrList.H:103
Foam::LPtrList::end
const iterator & end()
Definition: LPtrList.H:379
Foam::LPtrList
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:46
Foam::LList
Template class for non-intrusive linked lists.
Definition: LList.H:50
Foam::LPtrList::transfer
void transfer(LPtrList< LListBase, T > &lst)
Definition: LPtrList.C:86
Foam::INew
A helper class when constructing from an Istream or dictionary.
Definition: INew.H:45
Foam::LPtrList::operator=
void operator=(const LPtrList< LListBase, T > &lst)
Definition: LPtrList.C:96
Foam::LPtrList::rend
const reverse_iterator & rend()
Definition: LPtrList.H:391
Foam::LList::iterator::operator*
reference operator*() const
Definition: LList.H:333
Foam::LPtrList::first
T & first()
Definition: LPtrList.H:142
Foam::LPtrList::const_reverse_iterator::const_reverse_iterator
const_reverse_iterator(const_base_iterator iter)
Definition: LPtrList.H:313
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
LPtrList.C
Foam::LPtrList::LPtrList
LPtrList(T *item)
Definition: LPtrList.H:116
Foam::LPtrList::rbegin
const_reverse_iterator rbegin() const
Definition: LPtrList.H:372
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:51
Foam::LPtrList::const_pointer
const typedef T * const_pointer
Definition: LPtrList.H:89
Foam::LPtrList::const_iterator::get
const_pointer get() const
Definition: LPtrList.H:243
Foam::LPtrList::const_iterator::operator()
const_reference operator()() const
Definition: LPtrList.H:258
Foam::LPtrList::iterator
Definition: LPtrList.H:189
Foam::LPtrList::~LPtrList
~LPtrList()
Definition: LPtrList.C:49
LList.H
Foam::LPtrList::const_reverse_iterator::operator*
const_reference operator*() const
Definition: LPtrList.H:324
os
OBJstream os(runTime.globalPath()/outputName)
Foam::LPtrList::crbegin
const_reverse_iterator crbegin() const
Definition: LPtrList.H:360
Foam
Definition: atmBoundaryLayer.C:26
Foam::LPtrList::const_reverse_iterator::get
const_pointer get() const
Definition: LPtrList.H:319
Foam::LPtrList::pointer
T * pointer
Definition: LPtrList.H:86
Foam::LPtrList::eraseHead
bool eraseHead()
Definition: LPtrList.C:58
Foam::LPtrList::const_iterator::const_iterator
const_iterator(base_iterator iter)
Definition: LPtrList.H:237
Foam::LPtrList::begin
const_iterator begin() const
Definition: LPtrList.H:366
Foam::LPtrList::parent_type
LList< LListBase, T * > parent_type
Definition: LPtrList.H:107
Foam::LPtrList::reverse_iterator::operator*
reference operator*() const
Definition: LPtrList.H:286
stdFoam::cbegin
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Definition: stdFoam.H:118
Foam::LPtrList::reverse_iterator
Definition: LPtrList.H:269
Foam::LPtrList::crend
const const_reverse_iterator & crend() const
Definition: LPtrList.H:397
LPtrListIO.C
Foam::LPtrList::iterator::get
pointer get() const
Definition: LPtrList.H:201
Foam::LPtrList::const_iterator::operator*
const_reference operator*() const
Definition: LPtrList.H:248
Foam::LList::last
reference last()
Definition: LList.H:207
Foam::LPtrList::cend
const const_iterator & cend() const
Definition: LPtrList.H:385
Foam::LPtrList::iterator::operator*
reference operator*() const
Definition: LPtrList.H:206
Foam::LPtrList::reverse_iterator::operator()
reference operator()() const
Definition: LPtrList.H:296
Foam::LPtrList::LPtrList
LPtrList()=default
Foam::Ostream
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:52
Foam::LPtrList::iterator::operator()
reference operator()() const
Definition: LPtrList.H:216
Foam::LList::const_reverse_iterator::operator*
const_reference operator*() const
Definition: LList.H:468
Foam::LList::const_iterator
Definition: LList.H:365
Foam::LPtrList::clear
void clear()
Definition: LPtrList.C:73
Foam::LPtrList::reverse_iterator::reverse_iterator
reverse_iterator(base_iterator iter)
Definition: LPtrList.H:275