Loading...
Searching...
No Matches
PtrListDetail.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) 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
26Class
27 Foam::Detail::PtrListDetail
28
29Description
30 A rudimentary list of pointers used for PtrList, UPtrList, etc.
31 This class is considered implementation detail and should not normally
32 be used other than by OpenFOAM container classes.
33
34 It stores a list of pointers, but makes leaves memory management
35 to the caller or sub-class.
36 The free() method can be used explicitly as required.
37
38SourceFiles
39 PtrListDetail.C
40 PtrListDetailI.H
41 PtrListDetailIO.C
42
43\*---------------------------------------------------------------------------*/
44
45#ifndef Foam_PtrListDetail_H
46#define Foam_PtrListDetail_H
47
48#include "List.H"
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52namespace Foam
53{
54namespace Detail
55{
56
57/*---------------------------------------------------------------------------*\
58 Class Detail::PtrListDetail Declaration
59\*---------------------------------------------------------------------------*/
60
61template<class T>
62class PtrListDetail
63:
64 public List<T*>
65{
66public:
67
68 // Constructors
69
70 //- Default construct
71 inline constexpr PtrListDetail() noexcept;
72
73 //- Construct with specified size, each element initialized to nullptr
74 inline explicit PtrListDetail(const label len);
75
76 //- Copy a list of pointers.
77 // The caller is responsible for memory management.
78 inline explicit PtrListDetail(const UList<T*>& list);
79
80 //- Copy construct (shallow copies addresses)
81 inline PtrListDetail(const PtrListDetail<T>& list);
82
83 //- Move construct
84 inline PtrListDetail(PtrListDetail<T>&& list) noexcept;
85
86 //- Copy or move (reuse) construct as specified
87 inline PtrListDetail(PtrListDetail<T>& list, bool reuse);
88
89
90 // Member Functions
91
92 //- Return const pointer to element or nullptr for out-of-range access.
93 inline const T* get(const label i) const;
94
95 //- Return pointer to element or nullptr for out-of-range access.
96 inline T* get(const label i);
97
98 //- The number of non-nullptr entries in the list
99 label count_nonnull() const noexcept;
100
101 //- FatalError if any null exists in the list
102 inline void checkNonNull() const;
103
104 //- Locate the first entry that is non-null.
105 // \return the location or -1 if there are no bits set.
106 //
107 // \note Method name as per bitSet
108 label find_first() const;
109
110 //- Locate the first entry that is null, -1 if there are none (or empty list)
111 // \return the location or -1 if the list is empty or all entries
112 // are non-null.
113 //
114 // \note Method name as per bitSet, symmetry with find_first()
115 label find_first_not() const;
116
117 //- Locate the next non-null entry, starting one beyond the specified
118 //- position
119 // \return the location or -1 if remaining entries are null.
120 //
121 // \note Method name as per bitSet
122 label find_next(label pos) const;
123
124 //- Locate the next null entry, starting one beyond the specified
125 //- position
126 // \return the location or -1 if remaining entries are non-null.
127 //
128 // \note Method name as per bitSet
129 label find_next_not(label pos) const;
130
131 //- Delete allocated entries and reassign to nullptr.
132 //- Does not affect the list size.
133 void free();
134
135 //- Make a copy by cloning each of the list pointers.
136 template<class... Args>
137 PtrListDetail<T> clone(Args&&... args) const;
138
139 //- Reset size of list.
140 // New entries are initialized to nullptr.
141 inline void resize(const label newLen);
142
143 //- Set the list to the given size and set all entries to nullptr.
144 inline void resize_null(const label newLen);
145
146 //- Set addressed size to be inconsistent with allocated storage.
147 // Use with care
148 inline void setAddressableSize(const label n) noexcept;
149
150 //- Write pointer values to Ostream (debugging only).
151 // Optionally allow addressing beyond the regular range
152 Ostream& printAddresses(Ostream& os, label maxLen = -1) const;
153
154 //- Write output, optionally silently trimming nullptrs
155 Ostream& write(Ostream& os, const bool trimNull=false) const;
156
157
158 // Member Operators
159
160 //- Copy assignment (shallow copies addresses)
161 inline void operator=(const PtrListDetail<T>& list);
162
163 //- Move assignment
164 inline void operator=(PtrListDetail<T>&& list);
165
166 //- Assign all entries to nullptr (without deleting)
167 inline void operator=(std::nullptr_t);
168
170 // Housekeeping
171
172 // Just use resize().
173 void setSize(const label) = delete;
174 void setSize(const label, const T&) = delete;
175 void setSize(const label, const T*) = delete;
176
177 // Too fragile or dangerous
178 void resize_nocopy(const label) = delete;
179};
180
181
182// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
183
184} // End namespace Detail
185} // End namespace Foam
186
187// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
188
189#include "PtrListDetailI.H"
190
191// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
192
193#ifdef NoRepository
194 #include "PtrListDetail.C"
195 #include "PtrListDetailIO.C"
196#endif
197
198// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
199
200
201#endif
202
203// ************************************************************************* //
label n
void setSize(const label)=delete
label find_next_not(label pos) const
Locate the next null entry, starting one beyond the specified position.
void setSize(const label, const T *)=delete
void operator=(const PtrListDetail< T > &list)
Copy assignment (shallow copies addresses).
label find_first_not() const
Locate the first entry that is null, -1 if there are none (or empty list).
void resize_nocopy(const label)=delete
const T * get(const label i) const
Return const pointer to element or nullptr for out-of-range access.
Ostream & printAddresses(Ostream &os, label maxLen=-1) const
Write pointer values to Ostream (debugging only).
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.
void resize_null(const label newLen)
Set the list to the given size and set all entries to nullptr.
void setSize(const label, const T &)=delete
PtrListDetail< T > clone(Args &&... args) const
Make a copy by cloning each of the list pointers.
void checkNonNull() const
FatalError if any null exists in the list.
constexpr PtrListDetail() noexcept
Default construct.
label find_next(label pos) const
Locate the next non-null entry, starting one beyond the specified position.
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
void resize(const label newLen)
Reset size of list.
label find_first() const
Locate the first entry that is non-null.
autoPtr< List< T > > clone() const
Definition ListI.H:124
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition Ostream.H:59
UList(const UList< T > &) noexcept=default
Copy construct, shallow copy.
OBJstream os(runTime.globalPath()/outputName)
Implementation details for various OpenFOAM classes.
Definition zoneSubSet.C:30
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
runTime write()
Foam::argList args(argc, argv)