LPtrList.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 OpenFOAM Foundation
9  Copyright (C) 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 "LPtrList.H"
30 
31 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class LListBase, class T>
34 Foam::LPtrList<LListBase, T>::LPtrList(const LPtrList<LListBase, T>& lst)
35 :
36  LList<LListBase, T*>()
37 {
38  for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
39  {
40  this->push_back((*iter).clone().ptr());
41  }
42 }
43 
44 
45 template<class LListBase, class T>
46 Foam::LPtrList<LListBase, T>::LPtrList(LPtrList<LListBase, T>&& lst)
47 :
48  LList<LListBase, T*>()
49 {
51 }
52 
53 
54 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
55 
56 template<class LListBase, class T>
58 {
59  this->clear();
60 }
61 
62 
63 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
64 
65 template<class LListBase, class T>
67 {
68  if (n > this->size())
69  {
70  n = this->size();
71  }
72 
73  while (n > 0)
74  {
75  T* p = this->removeHead();
76  delete p;
77  --n;
78  }
79 }
80 
81 
82 template<class LListBase, class T>
84 {
85  this->pop_front(this->size());
87 }
88 
89 
90 template<class LListBase, class T>
92 {
93  clear();
95 }
96 
97 
98 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
99 
100 template<class LListBase, class T>
102 {
103  clear();
104 
105  for (auto iter = lst.cbegin(); iter != lst.cend(); ++iter)
106  {
107  this->push_back((*iter).clone().ptr());
108  }
109 }
110 
111 
112 template<class LListBase, class T>
113 void Foam::LPtrList<LListBase, T>::operator=(LPtrList<LListBase, T>&& lst)
114 {
115  transfer(lst);
116 }
117 
118 
119 // ************************************************************************* //
const_iterator cbegin() const
Iterator to first item in list with const access.
Definition: LPtrList.H:431
void operator=(const LPtrList< LListBase, T > &lst)
Copy assign by using &#39;clone()&#39; for each element.
Definition: LPtrList.C:94
~LPtrList()
Destructor. Calls clear()
Definition: LPtrList.C:50
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:46
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
patchWriters clear()
void clear()
Delete contents of list.
Definition: LList.C:88
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
const volScalarField & T
const const_iterator & cend() const
End of list for forward iterators.
Definition: LPtrList.H:480
void clear()
Clear the contents of the list.
Definition: LPtrList.C:76
LPtrList()=default
Default construct.
label n
void transfer(LPtrList< LListBase, T > &lst)
Transfer the contents of the argument into this List and annul the argument list. ...
Definition: LPtrList.C:84
volScalarField & p
void pop_front(label n=1)
Remove first element(s) from the list (deletes pointers)
Definition: LPtrList.C:59