DLListBase.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-2020 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::DLListBase
26 
27 Description
28  Base doubly-linked list.
29 
30 SourceFiles
31  DLListBase.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef DLListBase_H
36 #define DLListBase_H
37 
38 #include "bool.H"
39 #include "label.H"
40 #include "uLabel.H"
41 
42 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
43 
44 namespace Foam
45 {
46 
47 /*---------------------------------------------------------------------------*\
48  Class DLListBase Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class DLListBase
52 {
53 
54 public:
55 
56  //- Link structure
57  struct link
58  {
59  //- Pointer to next entry in list
60  link *prev_, *next_;
61 
62  //- Null construct
63  inline link();
64 
65  //- Check if the link is registered with the DLListBase
66  inline bool registered() const;
67 
68  //- Deregister the link after removal
69  inline void deregister();
70  };
71 
72 
73 private:
74 
75  // Private Data
76 
77  //- first_ points to first element and last_ points to last element.
78  link *first_, *last_;
79 
80  //- Number of elements in in list
81  label nElmts_;
82 
83 
84 public:
85 
86  // Forward declaration of STL iterators
87 
88  class iterator;
89  friend class iterator;
90 
91  class const_iterator;
92  friend class const_iterator;
93 
95  friend class const_reverse_iterator;
96 
97 
98  // Constructors
99 
100  //- Null construct
101  inline DLListBase();
102 
103  //- Construct given initial entry
104  inline DLListBase(link*);
105 
106  //- Disallow default bitwise copy construction
107  DLListBase(const DLListBase&) = delete;
108 
109 
110  //- Destructor
111  ~DLListBase();
112 
113 
114  // Member Functions
115 
116  // Access
117 
118  //- Return number of elements in list
119  inline label size() const;
120 
121  //- Return true if the list is empty
122  inline bool empty() const;
123 
124  //- Return first entry
125  inline link* first();
126 
127  //- Return const access to first entry
128  inline const link* first() const;
129 
130  //- Return last entry
131  inline link* last();
132 
133  //- Return const access to last entry
134  inline const link* last() const;
135 
136 
137  // Edit
138 
139  //- Add at head of list
140  void insert(link*);
141 
142  //- Add at tail of list
143  void append(link*);
144 
145  //- Swap this element with the one above unless it is at the top
146  bool swapUp(link*);
147 
148  //- Swap this element with the one below unless it is at the bottom
149  bool swapDown(link*);
150 
151  //- Remove and return head
152  link* removeHead();
153 
154  //- Remove and return element
155  link* remove(link*);
156 
157  // Remove and return element specified by iterator
158  inline link* remove(iterator&);
159 
160  //- Replace oldLink with newLink and return element
161  link* replace(link* oldLink, link* newLink);
162 
163  //- Replace oldIter with newLink and return element
164  inline link* replace(iterator& oldIter, link* newLink);
165 
166  //- Clear the list
167  inline void clear();
168 
169  //- Transfer the contents of the argument into this List
170  // and annul the argument list.
171  inline void transfer(DLListBase&);
172 
173 
174  // Member Operators
175 
176  //- Disallow default bitwise assignment
177  void operator=(const DLListBase&) = delete;
178 
179 
180  // STL iterator
181 
182  //- An STL-conforming iterator
183  class iterator
184  {
185  friend class DLListBase;
186  friend class const_iterator;
187 
188  // Private Data
189 
190  //- Reference to the list this is an iterator for
191  DLListBase& curList_;
192 
193  //- Current element
194  link* curElmt_;
195 
196  //- Copy of the link
197  link curLink_;
198 
199  // Private Member Functions
200 
201  //- Construct for a given SLListBase with nullptr element and link.
202  // Only used to create endIter
203  inline iterator(DLListBase&);
204 
205  public:
206 
207  //- Construct for a given DLListBase and link
208  inline iterator(DLListBase&, link*);
209 
210  //- Copy constructor
211  inline iterator(const iterator&) = default;
212 
213  // Member Operators
214 
215  inline void operator=(const iterator&);
216 
217  inline bool operator==(const iterator&) const;
218  inline bool operator!=(const iterator&) const;
219 
220  inline link& operator*();
221 
222  inline iterator& operator++();
223  inline iterator operator++(int);
224  };
225 
226  inline iterator begin();
227  inline const iterator& end();
228 
229 
230  // STL const_iterator
231 
232  //- An STL-conforming const_iterator
233  class const_iterator
234  {
235  // Private Data
236 
237  //- Reference to the list this is an iterator for
238  const DLListBase& curList_;
239 
240  //- Current element
241  const link* curElmt_;
242 
243  public:
244 
245  //- Construct for a given DLListBase and link
246  inline const_iterator(const DLListBase&, const link*);
247 
248  //- Construct from a non-const iterator
249  inline const_iterator(const iterator&);
250 
251  //- Copy constructor
252  inline const_iterator(const const_iterator&) = default;
253 
254  // Member Operators
255 
256  inline void operator=(const const_iterator&);
257 
258  inline bool operator==(const const_iterator&) const;
259  inline bool operator!=(const const_iterator&) const;
260 
261  inline const link& operator*();
262 
263  inline const_iterator& operator++();
264  inline const_iterator operator++(int);
265  };
266 
267  inline const_iterator cbegin() const;
268  inline const const_iterator& cend() const;
269 
270  inline const_iterator begin() const;
271  inline const const_iterator& end() const;
272 
273 
274  // STL const_reverse_iterator
275 
276  //- An STL-conforming const_reverse_iterator
278  {
279  // Private Data
280 
281  //- Reference to the list this is an reverse_iterator for
282  const DLListBase& curList_;
283 
284  //- Current element
285  const link* curElmt_;
286 
287  public:
288 
289  //- Construct for a given DLListBase and link
290  inline const_reverse_iterator(const DLListBase&, const link*);
291 
292  //- Copy constructor
294  (
296  ) = default;
297 
298  // Member Operators
299 
300  inline void operator=(const const_reverse_iterator&);
301 
302  inline bool operator==(const const_reverse_iterator&) const;
303  inline bool operator!=(const const_reverse_iterator&) const;
304 
305  inline const link& operator*();
306 
307  inline const_reverse_iterator& operator++();
308  inline const_reverse_iterator operator++(int);
309  };
310 
311  inline const_reverse_iterator crbegin() const;
312  inline const const_reverse_iterator& crend() const;
313 
314  inline const_reverse_iterator rbegin() const;
315  inline const const_reverse_iterator& rend() const;
316 
317 
318 private:
319 
320  //- Iterator returned by end()
321  static iterator endIter_;
322 
323  //- const_iterator returned by end()
324  static const_iterator endConstIter_;
325 
326  //- const_reverse_iterator returned by end()
327  static const_reverse_iterator endConstRevIter_;
328 };
329 
330 
331 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
332 
333 } // End namespace Foam
334 
335 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
336 
337 #include "DLListBaseI.H"
338 
339 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
340 
341 #endif
342 
343 // ************************************************************************* //
void operator=(const DLListBase &)=delete
Disallow default bitwise assignment.
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
Base doubly-linked list.
Definition: DLListBase.H:50
const const_reverse_iterator & crend() const
Definition: DLListBaseI.H:473
bool empty() const
Return true if the list is empty.
Definition: DLListBaseI.H:83
link * removeHead()
Remove and return head.
Definition: DLListBase.C:175
link * replace(link *oldLink, link *newLink)
Replace oldLink with newLink and return element.
Definition: DLListBase.C:232
iterator begin()
Definition: DLListBaseI.H:253
link * last()
Return last entry.
Definition: DLListBaseI.H:116
const_reverse_iterator crbegin() const
Definition: DLListBaseI.H:459
const_reverse_iterator rbegin() const
Definition: DLListBaseI.H:480
label size() const
Return number of elements in list.
Definition: DLListBaseI.H:77
~DLListBase()
Destructor.
Definition: DLListBaseI.H:58
An STL-conforming const_reverse_iterator.
Definition: DLListBase.H:276
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
const const_iterator & cend() const
Definition: DLListBaseI.H:366
bool swapDown(link *)
Swap this element with the one below unless it is at the bottom.
Definition: DLListBase.C:134
link * first()
Return first entry.
Definition: DLListBaseI.H:90
An STL-conforming const_iterator.
Definition: DLListBase.H:232
An STL-conforming iterator.
Definition: DLListBase.H:182
friend class const_iterator
Definition: DLListBase.H:90
friend class const_reverse_iterator
Definition: DLListBase.H:93
const const_reverse_iterator & rend() const
Definition: DLListBaseI.H:487
void append(link *)
Add at tail of list.
Definition: DLListBase.C:73
const iterator & end()
Definition: DLListBaseI.H:266
DLListBase()
Null construct.
Definition: DLListBaseI.H:37
bool swapUp(link *)
Swap this element with the one above unless it is at the top.
Definition: DLListBase.C:93
void transfer(DLListBase &)
Transfer the contents of the argument into this List.
Definition: DLListBaseI.H:149
const_iterator cbegin() const
Definition: DLListBaseI.H:352
void insert(link *)
Add at head of list.
Definition: DLListBase.C:53
void clear()
Clear the list.
Definition: DLListBaseI.H:141
bool operator!=(const particle &, const particle &)
Definition: particle.C:1282
friend class iterator
Definition: DLListBase.H:87
System bool.
Namespace for OpenFOAM.