SubListI.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 -------------------------------------------------------------------------------
11 License
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 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "FixedList.H"
30 
31 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
32 
33 template<class T>
35 {
36  return NullObjectRef<SubList<T>>();
37 }
38 
39 
40 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
41 
42 template<class T>
44 (
45  const UList<T>& list
46 ) noexcept
47 :
48  UList<T>(const_cast<T*>(list.cdata()), list.size())
49 {}
50 
51 
52 template<class T>
53 template<unsigned N>
55 (
56  const FixedList<T, N>& list
57 ) noexcept
58 :
59  UList<T>(const_cast<T*>(list.cdata()), list.size())
60 {}
61 
62 
63 template<class T>
65 (
66  const UList<T>& list,
67  const label len
68 )
69 :
70  UList<T>(const_cast<T*>(list.cdata()), len)
71 {
72  #ifdef FULLDEBUG
73  list.checkSize(len);
74  #endif
75 }
76 
77 
78 template<class T>
80 (
81  const UList<T>& list,
82  const label len,
83  const label start
84 )
85 :
86  UList<T>(const_cast<T*>(list.cdata() + start), len)
87 {
88  #ifdef FULLDEBUG
89  list.checkRange(start, len);
90  #endif
91 }
92 
93 
94 template<class T>
96 (
97  const UList<T>& list,
98  const labelRange& range
99 )
100 :
101  SubList<T>(range.subset0(list.size()), list)
102 {
103  #ifdef FULLDEBUG
104  // The subset0() above always produces valid ranges but want to check
105  // that the input itself was valid
106  list.checkRange(range.start(), range.size());
107  #endif
108 }
109 
110 
111 template<class T>
113 (
114  const labelRange& range,
115  const UList<T>& list
116 )
117 :
118  SubList<T>(list, range.size(), range.start())
119 {}
120 
121 
122 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
123 
124 template<class T>
125 inline Foam::UList<T>& Foam::SubList<T>::reset(std::nullptr_t) noexcept
126 {
128  return *this;
129 }
130 
131 
132 template<class T>
134 (
135  const UList<T>& list
136 ) noexcept
137 {
139  return *this;
140 }
141 
142 
143 template<class T>
145 (
146  const UList<T>& list,
147  const label len
148 )
149 {
150  #ifdef FULLDEBUG
151  list.checkSize(len);
152  #endif
153 
154  UList<T>::shallowCopy(const_cast<T*>(list.cdata()), len);
155  return *this;
156 }
157 
158 
159 template<class T>
161 (
162  const UList<T>& list,
163  const label len,
164  const label start
165 )
166 {
167  #ifdef FULLDEBUG
168  list.checkRange(start, len);
169  #endif
170 
172  (
173  const_cast<T*>(list.cdata() + start),
174  len
175  );
176  return *this;
177 }
178 
179 
180 template<class T>
182 (
183  const UList<T>& list,
184  const labelRange& range
185 )
186 {
187  #ifdef FULLDEBUG
188  // subset0() always produces valid ranges but want to check
189  // that the input itself was valid
190  list.checkRange(range.start(), range.size());
191  #endif
192 
193  labelRange clamped(range.subset0(list.size()));
194 
196  (
197  const_cast<T*>(list.cdata() + clamped.start()),
198  clamped.size()
199  );
200  return *this;
201 }
202 
203 
204 template<class T>
206 (
207  const labelRange& range,
208  const UList<T>& list
209 )
210 {
211  #ifdef FULLDEBUG
212  list.checkRange(range.start(), range.size());
213  #endif
214 
216  (
217  const_cast<T*>(list.cdata() + range.start()),
218  range.size()
219  );
220  return *this;
221 }
222 
223 
224 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
225 
226 template<class T>
228 {
229  return *reinterpret_cast<const List<T>*>(this);
230 }
231 
232 
233 template<class T>
234 inline void Foam::SubList<T>::operator=(const SubList<T>& list)
235 {
236  UList<T>::deepCopy(list);
237 }
238 
239 
240 template<class T>
241 inline void Foam::SubList<T>::operator=(const UList<T>& list)
242 {
243  UList<T>::deepCopy(list);
244 }
245 
246 
247 template<class T>
248 template<class Addr>
250 {
251  UList<T>::deepCopy(list);
252 }
253 
254 
255 template<class T>
256 inline void Foam::SubList<T>::operator=(const T& val)
257 {
258  UList<T>::operator=(val);
259 }
260 
261 
262 template<class T>
263 inline void Foam::SubList<T>::operator=(const Foam::zero)
264 {
266 }
267 
268 
269 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:116
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:107
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
SubList() noexcept=default
Default construct, zero-sized and nullptr.
UList< T > & reset(std::nullptr_t) noexcept
Reset to zero-sized and nullptr.
Definition: SubListI.H:118
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
scalar range
void operator=(const SubList< T > &list)
Copy assign entries from given sub-list. Sizes must match!
Definition: SubListI.H:227
A List obtained as a section of another List.
Definition: SubList.H:50
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: HashTable.H:105
const direction noexcept
Definition: Scalar.H:258
const volScalarField & T
void checkRange(const label start, const label len) const
Check that start and length define a valid range.
Definition: UListI.H:167
static const SubList< T > & null()
Return a null SubList.
Definition: SubListI.H:27
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
void checkSize(const label size) const
Check size is within valid range [0,size].
Definition: UListI.H:153
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:265