SLListBase.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::SLListBase
26 
27 Description
28  Base singly-linked list.
29 
30 SourceFiles
31  SLListBase.C
32 
33 \*---------------------------------------------------------------------------*/
34 
35 #ifndef SLListBase_H
36 #define SLListBase_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 SLListBase Declaration
49 \*---------------------------------------------------------------------------*/
50 
51 class SLListBase
52 {
53 
54 public:
55 
56  //- Link structure
57  struct link
58  {
59  //- Pointer to next entry in list
60  link* next_;
61 
62  //- Null construct
63  inline link();
64 
65  //- Construct given pointer to another link
66  inline link(link* p);
67  };
68 
69 
70 private:
71 
72  // Private Data
73 
74  //- last_ points to last element
75  // last_->next_ points to first element, i.e. circular storage
76  link* last_;
77 
78  //- Number of elements in in list
79  label nElmts_;
80 
81 
82 public:
83 
84  // Forward declaration of STL iterators
85 
86  class iterator;
87  friend class iterator;
88 
89  class const_iterator;
90  friend class const_iterator;
91 
92 
93  // Constructors
94 
95  //- Null construct
96  inline SLListBase();
97 
98  //- Construct given initial entry
99  inline SLListBase(link*);
100 
101  //- Disallow default bitwise copy construction
102  SLListBase(const SLListBase&) = delete;
103 
104 
105  //- Destructor
106  ~SLListBase();
107 
108 
109  // Member Functions
110 
111  // Access
112 
113  //- Return number of elements in list
114  inline label size() const;
115 
116  //- Return true if the list is empty
117  inline bool empty() const;
118 
119  //- Return first entry
120  inline link* first();
121 
122  //- Return const access to first entry
123  inline const link* first() const;
124 
125  //- Return last entry
126  inline link* last();
127 
128  //- Return const access to last entry
129  inline const link* last() const;
130 
131 
132  // Edit
133 
134  //- Add at head of list
135  void insert(link*);
136 
137  //- Add at tail of list
138  void append(link*);
139 
140  //- Remove and return head
141  link* removeHead();
142 
143  // Remove and return element
144  link* remove(link*);
145 
146  // Remove and return element specified by iterator
147  inline link* remove(iterator&);
148 
149  //- Clear the list
150  inline void clear();
151 
152  //- Transfer the contents of the argument into this List
153  // and annul the argument list.
154  inline void transfer(SLListBase&);
155 
156 
157  // Member Operators
158 
159  //- Disallow default bitwise assignment
160  void operator=(const SLListBase&) = delete;
161 
162 
163  // STL iterator
164 
165  //- An STL-conforming iterator
166  class iterator
167  {
168  friend class SLListBase;
169  friend class const_iterator;
170 
171  // Private Data
172 
173  //- Reference to the list this is an iterator for
174  SLListBase& curList_;
175 
176  //- Current element
177  link* curElmt_;
178 
179  //- Copy of the link
180  link curLink_;
181 
182  // Private Member Functions
183 
184  //- Construct for a given SLListBase with nullptr element and link.
185  // Only used to create endIter
186  inline iterator(SLListBase&);
187 
188  public:
189 
190  //- Construct for a given SLListBase and link
191  inline iterator(SLListBase&, link*);
192 
193  //- Copy constructor
194  inline iterator(const iterator&) = default;
195 
196  // Member Operators
197 
198  inline void operator=(const iterator&);
199 
200  inline bool operator==(const iterator&) const;
201  inline bool operator!=(const iterator&) const;
202 
203  inline link& operator*();
204 
205  inline iterator& operator++();
206  inline iterator operator++(int);
207  };
208 
209  inline iterator begin();
210  inline const iterator& end();
211 
212 
213  // STL const_iterator
214 
215  //- An STL-conforming const_iterator
216  class const_iterator
217  {
218  // Private Data
219 
220  //- Reference to the list this is an iterator for
221  const SLListBase& curList_;
222 
223  //- Current element
224  const link* curElmt_;
225 
226  public:
227 
228  //- Construct for a given SLListBase and link
229  inline const_iterator(const SLListBase&, const link*);
230 
231  //- Construct from a non-const iterator
232  inline const_iterator(const iterator&);
233 
234  //- Copy constructor
235  inline const_iterator(const const_iterator&) = default;
236 
237  // Member Operators
238 
239  inline void operator=(const const_iterator&);
240 
241  inline bool operator==(const const_iterator&) const;
242  inline bool operator!=(const const_iterator&) const;
243 
244  inline const link& operator*();
245 
246  inline const_iterator& operator++();
247  inline const_iterator operator++(int);
248  };
249 
250  inline const_iterator cbegin() const;
251  inline const const_iterator& cend() const;
252 
253  inline const_iterator begin() const;
254  inline const const_iterator& end() const;
255 
256 
257 private:
258 
259  //- Iterator returned by end()
260  static iterator endIter_;
261 
262  //- const_iterator returned by end()
263  static const_iterator endConstIter_;
264 };
265 
266 
267 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
268 
269 } // End namespace Foam
270 
271 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
272 
273 #include "SLListBaseI.H"
274 
275 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
276 
277 #endif
278 
279 // ************************************************************************* //
link * first()
Return first entry.
Definition: SLListBaseI.H:80
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
friend class iterator
Definition: SLListBase.H:85
Base singly-linked list.
Definition: SLListBase.H:50
void clear()
Clear the list.
Definition: SLListBaseI.H:131
void transfer(SLListBase &)
Transfer the contents of the argument into this List.
Definition: SLListBaseI.H:138
An STL-conforming const_iterator.
Definition: SLListBase.H:215
void append(link *)
Add at tail of list.
Definition: SLListBase.C:62
SLListBase()
Null construct.
Definition: SLListBaseI.H:45
const_iterator cbegin() const
Definition: SLListBaseI.H:325
label size() const
Return number of elements in list.
Definition: SLListBaseI.H:67
tmp< fvMatrix< Type > > operator*(const volScalarField::Internal &, const fvMatrix< Type > &)
const const_iterator & cend() const
Definition: SLListBaseI.H:339
tmp< fvMatrix< Type > > operator==(const fvMatrix< Type > &, const fvMatrix< Type > &)
Base singly-linked list.
void insert(link *)
Add at head of list.
Definition: SLListBase.C:45
const iterator & end()
Definition: SLListBaseI.H:239
iterator begin()
Definition: SLListBaseI.H:225
bool empty() const
Return true if the list is empty.
Definition: SLListBaseI.H:73
void operator=(const SLListBase &)=delete
Disallow default bitwise assignment.
link * removeHead()
Remove and return head.
Definition: SLListBase.C:78
volScalarField & p
bool operator!=(const particle &, const particle &)
Definition: particle.C:1223
~SLListBase()
Destructor.
Definition: SLListBaseI.H:61
An STL-conforming iterator.
Definition: SLListBase.H:165
friend class const_iterator
Definition: SLListBase.H:88
System bool.
Namespace for OpenFOAM.
link * last()
Return last entry.
Definition: SLListBaseI.H:106