PtrListI.H
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) 2018-2019 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 "autoPtr.H"
30 #include "tmp.H"
31 
32 // * * * * * * * * * * * * Protected Member Functions * * * * * * * * * * * //
33 
34 template<class T>
36 {
37  (this->ptrs_).free(); // free old pointers
38 }
39 
40 
41 // * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
42 
43 template<class T>
44 inline constexpr Foam::PtrList<T>::PtrList() noexcept
45 :
46  UPtrList<T>()
47 {}
48 
49 
50 template<class T>
51 inline Foam::PtrList<T>::PtrList(const label len)
52 :
53  UPtrList<T>(len)
54 {}
55 
56 
57 template<class T>
59 :
60  UPtrList<T>(list.ptrs_.clone())
61 {}
62 
63 
64 template<class T>
66 :
67  UPtrList<T>(std::move(list))
68 {}
69 
70 
71 template<class T>
73 :
74  UPtrList<T>(list.size())
75 {
76  // Take ownership of the pointer
77  forAll(list, i)
78  {
79  set(i, list[i]);
80  list[i] = nullptr;
81  }
82 }
83 
84 
85 template<class T>
86 template<class CloneArg>
88 (
89  const PtrList<T>& list,
90  const CloneArg& cloneArg
91 )
92 :
93  UPtrList<T>(list.clone(cloneArg)())
94 {}
95 
96 
97 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
98 
99 template<class T>
101 {
102  (this->ptrs_).free(); // free old pointers
104 }
105 
106 
107 template<class T>
108 inline void Foam::PtrList<T>::setSize(const label newLen)
109 {
110  this->resize(newLen);
111 }
112 
113 
114 template<class T>
115 inline void Foam::PtrList<T>::append(T* ptr)
116 {
117  UPtrList<T>::append(ptr);
118 }
119 
120 
121 template<class T>
123 {
125 }
126 
127 
128 template<class T>
130 {
131  UPtrList<T>::append(aptr.release());
132 }
133 
134 
135 template<class T>
136 inline void Foam::PtrList<T>::append(const tmp<T>& tptr)
137 {
138  UPtrList<T>::append(tptr.ptr());
139 }
140 
141 
142 template<class T>
143 inline const T* Foam::PtrList<T>::set(const label i) const
144 {
145  return UPtrList<T>::set(i);
146 }
147 
148 
149 template<class T>
150 inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, T* ptr)
151 {
152  return autoPtr<T>(UPtrList<T>::set(i, ptr));
153 }
154 
155 
156 template<class T>
158 {
159  return set(i, aptr.release());
160 }
161 
162 
163 template<class T>
164 inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, autoPtr<T>&& aptr)
165 {
166  return set(i, aptr.release());
167 }
168 
169 
170 template<class T>
171 inline Foam::autoPtr<T> Foam::PtrList<T>::set(const label i, const tmp<T>& tptr)
172 {
173  return set(i, tptr.ptr());
174 }
175 
176 
177 template<class T>
179 {
180  if (i < 0 || i >= this->size())
181  {
182  return nullptr;
183  }
184 
185  return autoPtr<T>(UPtrList<T>::set(i, nullptr));
186 }
187 
188 
189 template<class T>
191 {
192  (this->ptrs_).free(); // free old pointers
193  UPtrList<T>::transfer(list);
194 }
195 
196 
197 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
198 
199 template<class T>
201 {
202  this->transfer(list);
203 }
204 
205 
206 // ************************************************************************* //
Foam::tmp
A class for managing temporary objects.
Definition: PtrList.H:59
Foam::PtrList::operator=
void operator=(const PtrList< T > &list)
Copy assignment.
Definition: PtrList.C:133
Foam::PtrList::release
autoPtr< T > release(const label i)
Release ownership of the pointer at the given position.
Definition: PtrListI.H:178
forAll
#define forAll(list, i)
Loop across all elements in list.
Definition: stdFoam.H:296
resize
patchWriters resize(patchIds.size())
Foam::autoPtr::release
T * release() noexcept
Return pointer to the managed object and release ownership.
Definition: autoPtrI.H:100
Foam::PtrList::setSize
void setSize(const label newLen)
Same as resize()
Definition: PtrListI.H:108
Foam::PtrList::PtrList
constexpr PtrList() noexcept
Construct null.
Definition: PtrListI.H:44
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:63
Foam::PtrList
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers....
Definition: List.H:62
Foam::PtrList::append
void append(T *ptr)
Append an element to the end of the list.
Definition: PtrListI.H:115
Foam::PtrList::clone
PtrList< T > clone(Args &&... args) const
Make a copy by cloning each of the list elements.
Foam::PtrList::clear
void clear()
Clear the PtrList. Delete allocated entries and set size to zero.
Definition: PtrListI.H:100
Foam::tmp::ptr
T * ptr() const
Definition: tmpI.H:296
Foam::PtrList::set
const T * set(const label i) const
Return const pointer to element (if set) or nullptr.
Definition: PtrListI.H:143
T
const volScalarField & T
Definition: createFieldRefs.H:2
Foam::PtrList::free
void free()
Delete the allocated entries, but retain the list size.
Definition: PtrListI.H:35
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
tmp.H
clear
patchWriters clear()
Foam::UList
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:103
append
rAUs append(new volScalarField(IOobject::groupName("rAU", phase1.name()), 1.0/(U1Eqn.A()+byDt(max(phase1.residualAlpha() - alpha1, scalar(0)) *rho1))))
Foam::PtrList::transfer
void transfer(PtrList< T > &list)
Transfer into this list and annul the argument list.
Definition: PtrListI.H:190
autoPtr.H