SLListBaseI.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 | www.openfoam.com
6 \\/ M anipulation |
7-------------------------------------------------------------------------------
8 Copyright (C) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27\*---------------------------------------------------------------------------*/
28
29#include "error.H"
30#include "nullObject.H"
31
32// * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33
34template<class IteratorType>
35inline const IteratorType& Foam::SLListBase::iterator_end()
36{
37 return *reinterpret_cast<const IteratorType*>(nullObjectPtr);
38}
39
40
41template<class IteratorType>
42inline IteratorType Foam::SLListBase::iterator_first() const
43{
44 SLListBase* list = const_cast<SLListBase*>(this);
45
46 if (size())
47 {
48 return IteratorType(list, const_cast<SLListBase::link*>(last_->next_));
49 }
50
51 // Return an end iterator
52 return IteratorType(list, nullptr);
53}
54
55
56template<class IteratorType>
57inline IteratorType Foam::SLListBase::iterator_last() const
58{
59 SLListBase* list = const_cast<SLListBase*>(this);
60
61 if (size())
62 {
63 return IteratorType(list, const_cast<SLListBase::link*>(last_));
64 }
65
66 // Return an end iterator
67 return IteratorType(list, nullptr);
68}
69
70
71// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
72
73inline Foam::label Foam::SLListBase::size() const noexcept
74{
75 return size_;
76}
77
78
80{
81 return !size_;
82}
83
84
87{
88 if (!size_)
89 {
91 << "list is empty"
92 << abort(FatalError);
93 }
94 return last_->next_;
95}
96
97
98inline const Foam::SLListBase::link*
100{
101 if (!size_)
102 {
104 << "list is empty"
105 << abort(FatalError);
106 }
107 return last_->next_;
108}
109
110
113{
114 if (!size_)
115 {
117 << "list is empty"
118 << abort(FatalError);
119 }
120 return last_;
121}
122
123
124inline const Foam::SLListBase::link*
126{
127 if (!size_)
128 {
130 << "list is empty"
131 << abort(FatalError);
132 }
133 return last_;
134}
135
136
138{
139 last_ = nullptr;
140 size_ = 0;
141}
142
143
145{
146 if (this == &lst)
147 {
148 return; // Self-swap is a no-op
149 }
150
151 std::swap(last_, lst.last_);
152 std::swap(size_, lst.size_);
153}
154
155
157{
158 if (this == &lst)
159 {
160 return; // Self-assignment is a no-op
161 }
162
163 last_ = lst.last_;
164 size_ = lst.size_;
165
166 lst.clear();
167}
168
169
171(
173)
174{
175 return remove(iter.node_);
176}
177
178
179// * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
180
182(
183 SLListBase* list,
184 SLListBase::link* item
185)
186:
187 node_(item),
188 list_(list),
189 copy_()
190{
191 if (node_ != nullptr)
192 {
193 copy_ = *node_;
194 }
195}
196
197
200{
201 return node_;
202}
203
204
206{
207 return (node_ != nullptr);
208}
209
210
212{
213 if (list_)
214 {
215 if (node_ == list_->last_ || list_->last_ == nullptr)
216 {
217 node_ = nullptr;
218 }
219 else
220 {
221 node_ = copy_.next_;
222 copy_ = *node_;
223 }
224 }
225}
226
227
229{
230 node_ = iter.node_;
231 list_ = iter.list_;
232 copy_ = iter.copy_;
233}
234
235
237{
238 return node_ == iter.node_;
239}
240
241
243{
244 return node_ != iter.node_;
245}
246
247
250{
251 if (size())
252 {
253 return iterator_first<iterator>();
254 }
255
256 return end();
257}
258
259
260inline const Foam::SLListBase::iterator&
262{
263 return iterator_end<SLListBase::iterator>();
264}
265
266
269{
270 return iterator_end<SLListBase::const_iterator>();
271}
272
273
274// * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
275
277(
278 const SLListBase* list,
279 const SLListBase::link* item
280)
281:
282 node_(item),
283 list_(list)
284{}
285
286
288(
289 const SLListBase::iterator& iter
290)
291:
292 node_(iter.node_),
293 list_(iter.list_)
294{}
295
296
297inline const Foam::SLListBase::link*
299{
300 return node_;
301}
302
303
305{
306 return (node_ != nullptr);
307}
308
309
311{
312 if (list_)
313 {
314 if (node_ == list_->last_)
315 {
316 node_ = nullptr;
317 }
318 else
319 {
320 node_ = node_->next_;
321 }
322 }
323}
324
325
327(
328 const const_iterator& iter
329) const
330{
331 return node_ == iter.node_;
332}
333
334
336(
337 const const_iterator& iter
338) const
339{
340 return node_ != iter.node_;
341}
342
343
346{
347 if (size())
348 {
349 return iterator_first<const_iterator>();
350 }
351
352 return cend();
353}
354
355
356// ************************************************************************* //
Forward iterator with non-const access.
Definition: HashTable.H:720
unsigned int remove()
Remove and return the last element.
Definition: PackedListI.H:709
A primitive const node iterator.
Definition: SLListBase.H:238
void next()
Move forward through list.
Definition: SLListBaseI.H:310
bool good() const noexcept
Pointing at a valid storage node.
Definition: SLListBaseI.H:304
const link * get_node() const noexcept
The storage node.
Definition: SLListBaseI.H:298
A primitive non-const node iterator.
Definition: SLListBase.H:190
void next()
Move forward through list.
Definition: SLListBaseI.H:211
void operator=(const iterator &iter)
Copy assignment.
Definition: SLListBaseI.H:228
bool good() const noexcept
Pointing at a valid storage node.
Definition: SLListBaseI.H:205
link * get_node() const noexcept
The storage node.
Definition: SLListBaseI.H:199
Base for singly-linked lists.
Definition: SLListBase.H:62
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition: SLListBaseI.H:345
link * first()
Return first entry.
Definition: SLListBaseI.H:86
const const_iterator & cend() const
End of list for iterators.
Definition: SLListBaseI.H:268
const iterator & end()
End of list for iterators.
Definition: SLListBaseI.H:261
bool empty() const noexcept
True if the list is empty.
Definition: SLListBaseI.H:79
link * last()
Return last entry.
Definition: SLListBaseI.H:112
IteratorType iterator_first() const
Return iterator to first item or end-iterator if list is empty.
Definition: SLListBaseI.H:42
static const IteratorType & iterator_end()
Factory method to return an iterator end.
Definition: SLListBaseI.H:35
label size() const noexcept
The number of elements in list.
Definition: SLListBaseI.H:73
IteratorType iterator_last() const
Return iterator to last item or end-iterator if list is empty.
Definition: SLListBaseI.H:57
void swap(SLListBase &lst)
Swap the contents of list.
Definition: SLListBaseI.H:144
iterator begin()
Iterator to first item in list with non-const access.
Definition: SLListBaseI.H:249
void clear()
Clear the list.
Definition: SLListBaseI.H:137
A const_iterator for iterating across on values.
Definition: bitSet.H:505
friend Ostream & operator(Ostream &, const faMatrix< Type > &)
friend bool operator!=(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:106
friend bool operator==(const refineCell &rc1, const refineCell &rc2)
Definition: refineCell.H:97
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
const NullObject * nullObjectPtr
Pointer to the unique nullObject.
Definition: nullObject.C:33
errorManip< error > abort(error &err)
Definition: errorManip.H:144
const direction noexcept
Definition: Scalar.H:223
error FatalError