Loading...
Searching...
No Matches
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\*---------------------------------------------------------------------------*/
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 }
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
75{
76 if (!size_)
77 {
79 << "list is empty"
81 }
82 return last_->next_;
83}
84
85
86inline const Foam::SLListBase::link*
88{
89 if (!size_)
90 {
92 << "list is empty"
94 }
95 return last_->next_;
96}
97
98
101{
102 if (!size_)
103 {
105 << "list is empty"
107 }
108 return last_;
109}
110
111
112inline const Foam::SLListBase::link*
114{
115 if (!size_)
116 {
118 << "list is empty"
119 << abort(FatalError);
120 }
121 return last_;
122}
123
124
126{
127 last_ = nullptr;
128 size_ = 0;
129}
130
131
132inline void Foam::SLListBase::swap(SLListBase& lst)
133{
134 if (this == &lst)
135 {
136 return; // Self-swap is a no-op
138
139 std::swap(last_, lst.last_);
140 std::swap(size_, lst.size_);
141}
142
143
144inline void Foam::SLListBase::transfer(SLListBase& lst)
145{
146 if (this == &lst)
147 {
148 return; // Self-assignment is a no-op
149 }
150
151 last_ = lst.last_;
152 size_ = lst.size_;
153
154 lst.clear();
155}
156
157
159(
161)
163 return remove(iter.node_);
164}
165
166
167// * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * * //
168
170(
171 SLListBase* list,
172 SLListBase::link* item
173)
174:
175 node_(item),
176 list_(list),
177 copy_()
178{
179 if (node_ != nullptr)
181 copy_ = *node_;
182 }
183}
184
185
190}
191
194{
195 return (node_ != nullptr);
196}
197
198
200{
201 if (list_)
202 {
203 if (node_ == list_->last_ || list_->last_ == nullptr)
204 {
205 node_ = nullptr;
206 }
207 else
208 {
209 node_ = copy_.next_;
210 copy_ = *node_;
211 }
212 }
213}
214
215
216inline void Foam::SLListBase::iterator::operator=(const iterator& iter)
218 node_ = iter.node_;
219 list_ = iter.list_;
220 copy_ = iter.copy_;
221}
222
224inline bool Foam::SLListBase::iterator::operator==(const iterator& iter) const
225{
226 return node_ == iter.node_;
227}
228
229
231{
232 return node_ != iter.node_;
233}
234
235
238{
239 if (size())
240 {
243
244 return end();
245}
246
247
248inline const Foam::SLListBase::iterator&
253
254
259}
260
261
262// * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * * //
263
265(
266 const SLListBase* list,
267 const SLListBase::link* item
269:
270 node_(item),
271 list_(list)
272{}
273
274
276(
277 const SLListBase::iterator& iter
278)
280 node_(iter.node_),
281 list_(iter.list_)
282{}
283
284
287{
288 return node_;
289}
290
293{
294 return (node_ != nullptr);
295}
296
297
299{
300 if (list_)
301 {
302 if (node_ == list_->last_)
303 {
304 node_ = nullptr;
305 }
306 else
308 node_ = node_->next_;
309 }
310 }
311}
312
313
314inline bool Foam::SLListBase::const_iterator::operator==
315(
316 const const_iterator& iter
317) const
318{
319 return node_ == iter.node_;
320}
321
322
323inline bool Foam::SLListBase::const_iterator::operator!=
324(
325 const const_iterator& iter
326) const
327{
328 return node_ != iter.node_;
329}
330
331
334{
335 if (size())
336 {
338 }
339
340 return cend();
341}
342
343
344// ************************************************************************* //
A primitive const node iterator.
Definition SLListBase.H:321
void next()
Move forward through list.
bool good() const noexcept
Pointing at a valid storage node.
const_iterator(const const_iterator &)=default
Copy construct.
const link * get_node() const noexcept
The storage node.
A primitive non-const node iterator.
Definition SLListBase.H:249
void next()
Move forward through list.
bool operator!=(const iterator &iter) const
void operator=(const iterator &iter)
Copy assignment.
bool good() const noexcept
Pointing at a valid storage node.
bool operator==(const iterator &iter) const
iterator(const iterator &)=default
Copy construct.
link * get_node() const noexcept
The storage node.
Base for singly-linked lists.
Definition SLListBase.H:58
link * remove(link *item)
Definition SLListBase.C:99
const_iterator cbegin() const
Iterator to first item in list with const access.
const const_iterator & cend() const
End of list for iterators.
void transfer(SLListBase &lst)
Transfer the contents of the argument into this list and annul the argument list.
link * front()
Return first entry.
Definition SLListBaseI.H:67
const iterator & end()
End of list for iterators.
IteratorType iterator_first() const
Return iterator to first item or end-iterator if list is empty.
Definition SLListBaseI.H:35
friend class iterator
Definition SLListBase.H:141
static const IteratorType & iterator_end()
Factory method to return an iterator end.
Definition SLListBaseI.H:28
IteratorType iterator_last() const
Return iterator to last item or end-iterator if list is empty.
Definition SLListBaseI.H:50
void swap(SLListBase &lst)
Swap the contents of list.
iterator begin()
Iterator to first item in list with non-const access.
label size() const noexcept
The number of elements in list.
Definition SLListBase.H:180
void clear()
Clear the list.
link * back()
Return last entry.
Definition SLListBaseI.H:93
SLListBase()=default
Default construct.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const NullObject * nullObjectPtr
Pointer to the unique nullObject.
Definition nullObject.C:29
errorManip< error > abort(error &err)
Definition errorManip.H:139
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...