Loading...
Searching...
No Matches
SLListBase.C
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-2015 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 "SLListBase.H"
30#include "error.H"
31
32// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
33
35{
36 if (!item)
37 {
38 return;
39 }
40
41 ++size_;
42
43 if (last_)
44 {
45 item->next_ = last_->next_;
46 }
47 else
48 {
49 last_ = item;
50 }
51
52 last_->next_ = item;
53}
54
55
56void Foam::SLListBase::push_back(SLListBase::link* item)
57{
58 if (!item)
59 {
60 return;
61 }
62
63 ++size_;
64
65 if (last_)
66 {
67 item->next_ = last_->next_;
68 last_ = last_->next_ = item;
69 }
70 else
71 {
72 last_ = item->next_ = item;
73 }
74}
75
76
78{
79 if (last_ == nullptr)
80 {
82 << "remove from empty list"
83 << abort(FatalError);
84
85 // return nullptr;
86 }
87
88 --size_;
89
90 SLListBase::link *ret = last_->next_;
91
92 if (ret == last_)
93 {
94 last_ = nullptr;
95 }
96 else
97 {
98 last_->next_ = ret->next_;
99 }
100
101 ret->deregister();
102 return ret;
103}
104
105
107{
108 SLListBase::iterator iter = begin();
109 SLListBase::link *prev = iter.get_node();
110
111 if (item == prev)
112 {
113 return removeHead();
114 }
115
116 for (iter.next(); iter != end(); iter.next())
117 {
118 SLListBase::link *p = iter.get_node();
119
120 if (p == item)
121 {
122 --size_;
123
124 prev->next_ = p->next_;
125
126 if (p == last_)
127 {
128 last_ = prev;
129 }
130
131 item->deregister();
132 return item;
133 }
134
135 prev = p;
136 }
137
138 // Did not remove
139 return nullptr;
140}
141
142
143// ************************************************************************* //
A primitive non-const node iterator.
Definition SLListBase.H:249
void next()
Move forward through list.
link * get_node() const noexcept
The storage node.
link * remove(link *item)
Definition SLListBase.C:99
const iterator & end()
End of list for iterators.
void push_back(link *item)
Add at back of list.
Definition SLListBase.C:49
link * removeHead()
Remove and return first entry.
Definition SLListBase.C:70
friend class iterator
Definition SLListBase.H:141
iterator begin()
Iterator to first item in list with non-const access.
void push_front(link *item)
Add at front of list.
Definition SLListBase.C:27
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
const char * end
Definition SVGTools.H:223
errorManip< error > abort(error &err)
Definition errorManip.H:139
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...