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
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 --size_;
80
81 if (last_ == nullptr)
82 {
84 << "remove from empty list"
85 << abort(FatalError);
86 }
87
88 SLListBase::link *ret = last_->next_;
89
90 if (ret == last_)
91 {
92 last_ = nullptr;
93 }
94 else
95 {
96 last_->next_ = ret->next_;
97 }
98
99 return ret;
100}
101
102
104{
105 SLListBase::iterator iter = begin();
106 SLListBase::link *prev = iter.get_node();
107
108 if (item == prev)
109 {
110 return removeHead();
111 }
112
113 for (iter.next(); iter != end(); iter.next())
114 {
115 SLListBase::link *p = iter.get_node();
116
117 if (p == item)
118 {
119 --size_;
120
121 prev->next_ = p->next_;
122
123 if (p == last_)
124 {
125 last_ = prev;
126 }
127
128 return item;
129 }
130
131 prev = p;
132 }
133
134 // Did not remove
135 return nullptr;
136}
137
138
139// ************************************************************************* //
unsigned int remove()
Remove and return the last element.
Definition: PackedListI.H:709
A primitive non-const node iterator.
Definition: SLListBase.H:190
void next()
Move forward through list.
Definition: SLListBaseI.H:211
link * get_node() const noexcept
The storage node.
Definition: SLListBaseI.H:199
link * removeHead()
Remove and return first entry.
Definition: SLListBase.C:77
void prepend(link *item)
Add at front of list.
Definition: SLListBase.C:34
bool append() const noexcept
True if output format uses an append mode.
volScalarField & p
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
errorManip< error > abort(error &err)
Definition: errorManip.H:144
error FatalError