ILList.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 -------------------------------------------------------------------------------
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 "ILList.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class LListBase, class T>
35 :
36  UILList<LListBase, T>()
37 {
38  for (const auto& item : lst)
39  {
40  this->push_back(item.clone().ptr());
41  }
42 }
43 
44 
45 template<class LListBase, class T>
46 Foam::ILList<LListBase, T>::ILList(ILList<LListBase, T>&& lst)
47 :
48  UILList<LListBase, T>()
49 {
50  LListBase::transfer(lst);
51 }
52 
53 
54 template<class LListBase, class T>
55 template<class CloneArg>
57 (
58  const ILList<LListBase, T>& lst,
59  const CloneArg& cloneArg
60 )
61 :
62  UILList<LListBase, T>()
63 {
64  for (const auto& item : lst)
65  {
66  this->push_back(item.clone(cloneArg).ptr());
67  }
68 }
69 
70 
71 // * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * * //
72 
73 template<class LListBase, class T>
75 {
76  this->clear();
77 }
78 
79 
80 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
81 
82 template<class LListBase, class T>
84 {
85  if (n > this->size())
86  {
87  n = this->size();
88  }
89 
90  while (n > 0)
91  {
92  T* p = this->removeHead();
93  delete p;
94  --n;
95  }
96 }
97 
98 
99 template<class LListBase, class T>
101 {
102  this->pop_front(this->size());
104 }
105 
106 
107 template<class LListBase, class T>
109 {
110  T* p = remove(item);
111  delete p;
112  return bool(p);
113 }
114 
115 
116 template<class LListBase, class T>
118 {
119  clear();
120  LListBase::transfer(lst);
121 }
122 
123 
124 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
125 
126 template<class LListBase, class T>
128 {
129  this->clear();
130 
131  for (const auto& item : lst)
132  {
133  this->push_back(item.clone().ptr());
134  }
135 }
136 
137 
138 template<class LListBase, class T>
139 void Foam::ILList<LListBase, T>::operator=(ILList<LListBase, T>&& lst)
140 {
141  clear();
142  LListBase::transfer(lst);
143 }
144 
145 
146 // ************************************************************************* //
Template class for intrusive linked lists.
Definition: ILList.H:45
Template class for intrusive linked lists.
Definition: UILList.H:47
void transfer(ILList< LListBase, T > &lst)
Transfer the contents of the argument into this List and annul the argument list. ...
Definition: ILList.C:110
void pop_front(label n=1)
Remove first element(s) from the list (deletes pointers)
Definition: ILList.C:76
void clear()
Clear the contents of the list.
Definition: ILList.C:93
patchWriters clear()
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const volScalarField & T
bool erase(T *item)
Remove the specified element from the list and delete it.
Definition: ILList.C:101
ILList()=default
Default construct.
label n
volScalarField & p
~ILList()
Destructor. Calls clear()
Definition: ILList.C:67
void operator=(const ILList< LListBase, T > &lst)
Copy assignment using the &#39;clone()&#39; method for each element.
Definition: ILList.C:120