LPtrList.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-2023 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 "LPtrList.H"
27 
28 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
29 
30 template<class LListBase, class T>
31 Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
32 :
33  ULPtrList<LListBase, T>()
34 {
35  for
36  (
37  typename ULPtrList<LListBase, T>::const_iterator iter = lst.begin();
38  iter != lst.end();
39  ++iter
40  )
41  {
42  this->append(iter().clone().ptr());
43  }
44 }
45 
46 
47 template<class LListBase, class T>
48 Foam::LPtrList<LListBase, T>::LPtrList(LPtrList<LListBase, T>&& lst)
49 :
50  ULPtrList<LListBase, T>()
51 {
52  transfer(lst);
53 }
54 
55 
56 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
57 
58 template<class LListBase, class T>
60 {
61  this->clear();
62 }
63 
64 
65 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
66 
67 template<class LListBase, class T>
69 {
70  T* tPtr;
71  if ((tPtr = this->removeHead()))
72  {
73  delete tPtr;
74  return true;
75  }
76  else
77  {
78  return false;
79  }
80 }
81 
82 
83 template<class LListBase, class T>
85 {
86  const label oldSize = this->size();
87  for (label i=0; i<oldSize; ++i)
88  {
89  eraseHead();
90  }
91 
93 }
94 
95 
96 template<class LListBase, class T>
98 {
99  clear();
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
105 
106 template<class LListBase, class T>
108 {
109  clear();
110 
111  for
112  (
113  typename ULPtrList<LListBase, T>::const_iterator iter = lst.begin();
114  iter != lst.end();
115  ++iter
116  )
117  {
118  this->append(iter().clone().ptr());
119  }
120 }
121 
122 
123 template<class LListBase, class T>
125 {
126  transfer(lst);
127 }
128 
129 
130 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
131 
132 #include "LPtrListIO.C"
133 
134 
135 // ************************************************************************* //
const iterator & end()
Definition: LList.H:286
void append(const T * &a)
Add at tail of list.
Definition: LList.H:172
void clear()
Delete contents of list.
Definition: LList.C:73
iterator begin()
Definition: LList.H:281
void transfer(LList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: LList.C:86
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:65
LPtrList()
Null construct.
Definition: LPtrList.H:78
void transfer(LPtrList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: LPtrList.C:97
bool eraseHead()
Remove the head element from the list and delete the pointer.
Definition: LPtrList.C:68
void operator=(const LPtrList< LListBase, T > &)
Assignment operator.
Definition: LPtrList.C:107
void clear()
Clear the contents of the list.
Definition: LPtrList.C:84
~LPtrList()
Destructor.
Definition: LPtrList.C:59
An STL-conforming const_iterator.
Definition: ULPtrList.H:187
friend class const_iterator
Definition: ULPtrList.H:74
tUEqn clear()
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:59
T clone(const T &t)
Definition: List.H:55
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)