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