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-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
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);
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 the count of non-nullptr entries
93 label count() const;
94
95 //- Locate the first null entry, -1 if there are none (or empty list)
96 label findNull() const;
97
98 //- FatalError if any null exists in the list
99 inline void checkNonNull() const;
100
101 //- Assign all pointers to nullptr, without deleting.
102 void setNull();
103
104 //- Delete the allocated entries, but retain the list size.
105 void free();
106
107 //- Make a copy by cloning each of the list pointers.
108 template<class... Args>
109 PtrListDetail<T> clone(Args&&... args) const;
110
111 //- Reset size of list.
112 // New entries are initialized to nullptr.
113 inline void resize(const label newLen);
114
115 //- Set addressed size to be inconsistent with allocated storage.
116 // Use with care
117 inline void setAddressableSize(const label n) noexcept;
118
119 //- Write output, optionally silently trimming nullptrs
120 Ostream& write(Ostream& os, const bool trimNull=false) const;
121
122
123 // Member Operators
124
125 //- Copy assignment (shallow copies addresses)
126 inline void operator=(const PtrListDetail<T>& list);
127
128 //- Move assignment
129 inline void operator=(PtrListDetail<T>&& list);
130
131
132 // Housekeeping
133
134 // Just use resize().
135 void setSize(const label) = delete;
136 void setSize(const label, const T&) = delete;
137 void setSize(const label, const T*) = delete;
138
139 // Too fragile or dangerous
140 void resize_nocopy(const label) = delete;
141};
142
143// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
144
145} // End namespace Detail
146} // End namespace Foam
147
148// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
149
150#include "PtrListDetailI.H"
151
152// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
153
154#ifdef NoRepository
155 #include "PtrListDetail.C"
156 #include "PtrListDetailIO.C"
157#endif
158
159// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
160
161
162#endif
163
164// ************************************************************************* //
label n
A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementati...
Definition: PtrListDetail.H:64
void setSize(const label)=delete
void setSize(const label, const T *)=delete
label findNull() const
Locate the first null entry, -1 if there are none (or empty list)
Definition: PtrListDetail.C:51
void operator=(const PtrListDetail< T > &list)
Copy assignment (shallow copies addresses)
void resize_nocopy(const label)=delete
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
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 count() const
Return the count of non-nullptr entries.
Definition: PtrListDetail.C:34
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
void resize(const label newLen)
Reset size of list.
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
autoPtr< List< T * > > clone() const
Clone.
Definition: ListI.H:100
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
Definition: Ostream.H:62
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
const volScalarField & T
OBJstream os(runTime.globalPath()/outputName)
Namespace for OpenFOAM.
runTime write()
Foam::argList args(argc, argv)