Loading...
Searching...
No Matches
PtrListDetailI.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-2023 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// * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * * //
29
30template<class T>
32:
33 List<T*>()
34{}
35
36
37template<class T>
39:
40 List<T*>(len, static_cast<T*>(nullptr))
41{}
42
43
44template<class T>
46(
47 const UList<T*>& list
49:
50 List<T*>(list)
51{}
52
53
54template<class T>
56(
57 const PtrListDetail<T>& list
59:
60 List<T*>(static_cast<const List<T*>&>(list))
61{}
62
63
64template<class T>
66(
67 PtrListDetail<T>&& list
69:
70 List<T*>(std::move(static_cast<List<T*>&>(list)))
71{}
72
73
74template<class T>
76(
77 PtrListDetail<T>& list,
78 bool reuse
79)
80:
81 List<T*>(static_cast<List<T*>&>(list), reuse)
82{}
83
84
85// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
86
87template<class T>
88inline const T* Foam::Detail::PtrListDetail<T>::get(const label i) const
89{
90 return (i >= 0 && i < this->size()) ? (*this)[i] : nullptr;
91}
92
93
94template<class T>
96{
97 return (i >= 0 && i < this->size()) ? (*this)[i] : nullptr;
98}
99
100
101template<class T>
104 const label n
105) noexcept
106{
108}
109
110
111template<class T>
112inline void Foam::Detail::PtrListDetail<T>::resize(const label newLen)
113{
114 if (newLen <= 0)
115 {
117 }
118 else if (newLen != List<T*>::size())
119 {
120 // Truncate or extend. Any new elements are initialized to nullptr.
121 List<T*>::resize(newLen, static_cast<T*>(nullptr));
122 }
123}
124
125
126template<class T>
127inline void Foam::Detail::PtrListDetail<T>::resize_null(const label newLen)
128{
129 if (newLen <= 0)
130 {
132 }
133 else
134 {
136 List<T*>::operator=(static_cast<T*>(nullptr));
137 }
138}
139
140
141template<class T>
143{
144 const label idx = this->find_first_not();
145
146 if (idx >= 0)
147 {
149 << "Element " << idx << " is null" << nl
150 << abort(FatalError);
152}
153
154
155// * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
156
157template<class T>
159(
160 const PtrListDetail<T>& list
162{
163 List<T*>::operator=(list); // shallow copy
164}
165
166
167template<class T>
169(
170 PtrListDetail<T>&& list
172{
173 List<T*>::transfer(list);
174}
175
177template<class T>
178inline void Foam::Detail::PtrListDetail<T>::operator=(std::nullptr_t)
179{
180 List<T*>::operator=(static_cast<T*>(nullptr));
182
183
184// ************************************************************************* //
label n
A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementati...
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).
const T * get(const label i) const
Return const pointer to element or nullptr for out-of-range access.
void resize_null(const label newLen)
Set the list to the given size and set all entries to nullptr.
void checkNonNull() const
FatalError if any null exists in the list.
constexpr PtrListDetail() noexcept
Default construct.
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
void resize(const label newLen)
Reset size of list.
void transfer(List< T > &list)
Transfer the contents of the argument List into this list and annul the argument list.
Definition List.C:347
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
Definition ListI.H:171
void operator=(const UList< T > &list)
Assignment to UList operator. Takes linear time.
Definition List.C:381
void resize(const label len)
Adjust allocated size of list.
Definition ListI.H:153
void clear()
Clear the list, i.e. set size to zero.
Definition ListI.H:133
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:89
UList(const UList< T > &) noexcept=default
Copy construct, shallow copy.
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
Definition UListI.H:517
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition error.H:600
errorManip< error > abort(error &err)
Definition errorManip.H:139
const direction noexcept
Definition scalarImpl.H:265
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
constexpr char nl
The newline '\n' character (0x0a).
Definition Ostream.H:50