DLListBase.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 | Copyright (C) 2011-2016 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  // Private Member Functions
85 
86  //- Disallow default bitwise copy construct
87  DLListBase(const DLListBase&);
88 
89  //- Disallow default bitwise assignment
90  void operator=(const DLListBase&);
91 
92 
93 public:
94 
95  // Forward declaration of STL iterators
96 
97  class iterator;
98  friend class iterator;
99 
100  class const_iterator;
101  friend class const_iterator;
104  friend class const_reverse_iterator;
105 
106 
107  // Constructors
108 
109  //- Null construct
110  inline DLListBase();
111 
112  //- Construct given initial entry
113  inline DLListBase(link*);
114 
115 
116  //- Destructor
117  ~DLListBase();
118 
119 
120  // Member Functions
121 
122  // Access
123 
124  //- Return number of elements in list
125  inline label size() const;
126 
127  //- Return true if the list is empty
128  inline bool empty() const;
129 
130  //- Return first entry
131  inline link* first();
132 
133  //- Return const access to first entry
134  inline const link* first() const;
135 
136  //- Return last entry
137  inline link* last();
138 
139  //- Return const access to last entry
140  inline const link* last() const;
141 
142 
143  // Edit
144 
145  //- Add at head of list
146  void insert(link*);
147 
148  //- Add at tail of list
149  void append(link*);
150 
151  //- Swap this element with the one above unless it is at the top
152  bool swapUp(link*);
153 
154  //- Swap this element with the one below unless it is at the bottom
155  bool swapDown(link*);
156 
157  //- Remove and return head
158  link* removeHead();
159 
160  //- Remove and return element
161  link* remove(link*);
162 
163  // Remove and return element specified by iterator
164  inline link* remove(iterator&);
165 
166  //- Replace oldLink with newLink and return element
167  link* replace(link* oldLink, link* newLink);
168 
169  //- Replace oldIter with newLink and return element
170  inline link* replace(iterator& oldIter, link* newLink);
171 
172  //- Clear the list
173  inline void clear();
174 
175  //- Transfer the contents of the argument into this List
176  // and annul the argument list.
177  inline void transfer(DLListBase&);
178 
179  // STL iterator
180 
181  //- An STL-conforming iterator
182  class iterator
183  {
184  friend class DLListBase;
185  friend class const_iterator;
186 
187  // Private data
188 
189  //- Reference to the list this is an iterator for
190  DLListBase& curList_;
191 
192  //- Current element
193  link* curElmt_;
194 
195  //- Copy of the link
196  link curLink_;
197 
198  // Private Member Functions
199 
200  //- Construct for a given SLListBase with nullptr element and link.
201  // Only used to create endIter
202  inline iterator(DLListBase&);
203 
204  public:
205 
206  //- Construct for a given DLListBase and link
207  inline iterator(DLListBase&, link*);
208 
209  // Member operators
210 
211  inline void operator=(const iterator&);
212 
213  inline bool operator==(const iterator&) const;
214  inline bool operator!=(const iterator&) const;
215 
216  inline link& operator*();
217 
218  inline iterator& operator++();
219  inline iterator operator++(int);
220  };
221 
222  inline iterator begin();
223  inline const iterator& end();
224 
225 
226  // STL const_iterator
227 
228  //- An STL-conforming const_iterator
229  class const_iterator
230  {
231  // Private data
232 
233  //- Reference to the list this is an iterator for
234  const DLListBase& curList_;
235 
236  //- Current element
237  const link* curElmt_;
238 
239  public:
240 
241  //- Construct for a given DLListBase and link
242  inline const_iterator(const DLListBase&, const link*);
243 
244  //- Construct from a non-const iterator
245  inline const_iterator(const iterator&);
246 
247  // Member operators
248 
249  inline void operator=(const const_iterator&);
250 
251  inline bool operator==(const const_iterator&) const;
252  inline bool operator!=(const const_iterator&) const;
253 
254  inline const link& operator*();
255 
256  inline const_iterator& operator++();
257  inline const_iterator operator++(int);
258  };
259 
260  inline const_iterator cbegin() const;
261  inline const const_iterator& cend() const;
262 
263  inline const_iterator begin() const;
264  inline const const_iterator& end() const;
265 
266 
267  // STL const_reverse_iterator
268 
269  //- An STL-conforming const_reverse_iterator
271  {
272  // Private data
273 
274  //- Reference to the list this is an reverse_iterator for
275  const DLListBase& curList_;
276 
277  //- Current element
278  const link* curElmt_;
279 
280  public:
281 
282  //- Construct for a given DLListBase and link
283  inline const_reverse_iterator(const DLListBase&, const link*);
284 
285  // Member operators
286 
287  inline void operator=(const const_reverse_iterator&);
288 
289  inline bool operator==(const const_reverse_iterator&) const;
290  inline bool operator!=(const const_reverse_iterator&) const;
291 
292  inline const link& operator*();
293 
294  inline const_reverse_iterator& operator++();
295  inline const_reverse_iterator operator++(int);
296  };
297 
298  inline const_reverse_iterator crbegin() const;
299  inline const const_reverse_iterator& crend() const;
300 
301  inline const_reverse_iterator rbegin() const;
302  inline const const_reverse_iterator& rend() const;
303 
304 
305 private:
306 
307  //- Iterator returned by end()
308  static iterator endIter_;
309 
310  //- const_iterator returned by end()
311  static const_iterator endConstIter_;
312 
313  //- const_reverse_iterator returned by end()
314  static const_reverse_iterator endConstRevIter_;
315 };
316 
317 
318 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
319 
320 } // End namespace Foam
321 
322 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
323 
324 #include "DLListBaseI.H"
325 
326 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
327 
328 #endif
329 
330 // ************************************************************************* //
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
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
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
An STL-conforming const_reverse_iterator.
Definition: DLListBase.H:269
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:228
An STL-conforming iterator.
Definition: DLListBase.H:181
friend class const_iterator
Definition: DLListBase.H:99
friend class const_reverse_iterator
Definition: DLListBase.H:102
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:1106
friend class iterator
Definition: DLListBase.H:96
System bool.
Namespace for OpenFOAM.