Loading...
Searching...
No Matches
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-------------------------------------------------------------------------------
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 "LList.H"
30
31// * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32
33template<class LListBase, class T>
35:
36 LListBase()
37{
38 for (const T& val : lst)
39 {
40 this->push_back(val);
41 }
42}
43
44
45template<class LListBase, class T>
46Foam::LList<LListBase, T>::LList(LList<LListBase, T>&& lst)
47:
48 LListBase()
49{
50 LListBase::transfer(lst);
51}
52
53
54template<class LListBase, class T>
55Foam::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
68template<class LListBase, class T>
70{
71 this->clear();
72}
73
74
75// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
76
77template<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
94template<class LListBase, class T>
97 this->pop_front(this->size());
98 LListBase::clear();
99}
100
101
102template<class LListBase, class T>
104{
105 clear();
106 LListBase::transfer(lst);
107}
108
109
110// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
111
112template<class LListBase, class T>
114{
115 this->clear();
116
117 for (const T& val : lst)
119 this->push_back(val);
120 }
121}
122
123
124template<class LListBase, class T>
125void Foam::LList<LListBase, T>::operator=(LList<LListBase, T>&& lst)
126{
127 this->clear();
128
129 LListBase::transfer(lst);
130}
131
132
133template<class LListBase, class T>
134void 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// ************************************************************************* //
label n
Template class for non-intrusive linked lists.
Definition LList.H:71
void pop_front(label n=1)
Remove first element(s) from the list (deletes pointers).
Definition LList.C:71
LList()=default
Default construct.
void transfer(LList< LListBase, T > &lst)
Transfer the contents of the argument into this List and annul the argument list.
Definition LList.C:96
void push_back(const T &elem)
Add copy at back of list.
Definition LList.H:299
void clear()
Delete contents of list.
Definition LList.C:88
~LList()
Destructor. Calls clear().
Definition LList.C:62
void operator=(const LList< LListBase, T > &lst)
Copy assignment.
Definition LList.C:106
volScalarField & p
surface1 clear()
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)