UILList.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::UILList
26 
27 Description
28  Template class for intrusive linked lists.
29 
30 SourceFiles
31  UILList.C
32  UILListIO.C
33 
34 \*---------------------------------------------------------------------------*/
35 
36 #ifndef UILList_H
37 #define UILList_H
38 
39 #include "label.H"
40 #include "uLabel.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 class Ostream;
48 
49 // Forward declaration of friend functions and operators
50 
51 template<class LListBase, class T>
52 class UILList;
53 
54 template<class LListBase, class T>
55 Ostream& operator<<
56 (
57  Ostream&,
59 );
60 
61 
62 /*---------------------------------------------------------------------------*\
63  Class UILList Declaration
64 \*---------------------------------------------------------------------------*/
65 
66 template<class LListBase, class T>
67 class UILList
68 :
69  public LListBase
70 {
71 
72 public:
73 
74  // Forward declaration of STL iterators
75 
76  class iterator;
77  friend class iterator;
78 
79  class const_iterator;
80  friend class const_iterator;
81 
83  friend class const_reverse_iterator;
84 
85 
86  // Constructors
87 
88  //- Null construct
89  UILList()
90  {}
91 
92  //- Construct given initial T
93  UILList(T* a)
94  :
95  LListBase(a)
96  {}
97 
98  //- Construct as copy
100 
101 
102  // Member Functions
103 
104  // Access
105 
106  //- Return the first entry
107  T* first()
108  {
109  return static_cast<T*>(LListBase::first());
110  }
111 
112  //- Return the first entry
113  const T* first() const
114  {
115  return static_cast<const T*>(LListBase::first());
116  }
117 
118  //- Return the last entry
119  T* last()
120  {
121  return static_cast<T*>(LListBase::last());
122  }
123 
124  //- Return the last entry
125  const T* last() const
126  {
127  return static_cast<const T*>(LListBase::last());
128  }
129 
130 
131  // Edit
132 
133  //- Remove and return head
134  T* removeHead()
135  {
136  return static_cast<T*>(LListBase::removeHead());
137  }
138 
139  //- Remove and return element
140  T* remove(T* p)
141  {
142  return static_cast<T*>(LListBase::remove(p));
143  }
144 
145  //- Remove and return specified by iterator
146  T* remove(iterator& it)
147  {
148  return static_cast<T*>(LListBase::remove(it));
149  }
150 
151 
152  // Member operators
153 
154  void operator=(const UILList<LListBase, T>&);
155 
156 
157  // STL type definitions
158 
159  //- Type of values the DLList contains.
160  typedef T value_type;
161 
162  //- Type that can be used for storing into DLList::value_type
163  // objects.
164  typedef T& reference;
165 
166  //- Type that can be used for storing into constant
167  // DLList::value_type objects.
168  typedef const T& const_reference;
169 
170  //- The type that can represent the size of a DLList.
171  typedef label size_type;
172 
173 
174  // STL iterator
176  typedef typename LListBase::iterator LListBase_iterator;
177 
178  //- An STL-conforming iterator
179  class iterator
180  :
181  public LListBase_iterator
182  {
183 
184  public:
185 
186  //- Construct from base iterator
187  iterator(LListBase_iterator baseIter)
188  :
189  LListBase_iterator(baseIter)
190  {}
191 
192 
193  // Member operators
195  T& operator*()
196  {
197  return static_cast<T&>(LListBase_iterator::operator*());
198  }
200  T& operator()()
201  {
202  return operator*();
203  }
206  {
207  LListBase_iterator::operator++();
208  return *this;
209  }
210  };
212  inline iterator begin()
213  {
214  return LListBase::begin();
215  }
217  inline const iterator& end()
218  {
219  return static_cast<const iterator&>(LListBase::end());
220  }
221 
222 
223  // STL const_iterator
225  typedef typename LListBase::const_iterator LListBase_const_iterator;
226 
227  //- An STL-conforming const_iterator
228  class const_iterator
229  :
230  public LListBase_const_iterator
231  {
232 
233  public:
234 
235  //- Construct from base const_iterator
236  const_iterator(LListBase_const_iterator baseIter)
237  :
238  LListBase_const_iterator(baseIter)
239  {}
240 
241  //- Construct from base iterator
242  const_iterator(LListBase_iterator baseIter)
243  :
244  LListBase_const_iterator(baseIter)
245  {}
246 
247 
248  // Member operators
250  const T& operator*()
251  {
252  return
253  static_cast<const T&>
255  }
257  const T& operator()()
258  {
259  return operator*();
260  }
263  {
264  LListBase_const_iterator::operator++();
265  return *this;
266  }
267  };
269  inline const_iterator cbegin() const
270  {
271  return LListBase::cbegin();
272  }
274  inline const const_iterator& cend() const
275  {
276  return static_cast<const const_iterator&>(LListBase::cend());
277  }
279  inline const_iterator begin() const
280  {
281  return LListBase::begin();
282  }
284  inline const const_iterator& end() const
285  {
286  return static_cast<const const_iterator&>(LListBase::end());
287  }
288 
289 
290  // STL const_reverse_iterator
291 
292  //- An STL-conforming const_reverse_iterator
294  :
295  public LListBase::const_reverse_iterator
296  {
297 
298  public:
299 
300  //- Construct from base const_reverse_iterator
302  (
303  typename LListBase::const_reverse_iterator baseIter
304  )
305  :
306  LListBase::const_reverse_iterator(baseIter)
307  {}
308 
309 
310  // Member operators
312  const T& operator*()
313  {
314  return
315  static_cast<const T&>
317  }
319  const T& operator()()
320  {
321  return operator*();
322  }
325  {
326  LListBase::const_reverse_iterator::operator++();
327  return *this;
328  }
329  };
331  inline const_reverse_iterator crbegin() const
332  {
333  return LListBase::crbegin();
334  }
336  inline const const_reverse_iterator& crend() const
337  {
338  return
339  static_cast<const const_reverse_iterator&>(LListBase::crend());
340  }
341 
343  inline const_reverse_iterator rbegin() const
344  {
345  return LListBase::rbegin();
346  }
348  inline const const_reverse_iterator& rend() const
349  {
350  return
351  static_cast<const const_reverse_iterator&>(LListBase::rend());
352  }
353 
354 
355  // STL member operators
356 
357  //- Equality operation on ULists of the same type.
358  // Returns true when the ULists are element-wise equal
359  // (using UList::value_type::operator==). Takes linear time.
360  bool operator==(const UILList<LListBase, T>&) const;
361 
362  //- The opposite of the equality operation. Takes linear time.
363  bool operator!=(const UILList<LListBase, T>&) const;
364 
365 
366  // Ostream operator
367 
368  friend Ostream& operator<< <LListBase, T>
369  (
370  Ostream&,
371  const UILList<LListBase, T>&
372  );
373 };
374 
375 
376 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
377 
378 } // End namespace Foam
379 
380 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
381 
382 #ifdef NoRepository
383  #include "UILList.C"
384 #endif
385 
386 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
387 
388 #endif
389 
390 // ************************************************************************* //
const const_iterator & cend() const
Definition: UILList.H:273
Template class for intrusive linked lists.
Definition: UILList.H:51
const_reverse_iterator rbegin() const
Definition: UILList.H:342
const T & const_reference
Type that can be used for storing into constant.
Definition: UILList.H:167
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
iterator & operator++()
Definition: UILList.H:204
bool operator==(const UILList< LListBase, T > &) const
Equality operation on ULists of the same type.
Definition: UILList.C:56
LListBase::iterator LListBase_iterator
Definition: UILList.H:175
T * last()
Return the last entry.
Definition: UILList.H:118
An STL-conforming const_iterator.
Definition: UILList.H:227
LListBase::const_iterator LListBase_const_iterator
Definition: UILList.H:224
iterator(LListBase_iterator baseIter)
Construct from base iterator.
Definition: UILList.H:186
const_iterator cbegin() const
Definition: UILList.H:268
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
friend class const_reverse_iterator
Definition: UILList.H:81
An STL-conforming iterator.
Definition: UILList.H:178
const iterator & end()
Definition: UILList.H:216
bool operator!=(const UILList< LListBase, T > &) const
The opposite of the equality operation. Takes linear time.
Definition: UILList.C:81
const const_reverse_iterator & rend() const
Definition: UILList.H:347
const_reverse_iterator crbegin() const
Definition: UILList.H:330
T value_type
Type of values the DLList contains.
Definition: UILList.H:159
T & reference
Type that can be used for storing into DLList::value_type.
Definition: UILList.H:163
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
An STL-conforming const_reverse_iterator.
Definition: UILList.H:292
label size_type
The type that can represent the size of a DLList.
Definition: UILList.H:170
UILList()
Null construct.
Definition: UILList.H:88
volScalarField & p
T * first()
Return the first entry.
Definition: UILList.H:106
T * removeHead()
Remove and return head.
Definition: UILList.H:133
iterator begin()
Definition: UILList.H:211
const const_reverse_iterator & crend() const
Definition: UILList.H:335
void operator=(const UILList< LListBase, T > &)
Definition: UILList.C:43
friend class const_iterator
Definition: UILList.H:78
Namespace for OpenFOAM.