Loading...
Searching...
No Matches
SubList.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2023 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::SubList
29
30Description
31 A non-owning sub-view of a List (allocated or unallocated storage).
32
33SourceFiles
34 SubListI.H
35
36\*---------------------------------------------------------------------------*/
37
38#ifndef Foam_SubList_H
39#define Foam_SubList_H
40
41#include "List.H"
42
43// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
44
45namespace Foam
46{
47
48// Forward Declarations
49template<class T, unsigned N> class FixedList;
50template<class T> class SubList;
51
52// Common list types
56
57
58/*---------------------------------------------------------------------------*\
59 Class SubList Declaration
60\*---------------------------------------------------------------------------*/
61
62template<class T>
63class SubList
64:
65 public UList<T>
66{
67public:
68
69 // Static Functions
71 //- Return a null SubList (reference to a nullObject).
72 //- Behaves like an empty SubList.
73 static const SubList<T>& null() noexcept
74 {
76 }
77
78
79 // Generated Methods
80
81 //- Default construct, zero-sized and nullptr
82 SubList() noexcept = default;
83
84 //- Copy construct, shallow copy
85 SubList(const SubList<T>&) noexcept = default;
87
88 // Constructors
89
90 //- Construct from UList, the entire size
91 inline explicit SubList(const UList<T>& list) noexcept;
92
93 //- Construct from FixedList, the entire size
94 template<unsigned N>
95 inline explicit SubList(const FixedList<T, N>& list) noexcept;
96
97 //- Construct from UList and sub-list size, start at 0
98 inline SubList
99 (
100 const UList<T>& list,
101 const label len
102 );
103
104 //- Construct from UList, sub-list size and start index
105 inline SubList
106 (
107 const UList<T>& list,
108 const label len,
109 const label start
110 );
111
112 //- Construct from UList and a (start,size) range.
113 // The range is subsetted with the list size itself to ensure that the
114 // result always addresses a valid section of the list.
115 inline SubList
116 (
117 const UList<T>& list,
118 const labelRange& range
119 );
120
121 //- Construct from UList and a (start,size) range,
122 //- but bypassing run-time range checking.
123 inline SubList
124 (
125 const labelRange& range,
126 const UList<T>& list
127 );
128
129
130 // Member Functions
131
132 //- Reset to zero-sized and nullptr
133 inline UList<T>& reset(std::nullptr_t) noexcept;
134
135 //- Reset to use entire UList
136 inline UList<T>& reset(const UList<T>& list) noexcept;
138 //- Reset to use UList with sub-list size, start at 0
139 inline UList<T>& reset
140 (
141 const UList<T>& list,
142 const label len
143 );
144
145 //- Reset to use UList with sub-list size and start index
146 inline UList<T>& reset
147 (
148 const UList<T>& list,
149 const label len,
150 const label start
151 );
152
153 //- Reset to use UList with a (start,size) range.
154 // The range is subsetted with the list size itself to ensure that the
155 // result always addresses a valid section of the list.
156 inline UList<T>& reset
157 (
158 const UList<T>& list,
160 );
161
162 //- Reset to use UList with a (start,size) range, but bypassing
163 //- run-time range checking.
164 inline UList<T>& reset
165 (
166 const labelRange& range,
167 const UList<T>& list
168 );
169
170
171 // Member Operators
172
173 //- Allow cast to a const List<T>&
174 FOAM_DEPRECATED_STRICTER(2025-04, "dereference as SubList, not List?")
175 operator const Foam::List<T>&() const
176 {
177 return *reinterpret_cast<const List<T>*>(this);
178 }
179
180 //- Copy assign entries (deep copy) from given sub-list.
181 //- Sizes must match!
182 inline void operator=(const SubList<T>& list);
183
184 //- Copy assign entries (deep copy) from given list.
185 //- Sizes must match!
186 inline void operator=(const UList<T>& list);
187
188 //- Copy assign entries from given indirect list. Sizes must match!
189 template<class Addr>
190 inline void operator=(const IndirectListBase<T, Addr>& list);
192 //- Assign all entries to the given value
193 inline void operator=(const T& val);
194
195 //- Assign all entries to zero
196 inline void operator=(Foam::zero);
197};
198
199
200// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
201
202} // End namespace Foam
203
204// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
205
206#include "SubListI.H"
207
208// * * * * * * * * * * * * * * * Implementations * * * * * * * * * * * * * * //
209
210template<class Type>
212:
213 UList<Type>(list.data(), list.size())
214{}
215
216
217template<class Type>
219Foam::UList<Type>::slice(const label pos, label len)
220{
221 if (len < 0)
222 {
223 len = (this->size() - pos);
224 }
225 return SubList<Type>(*this, len, pos);
226}
227
228
229template<class Type>
231Foam::UList<Type>::slice(const label pos, label len) const
232{
233 if (len < 0)
234 {
235 len = (this->size() - pos);
236 }
237 return SubList<Type>(*this, len, pos);
238}
239
240
241template<class Type>
243Foam::UList<Type>::slice(const labelRange& range)
244{
245 return SubList<Type>(*this, range); // with range checking
246}
247
248
249template<class Type>
251Foam::UList<Type>::slice(const labelRange& range) const
252{
253 return SubList<Type>(*this, range); // with range checking
254}
255
256
257// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
259#endif
260
261// ************************************************************************* //
scalar range
A 1D vector of objects of type <T> with a fixed length <N>.
Definition FixedList.H:73
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
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
A non-owning sub-view of a List (allocated or unallocated storage).
Definition SubList.H:61
void operator=(Foam::zero)
Assign all entries to zero.
Definition SubListI.H:240
void operator=(const SubList< T > &list)
Copy assign entries (deep copy) from given sub-list. Sizes must match!
Definition SubListI.H:211
void operator=(const UList< T > &list)
Copy assign entries (deep copy) from given list. Sizes must match!
Definition SubListI.H:218
UList< bool > & reset(std::nullptr_t) noexcept
void operator=(const T &val)
Assign all entries to the given value.
Definition SubListI.H:233
SubList() noexcept=default
Default construct, zero-sized and nullptr.
static const SubList< T > & null() noexcept
Return a null SubList (reference to a nullObject). Behaves like an empty SubList.
Definition SubList.H:70
void operator=(const IndirectListBase< T, Addr > &list)
Copy assign entries from given indirect list. Sizes must match!
Definition SubListI.H:226
UList(const UList< T > &) noexcept=default
Copy construct, shallow copy.
constexpr UList() noexcept
Default construct, zero-sized and nullptr.
Definition UListI.H:28
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
Definition SubList.H:258
void size(const label n)
Older name for setAddressableSize.
Definition UList.H:118
A range or interval of labels defined by a start and a size.
Definition labelRange.H:66
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition zero.H:58
Namespace for OpenFOAM.
dimensionedScalar pos(const dimensionedScalar &ds)
const T & NullObjectRef() noexcept
Const reference (of type T) to the nullObject.
Definition nullObject.H:228
SubList< bool > boolSubList
A SubList of bools.
Definition SubList.H:48
SubList< char > charSubList
A SubList of chars.
Definition SubList.H:49
SubList< label > labelSubList
A SubList of labels.
Definition SubList.H:50
const direction noexcept
Definition scalarImpl.H:265
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
#define FOAM_DEPRECATED_STRICTER(since, replacement)
Definition stdFoam.H:56
const Vector< label > N(dict.get< Vector< label > >("N"))