CompactListListI.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) 2019-2020 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 "ListOps.H"
30 #include "SubList.H"
31 
32 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
33 
34 template<class T, class Container>
36 :
37  size_(0)
38 {}
39 
40 
41 template<class T, class Container>
43 (
44  const label mRows,
45  const label nData
46 )
47 :
48  size_(mRows),
49  offsets_(mRows+1, 0),
50  m_(nData)
51 {}
52 
53 
54 template<class T, class Container>
56 (
57  const label mRows,
58  const label nData,
59  const T& val
60 )
61 :
62  size_(mRows),
63  offsets_(mRows+1, 0),
64  m_(nData, val)
65 {}
66 
67 
68 template<class T, class Container>
70 (
72 )
73 :
74  size_(lst.size()),
75  offsets_(lst.offsets_),
76  m_(lst.m_)
77 {}
78 
79 
80 template<class T, class Container>
82 (
84 )
85 {
86  transfer(lst);
87 }
88 
89 
90 template<class T, class Container>
92 (
94  bool reuse
95 )
96 :
97  size_(list.size()),
98  offsets_(list.offsets_, reuse),
99  m_(list.m_, reuse)
100 {
101  if (reuse)
102  {
103  list.size_ = 0;
104  }
105 }
106 
107 
108 template<class T, class Container>
111 {
113 }
114 
115 
116 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
117 
118 template<class T, class Container>
121 {
122  return NullObjectRef<CompactListList<T, Container>>();
123 }
124 
125 
126 template<class T, class Container>
127 inline Foam::label Foam::CompactListList<T, Container>::size() const noexcept
128 {
129  return size_;
130 }
131 
132 
133 template<class T, class Container>
134 inline bool Foam::CompactListList<T, Container>::empty() const noexcept
135 {
136  return !size_;
137 }
138 
139 
140 template<class T, class Container>
141 inline const Foam::List<Foam::label>&
143 {
144  return offsets_;
145 }
146 
147 
148 template<class T, class Container>
150 {
151  return offsets_;
152 }
153 
154 
155 template<class T, class Container>
157 const
158 {
159  return m_;
160 }
161 
162 
163 template<class T, class Container>
165 {
166  return m_;
167 }
168 
169 
170 template<class T, class Container>
172 (
173  const label i,
174  const label j
175 ) const
176 {
177  return offsets_[i] + j;
178 }
179 
180 
181 template<class T, class Container>
182 inline Foam::label Foam::CompactListList<T, Container>::whichRow(const label i)
183 const
184 {
185  if (i < 0 || i >= m_.size())
186  {
188  << "Index " << i << " outside 0.." << m_.size()
189  << abort(FatalError);
190  }
191 
192  return findLower(offsets_, i+1);
193 }
194 
195 
196 template<class T, class Container>
198 (
199  const label row,
200  const label i
201 ) const
202 {
203  return i - index(row, 0);
204 }
205 
206 
207 template<class T, class Container>
208 inline void Foam::CompactListList<T, Container>::resize(const label mRows)
209 {
210  this->setSize(mRows);
211 }
212 
213 
214 template<class T, class Container>
216 (
217  const label mRows,
218  const label nData
219 )
220 {
221  this->setSize(mRows, nData);
222 }
223 
224 
225 template<class T, class Container>
227 (
228  const label mRows,
229  const label nData,
230  const T& t
231 )
232 {
233  this->setSize(mRows, nData, t);
234 }
235 
236 
237 template<class T, class Container>
239 (
240  const labelUList& rowSizes
241 )
242 {
243  this->setSize(rowSizes);
244 }
245 
246 
247 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
248 
249 template<class T, class Container>
251 (
252  const label i
253 )
254 {
255  const label start = offsets_[i];
256  return UList<T>(m_.begin() + start, offsets_[i+1] - start);
257 }
258 
259 
260 template<class T, class Container>
261 inline const Foam::UList<T>
263 (
264  const label i
265 ) const
266 {
267  const label start = offsets_[i];
268  return UList<T>
269  (
270  const_cast<T*>(m_.begin() + start),
271  offsets_[i+1] - start
272  );
273 }
274 
275 
276 template<class T, class Container>
278 (
279  const label i,
280  const label j
281 )
282 {
283  return m_[index(i, j)];
284 }
285 
286 
287 template<class T, class Container>
289 (
290  const label i,
291  const label j
292 ) const
293 {
294  return m_[index(i, j)];
295 }
296 
297 
298 template<class T, class Container>
300 {
301  m_ = val;
302 }
303 
304 
305 template<class T, class Container>
307 (
309 )
310 {
311  if (this == &lst)
312  {
313  return; // Self-assignment is a no-op
314  }
315 
316  size_ = lst.size_;
317  offsets_ = lst.offsets_,
318  m_ = lst.m_;
319 }
320 
321 
322 template<class T, class Container>
324 (
326 )
327 {
328  if (this == &lst)
329  {
330  return; // Self-assignment is a no-op
331  }
332 
333  transfer(lst);
334 }
335 
336 
337 // ************************************************************************* //
Foam::CompactListList::offsets
const List< label > & offsets() const
Return the offset table (= size()+1)
Definition: CompactListListI.H:142
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:156
Foam::CompactListList::operator=
void operator=(const T &val)
Assignment of all entries to the given value.
Definition: CompactListListI.H:299
setSize
points setSize(newPointi)
SubList.H
Foam::CompactListList::whichRow
label whichRow(const label index) const
Get row for index into m.
Definition: CompactListListI.H:182
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: polyTopoChange.H:93
Foam::CompactListList::empty
bool empty() const noexcept
True if the number of rows is zero.
Definition: CompactListListI.H:134
Foam::CompactListList::whichColumn
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
Definition: CompactListListI.H:198
Foam::CompactListList::resize
void resize(const label mRows)
Reset size of CompactListList.
Definition: CompactListListI.H:208
Foam::findLower
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Foam::CompactListList::operator
friend Ostream & operator(Ostream &, const CompactListList< T, Container > &)
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::CompactListList::null
static const CompactListList< T, Container > & null()
Return a null CompactListList.
Definition: CompactListListI.H:120
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:144
Foam::CompactListList::index
label index(const label row, const label col) const
Return index into m.
Definition: CompactListListI.H:172
Foam::New
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tdf1, const word &name, const dimensionSet &dimensions)
Global function forwards to reuseTmpDimensionedField::New.
Definition: DimensionedFieldReuseFunctions.H:105
Foam::autoPtr
Pointer management similar to std::unique_ptr, with some additional methods and type checking.
Definition: HashPtrTable.H:53
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:381
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:63
Foam::UList< label >
Foam::CompactListList::CompactListList
CompactListList()
Null constructor.
Definition: CompactListListI.H:35
Foam::CompactListList::size
label size() const noexcept
The primary size (the number of rows)
Definition: CompactListListI.H:127
ListOps.H
Various functions to operate on Lists.
Foam::CompactListList::clone
autoPtr< CompactListList< T, Container > > clone() const
Clone.
Definition: CompactListListI.H:110