PtrListDetail.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) 2018-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26\*---------------------------------------------------------------------------*/
27
28#include "PtrListDetail.H"
29#include <utility>
30
31// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32
33template<class T>
35{
36 label ngood = 0;
37
38 for (const T* ptr : *this)
39 {
40 if (ptr)
41 {
42 ++ngood;
43 }
44 }
45
46 return ngood;
47}
48
49
50template<class T>
52{
53 // Same as List<T*>::find(nullptr);
54 // except perhaps without pointer ambiguities...
55
56 label idx = 0;
57
58 for (const T* ptr : *this)
59 {
60 if (!ptr)
61 {
62 return idx;
63 }
64
65 ++idx;
66 }
67
68 return -1;
69}
70
71
72template<class T>
74{
75 List<T*>& ptrs = *this;
76 const label len = ptrs.size();
77
78 for (label i=0; i<len; ++i)
79 {
80 ptrs[i] = nullptr;
81 }
82}
83
84
85template<class T>
87{
88 List<T*>& ptrs = *this;
89 const label len = ptrs.size();
90
91 for (label i=0; i<len; ++i)
92 {
93 T* ptr = ptrs[i];
94
95 if (ptr)
96 {
97 delete ptr;
98 }
99
100 ptrs[i] = nullptr;
102}
103
105template<class T>
106template<class... Args>
109{
110 const List<T*>& ptrs = *this;
111 const label len = ptrs.size();
112
113 PtrListDetail<T> cloned(len);
114
115 for (label i=0; i<len; ++i)
116 {
117 const T* ptr = ptrs[i];
118
119 if (ptr)
120 {
121 cloned[i] = ptr->clone(std::forward<Args>(args)...).ptr();
122 }
123 }
124
125 return cloned;
126}
127
128
129// ************************************************************************* //
A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementati...
Definition: PtrListDetail.H:64
label findNull() const
Locate the first null entry, -1 if there are none (or empty list)
Definition: PtrListDetail.C:51
void setNull()
Assign all pointers to nullptr, without deleting.
Definition: PtrListDetail.C:73
void free()
Delete the allocated entries, but retain the list size.
Definition: PtrListDetail.C:86
PtrListDetail< T > clone(Args &&... args) const
Make a copy by cloning each of the list pointers.
label count() const
Return the count of non-nullptr entries.
Definition: PtrListDetail.C:34
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:77
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
virtual tmp< fvPatchScalarField > clone() const
Construct and return a clone.
const volScalarField & T
Foam::argList args(argc, argv)