SLListBase.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2018 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "error.H"
27 #include "SLListBase.H"
28 
29 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
30 
31 Foam::SLListBase::iterator Foam::SLListBase::endIter_
32 (
33  const_cast<SLListBase&>(static_cast<const SLListBase&>(SLListBase()))
34 );
35 
36 Foam::SLListBase::const_iterator Foam::SLListBase::endConstIter_
37 (
38  static_cast<const SLListBase&>(SLListBase()),
39  reinterpret_cast<const link*>(0)
40 );
41 
42 
43 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
44 
46 {
47  nElmts_++;
48 
49  if (last_)
50  {
51  a->next_ = last_->next_;
52  }
53  else
54  {
55  last_ = a;
56  }
57 
58  last_->next_ = a;
59 }
60 
61 
63 {
64  nElmts_++;
65 
66  if (last_)
67  {
68  a->next_ = last_->next_;
69  last_ = last_->next_ = a;
70  }
71  else
72  {
73  last_ = a->next_ = a;
74  }
75 }
76 
77 
79 {
80  nElmts_--;
81 
82  if (last_ == 0)
83  {
85  << "remove from empty list"
86  << abort(FatalError);
87  }
88 
89  SLListBase::link* f = last_->next_;
90 
91  if (f == last_)
92  {
93  last_ = 0;
94  }
95  else
96  {
97  last_->next_ = f->next_;
98  }
99 
100  return f;
101 }
102 
103 
105 {
106  SLListBase::iterator iter = begin();
107  SLListBase::link *prev = &(*iter);
108 
109  if (it == prev)
110  {
111  return removeHead();
112  }
113 
114  nElmts_--;
115 
116  for (++iter; iter != end(); ++iter)
117  {
118  SLListBase::link *p = &(*iter);
119 
120  if (p == it)
121  {
122  prev->next_ = p->next_;
123 
124  if (p == last_)
125  {
126  last_ = prev;
127  }
128 
129  return it;
130  }
131 
132  prev = p;
133  }
134 
135  return 0;
136 }
137 
138 
139 // ************************************************************************* //
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
An STL-conforming const_iterator.
Definition: SLListBase.H:215
void append(link *)
Add at tail of list.
Definition: SLListBase.C:62
errorManip< error > abort(error &err)
Definition: errorManip.H:131
void insert(link *)
Add at head of list.
Definition: SLListBase.C:45
labelList f(nPoints)
const iterator & end()
Definition: SLListBaseI.H:239
iterator begin()
Definition: SLListBaseI.H:225
link * removeHead()
Remove and return head.
Definition: SLListBase.C:78
volScalarField & p
link * remove(link *)
Definition: SLListBase.C:104
An STL-conforming iterator.
Definition: SLListBase.H:165