All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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-2019 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  //- Copy constructor
100 
101  //- Move constructor
103 
104 
105  // Member Functions
106 
107  // Access
108 
109  //- Return the first entry
110  T* first()
111  {
112  return static_cast<T*>(LListBase::first());
113  }
114 
115  //- Return the first entry
116  const T* first() const
117  {
118  return static_cast<const T*>(LListBase::first());
119  }
120 
121  //- Return the last entry
122  T* last()
123  {
124  return static_cast<T*>(LListBase::last());
125  }
126 
127  //- Return the last entry
128  const T* last() const
129  {
130  return static_cast<const T*>(LListBase::last());
131  }
132 
133 
134  // Edit
135 
136  //- Remove and return head
137  T* removeHead()
138  {
139  return static_cast<T*>(LListBase::removeHead());
140  }
141 
142  //- Remove and return element
143  T* remove(T* p)
144  {
145  return static_cast<T*>(LListBase::remove(p));
146  }
147 
148  //- Remove and return specified by iterator
149  T* remove(iterator& it)
150  {
151  return static_cast<T*>(LListBase::remove(it));
152  }
153 
154 
155  // Member Operators
156 
157  //- Assignment operator
158  void operator=(const UILList<LListBase, T>&);
159 
160  //- Move assignment operator
162 
163 
164  // STL type definitions
165 
166  //- Type of values the DLList contains.
167  typedef T value_type;
168 
169  //- Type that can be used for storing into DLList::value_type
170  // objects.
171  typedef T& reference;
172 
173  //- Type that can be used for storing into constant
174  // DLList::value_type objects.
175  typedef const T& const_reference;
176 
177  //- The type that can represent the size of a DLList.
178  typedef label size_type;
179 
180 
181  // STL iterator
183  typedef typename LListBase::iterator LListBase_iterator;
184 
185  //- An STL-conforming iterator
186  class iterator
187  :
188  public LListBase_iterator
189  {
190 
191  public:
192 
193  //- Construct from base iterator
194  iterator(LListBase_iterator baseIter)
195  :
196  LListBase_iterator(baseIter)
197  {}
198 
199 
200  // Member Operators
202  T& operator*()
203  {
204  return static_cast<T&>(LListBase_iterator::operator*());
205  }
207  T& operator()()
208  {
209  return operator*();
210  }
213  {
214  LListBase_iterator::operator++();
215  return *this;
216  }
217  };
219  inline iterator begin()
220  {
221  return LListBase::begin();
222  }
224  inline const iterator& end()
225  {
226  return static_cast<const iterator&>(LListBase::end());
227  }
228 
229 
230  // STL const_iterator
232  typedef typename LListBase::const_iterator LListBase_const_iterator;
233 
234  //- An STL-conforming const_iterator
235  class const_iterator
236  :
237  public LListBase_const_iterator
238  {
239 
240  public:
241 
242  //- Construct from base const_iterator
243  const_iterator(LListBase_const_iterator baseIter)
244  :
245  LListBase_const_iterator(baseIter)
246  {}
247 
248  //- Construct from base iterator
249  const_iterator(LListBase_iterator baseIter)
250  :
251  LListBase_const_iterator(baseIter)
252  {}
253 
254 
255  // Member Operators
257  const T& operator*()
258  {
259  return
260  static_cast<const T&>
262  }
264  const T& operator()()
265  {
266  return operator*();
267  }
270  {
271  LListBase_const_iterator::operator++();
272  return *this;
273  }
274  };
276  inline const_iterator cbegin() const
277  {
278  return LListBase::cbegin();
279  }
281  inline const const_iterator& cend() const
282  {
283  return static_cast<const const_iterator&>(LListBase::cend());
284  }
286  inline const_iterator begin() const
287  {
288  return LListBase::begin();
289  }
291  inline const const_iterator& end() const
292  {
293  return static_cast<const const_iterator&>(LListBase::end());
294  }
295 
296 
297  // STL const_reverse_iterator
298 
299  //- An STL-conforming const_reverse_iterator
301  :
302  public LListBase::const_reverse_iterator
303  {
304 
305  public:
306 
307  //- Construct from base const_reverse_iterator
309  (
310  typename LListBase::const_reverse_iterator baseIter
311  )
312  :
313  LListBase::const_reverse_iterator(baseIter)
314  {}
315 
316 
317  // Member Operators
319  const T& operator*()
320  {
321  return
322  static_cast<const T&>
324  }
326  const T& operator()()
327  {
328  return operator*();
329  }
332  {
333  LListBase::const_reverse_iterator::operator++();
334  return *this;
335  }
336  };
338  inline const_reverse_iterator crbegin() const
339  {
340  return LListBase::crbegin();
341  }
343  inline const const_reverse_iterator& crend() const
344  {
345  return
346  static_cast<const const_reverse_iterator&>(LListBase::crend());
347  }
348 
350  inline const_reverse_iterator rbegin() const
351  {
352  return LListBase::rbegin();
353  }
355  inline const const_reverse_iterator& rend() const
356  {
357  return
358  static_cast<const const_reverse_iterator&>(LListBase::rend());
359  }
360 
361 
362  // STL member operators
363 
364  //- Equality operation on ULists of the same type.
365  // Returns true when the ULists are element-wise equal
366  // (using UList::value_type::operator==). Takes linear time.
367  bool operator==(const UILList<LListBase, T>&) const;
368 
369  //- The opposite of the equality operation. Takes linear time.
370  bool operator!=(const UILList<LListBase, T>&) const;
371 
372 
373  // Ostream operator
374 
375  friend Ostream& operator<< <LListBase, T>
376  (
377  Ostream&,
378  const UILList<LListBase, T>&
379  );
380 };
381 
382 
383 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
384 
385 } // End namespace Foam
386 
387 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
388 
389 #ifdef NoRepository
390  #include "UILList.C"
391 #endif
392 
393 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
394 
395 #endif
396 
397 // ************************************************************************* //
const const_iterator & cend() const
Definition: UILList.H:280
Template class for intrusive linked lists.
Definition: UILList.H:51
const_reverse_iterator rbegin() const
Definition: UILList.H:349
const T & const_reference
Type that can be used for storing into constant.
Definition: UILList.H:174
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:211
bool operator==(const UILList< LListBase, T > &) const
Equality operation on ULists of the same type.
Definition: UILList.C:70
LListBase::iterator LListBase_iterator
Definition: UILList.H:182
T * last()
Return the last entry.
Definition: UILList.H:121
An STL-conforming const_iterator.
Definition: UILList.H:234
LListBase::const_iterator LListBase_const_iterator
Definition: UILList.H:231
iterator(LListBase_iterator baseIter)
Construct from base iterator.
Definition: UILList.H:193
const_iterator cbegin() const
Definition: UILList.H:275
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:185
const iterator & end()
Definition: UILList.H:223
bool operator!=(const UILList< LListBase, T > &) const
The opposite of the equality operation. Takes linear time.
Definition: UILList.C:95
const const_reverse_iterator & rend() const
Definition: UILList.H:354
const_reverse_iterator crbegin() const
Definition: UILList.H:337
T value_type
Type of values the DLList contains.
Definition: UILList.H:166
T & reference
Type that can be used for storing into DLList::value_type.
Definition: UILList.H:170
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
An STL-conforming const_reverse_iterator.
Definition: UILList.H:299
label size_type
The type that can represent the size of a DLList.
Definition: UILList.H:177
UILList()
Null construct.
Definition: UILList.H:88
volScalarField & p
T * first()
Return the first entry.
Definition: UILList.H:109
T * removeHead()
Remove and return head.
Definition: UILList.H:136
iterator begin()
Definition: UILList.H:218
const const_reverse_iterator & crend() const
Definition: UILList.H:342
void operator=(const UILList< LListBase, T > &)
Assignment operator.
Definition: UILList.C:50
friend class const_iterator
Definition: UILList.H:78
Namespace for OpenFOAM.