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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
32 
33 template<class T>
35 (
36  const UList<T>& list
37 ) noexcept
38 :
39  UList<T>(const_cast<T*>(list.cdata()), list.size())
40 {}
41 
42 
43 template<class T>
44 template<unsigned N>
46 (
47  const FixedList<T, N>& list
48 ) noexcept
49 :
50  UList<T>(const_cast<T*>(list.cdata()), list.size())
51 {}
52 
53 
54 template<class T>
56 (
57  const UList<T>& list,
58  const label len
59 )
60 :
61  UList<T>(const_cast<T*>(list.cdata()), len)
62 {
63  #ifdef FULLDEBUG
64  list.checkSize(len);
65  #endif
66 }
67 
68 
69 template<class T>
71 (
72  const UList<T>& list,
73  const label len,
74  const label start
75 )
76 :
77  UList<T>(const_cast<T*>(list.cdata() + start), len)
78 {
79  #ifdef FULLDEBUG
80  list.checkRange(start, len);
81  #endif
82 }
83 
84 
85 template<class T>
87 (
88  const UList<T>& list,
89  const labelRange& range
90 )
91 :
92  SubList<T>(range.subset0(list.size()), list)
93 {
94  #ifdef FULLDEBUG
95  // The subset0() above always produces valid ranges but want to check
96  // that the input itself was valid
97  list.checkRange(range.start(), range.size());
98  #endif
99 }
100 
101 
102 template<class T>
104 (
105  const labelRange& range,
106  const UList<T>& list
107 )
108 :
109  SubList<T>(list, range.size(), range.start())
110 {}
111 
112 
113 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
114 
115 template<class T>
116 inline Foam::UList<T>& Foam::SubList<T>::reset(std::nullptr_t) noexcept
117 {
119  return *this;
120 }
121 
122 
123 template<class T>
125 (
126  const UList<T>& list
127 ) noexcept
128 {
130  return *this;
131 }
132 
133 
134 template<class T>
136 (
137  const UList<T>& list,
138  const label len
139 )
140 {
141  #ifdef FULLDEBUG
142  list.checkSize(len);
143  #endif
144 
145  UList<T>::shallowCopy(const_cast<T*>(list.cdata()), len);
146  return *this;
147 }
148 
149 
150 template<class T>
152 (
153  const UList<T>& list,
154  const label len,
155  const label start
156 )
157 {
158  #ifdef FULLDEBUG
159  list.checkRange(start, len);
160  #endif
161 
163  (
164  const_cast<T*>(list.cdata() + start),
165  len
166  );
167  return *this;
168 }
169 
170 
171 template<class T>
173 (
174  const UList<T>& list,
175  const labelRange& range
176 )
177 {
178  #ifdef FULLDEBUG
179  // subset0() always produces valid ranges but want to check
180  // that the input itself was valid
181  list.checkRange(range.start(), range.size());
182  #endif
183 
184  labelRange clamped(range.subset0(list.size()));
185 
187  (
188  const_cast<T*>(list.cdata() + clamped.start()),
189  clamped.size()
190  );
191  return *this;
192 }
193 
194 
195 template<class T>
197 (
198  const labelRange& range,
199  const UList<T>& list
200 )
201 {
202  #ifdef FULLDEBUG
203  list.checkRange(range.start(), range.size());
204  #endif
205 
207  (
208  const_cast<T*>(list.cdata() + range.start()),
209  range.size()
210  );
211  return *this;
212 }
213 
214 
215 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
216 
217 template<class T>
218 inline void Foam::SubList<T>::operator=(const SubList<T>& list)
219 {
220  UList<T>::deepCopy(list);
221 }
222 
223 
224 template<class T>
225 inline void Foam::SubList<T>::operator=(const UList<T>& list)
226 {
227  UList<T>::deepCopy(list);
228 }
229 
230 
231 template<class T>
232 template<class Addr>
234 {
235  UList<T>::deepCopy(list);
236 }
237 
238 
239 template<class T>
240 inline void Foam::SubList<T>::operator=(const T& val)
241 {
242  UList<T>::operator=(val);
243 }
244 
245 
246 template<class T>
248 {
250 }
251 
252 
253 // ************************************************************************* //
void size(const label n)
Older name for setAddressableSize.
Definition: UList.H:114
A 1D vector of objects of type <T> with a fixed length <N>.
Definition: HashTable.H:107
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:109
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 (deep copy) from given sub-list. Sizes must match!
Definition: SubListI.H:211
A non-owning sub-view of a List (allocated or unallocated storage).
Definition: SubList.H:46
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: scalarImpl.H:255
const volScalarField & T
void checkRange(const label start, const label len) const
Check that start and length define a valid range.
Definition: UListI.H:160
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:146
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:258