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 | Copyright (C) 2011 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  LList<LListBase, T*>()
34 {
35  for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
36  {
37  this->append(iter().clone().ptr());
38  }
39 }
40 
41 
42 // * * * * * * * * * * * * * * * * Destructor * * * * * * * * * * * * * * * //
43 
44 template<class LListBase, class T>
46 {
47  this->clear();
48 }
49 
50 
51 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
52 
53 template<class LListBase, class T>
55 {
56  T* tPtr;
57  if ((tPtr = this->removeHead()))
58  {
59  delete tPtr;
60  return true;
61  }
62  else
63  {
64  return false;
65  }
66 }
67 
68 
69 template<class LListBase, class T>
71 {
72  const label oldSize = this->size();
73  for (label i=0; i<oldSize; ++i)
74  {
75  eraseHead();
76  }
77 
79 }
80 
81 
82 template<class LListBase, class T>
84 {
85  clear();
87 }
88 
89 
90 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
91 
92 template<class LListBase, class T>
94 {
95  clear();
96 
97  for (const_iterator iter = lst.begin(); iter != lst.end(); ++iter)
98  {
99  this->append(iter().clone().ptr());
100  }
101 }
102 
103 
104 // * * * * * * * * * * * * * * * Friend Operators * * * * * * * * * * * * * //
105 
106 #include "LPtrListIO.C"
107 
108 
109 // ************************************************************************* //
Template class for non-intrusive linked PtrLists.
Definition: LPtrList.H:47
An STL-conforming const_iterator.
Definition: LPtrList.H:215
const iterator & end()
Definition: LList.H:273
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void clear()
Clear the contents of the list.
Definition: LPtrList.C:70
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
const volScalarField & T
Definition: createFields.H:25
friend class const_iterator
Definition: LPtrList.H:87
T * removeHead()
Remove and return head.
Definition: LList.H:172
void transfer(LPtrList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: LPtrList.C:83
void operator=(const LPtrList< LListBase, T > &)
Assign copy.
Definition: LPtrList.C:93
bool eraseHead()
Remove the head element from the list and delete the pointer.
Definition: LPtrList.C:54
void append(const T * &a)
Add at tail of list.
Definition: LList.H:166
LPtrList()
Null construct.
Definition: LPtrList.H:94
~LPtrList()
Destructor.
Definition: LPtrList.C:45
void transfer(LList< LListBase, T > &)
Transfer the contents of the argument into this List.
Definition: LList.C:66
void clear()
Delete contents of list.
Definition: LList.C:53