Loading...
Searching...
No Matches
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-2025 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
30// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
31
32template<class T>
34{
35 label n = 0;
36
37 for (const T* ptr : *this)
38 {
39 if (ptr)
40 {
41 ++n;
42 }
43 }
44
45 return n;
46}
47
48
49template<class T>
51{
52 return this->find_next(-1);
53}
54
55
56template<class T>
58{
59 return this->find_next_not(-1);
60}
61
62
63template<class T>
65{
66 const label len = this->size();
67
68 // Start search after the given position (input of -1 is also valid)
69 for (++pos; pos < len; ++pos)
70 {
71 if ((*this)[pos])
72 {
73 return pos;
74 }
75 }
76
77 return -1;
78}
79
80
81template<class T>
83{
84 const label len = this->size();
85
86 // Start search after the given position (input of -1 is also valid)
87 for (++pos; pos < len; ++pos)
88 {
89 if (!(*this)[pos])
90 {
91 return pos;
92 }
93 }
94
95 return -1;
96}
97
98
99template<class T>
101{
102 // Presume they were allocated from front to back...
103 List<T*>& ptrs = *this;
104
105 for (auto i = this->size()-1; i >= 0; --i)
106 {
107 delete ptrs[i];
108 ptrs[i] = nullptr;
110}
111
112
113template<class T>
114template<class... Args>
117{
118 const List<T*>& ptrs = *this;
119 const label len = ptrs.size();
120
121 PtrListDetail<T> cloned(len);
122
123 for (label i = 0; i < len; ++i)
124 {
125 const T* ptr = ptrs[i];
126
127 if (ptr)
128 {
129 cloned[i] = ptr->clone(std::forward<Args>(args)...).ptr();
130 }
131 }
132
133 return cloned;
134}
135
136
137// ************************************************************************* //
label n
A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementati...
label find_next_not(label pos) const
Locate the next null entry, starting one beyond the specified position.
label find_first_not() const
Locate the first entry that is null, -1 if there are none (or empty list).
void free()
Delete allocated entries and reassign to nullptr. Does not affect the list size.
label count_nonnull() const noexcept
The number of non-nullptr entries in the list.
label find_next(label pos) const
Locate the next non-null entry, starting one beyond the specified position.
label find_first() const
Locate the first entry that is non-null.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition List.H:72
autoPtr< List< T > > clone() const
Definition ListI.H:124
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
dimensionedScalar pos(const dimensionedScalar &ds)
const direction noexcept
Definition scalarImpl.H:265
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Foam::argList args(argc, argv)