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 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
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 // ************************************************************************* //
p
volScalarField & p
Definition: createFieldRefs.H:8
stdFoam::begin
constexpr auto begin(C &c) -> decltype(c.begin())
Return iterator to the beginning of the container c.
Definition: stdFoam.H:97
Foam::SLListBase::remove
link * remove(link *item)
Definition: SLListBase.C:103
Foam::SLListBase::append
void append(link *item)
Add at tail of list.
Definition: SLListBase.C:56
Foam::SLListBase::iterator::get_node
link * get_node() const
The storage node.
Definition: SLListBaseI.H:199
error.H
Foam::SLListBase::removeHead
link * removeHead()
Remove and return head.
Definition: SLListBase.C:77
Foam::SLListBase::iterator::next
void next()
Move forward through list.
Definition: SLListBaseI.H:211
Foam::FatalError
error FatalError
stdFoam::end
constexpr auto end(C &c) -> decltype(c.end())
Return iterator to the end of the container c.
Definition: stdFoam.H:121
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::SLListBase::iterator
A primitive non-const node iterator.
Definition: SLListBase.H:189
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:453
SLListBase.H
Foam::SLListBase::insert
void insert(link *item)
Add at head of list.
Definition: SLListBase.C:34