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 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_(lst.size()),
98  offsets_(lst.offsets_, reuse),
99  m_(lst.m_, reuse)
100 {}
101 
102 
103 template<class T, class Container>
106 {
108 }
109 
110 
111 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
112 
113 template<class T, class Container>
116 {
117  return NullObjectRef<CompactListList<T, Container>>();
118 }
119 
120 
121 template<class T, class Container>
123 {
124  return size_;
125 }
126 
127 
128 template<class T, class Container>
129 inline bool Foam::CompactListList<T, Container>::empty() const noexcept
130 {
131  return !size_;
132 }
133 
134 
135 template<class T, class Container>
136 inline const Foam::List<Foam::label>&
138 {
139  return offsets_;
140 }
141 
142 
143 template<class T, class Container>
145 {
146  return offsets_;
147 }
148 
149 
150 template<class T, class Container>
152 const
153 {
154  return m_;
155 }
156 
157 
158 template<class T, class Container>
160 {
161  return m_;
162 }
163 
164 
165 template<class T, class Container>
167 (
168  const label i,
169  const label j
170 ) const
171 {
172  return offsets_[i] + j;
173 }
174 
175 
176 template<class T, class Container>
178 const
179 {
180  if (i < 0 || i >= m_.size())
181  {
183  << "Index " << i << " outside 0.." << m_.size()
184  << abort(FatalError);
185  }
186 
187  return findLower(offsets_, i+1);
188 }
189 
190 
191 template<class T, class Container>
193 (
194  const label row,
195  const label i
196 ) const
197 {
198  return i - index(row, 0);
199 }
200 
201 
202 template<class T, class Container>
204 {
205  this->setSize(mRows);
206 }
207 
208 
209 template<class T, class Container>
211 (
212  const label mRows,
213  const label nData
214 )
215 {
216  this->setSize(mRows, nData);
217 }
218 
219 
220 template<class T, class Container>
222 (
223  const label mRows,
224  const label nData,
225  const T& t
226 )
227 {
228  this->setSize(mRows, nData, t);
229 }
230 
231 
232 template<class T, class Container>
234 (
235  const labelUList& rowSizes
236 )
237 {
238  this->setSize(rowSizes);
239 }
240 
241 
242 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
243 
244 template<class T, class Container>
246 (
247  const label i
248 )
249 {
250  const label start = offsets_[i];
251  return UList<T>(m_.begin() + start, offsets_[i+1] - start);
252 }
253 
254 
255 template<class T, class Container>
256 inline const Foam::UList<T>
258 (
259  const label i
260 ) const
261 {
262  const label start = offsets_[i];
263  return UList<T>
264  (
265  const_cast<T*>(m_.begin() + start),
266  offsets_[i+1] - start
267  );
268 }
269 
270 
271 template<class T, class Container>
273 (
274  const label i,
275  const label j
276 )
277 {
278  return m_[index(i, j)];
279 }
280 
281 
282 template<class T, class Container>
284 (
285  const label i,
286  const label j
287 ) const
288 {
289  return m_[index(i, j)];
290 }
291 
292 
293 template<class T, class Container>
295 {
296  m_ = val;
297 }
298 
299 
300 template<class T, class Container>
302 (
304 )
305 {
306  if (this == &lst)
307  {
308  return; // Self-assignment is a no-op
309  }
310 
311  size_ = lst.size_;
312  offsets_ = lst.offsets_,
313  m_ = lst.m_;
314 }
315 
316 
317 template<class T, class Container>
319 (
321 )
322 {
323  if (this == &lst)
324  {
325  return; // Self-assignment is a no-op
326  }
327 
328  transfer(lst);
329 }
330 
331 
332 // ************************************************************************* //
Foam::CompactListList::offsets
const List< label > & offsets() const
Return the offset table (= size()+1)
Definition: CompactListListI.H:137
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:151
Foam::CompactListList::operator=
void operator=(const T &val)
Assignment of all entries to the given value.
Definition: CompactListListI.H:294
setSize
points setSize(newPointi)
Foam::val
label ListType::const_reference val
Definition: ListOps.H:407
SubList.H
Foam::CompactListList::whichRow
label whichRow(const label index) const
Get row for index into m.
Definition: CompactListListI.H:177
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: polyTopoChange.H:94
Foam::CompactListList::empty
bool empty() const noexcept
True if the number of rows is zero.
Definition: CompactListListI.H:129
Foam::CompactListList::whichColumn
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
Definition: CompactListListI.H:193
Foam::CompactListList::resize
void resize(const label mRows)
Reset size of CompactListList.
Definition: CompactListListI.H:203
Foam::label
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Definition: label.H:62
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:115
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:137
Foam::CompactListList::index
label index(const label row, const label col) const
Return index into m.
Definition: CompactListListI.H:167
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:355
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:102
Foam::start
label ListType::const_reference const label start
Definition: ListOps.H:408
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:122
ListOps.H
Various functions to operate on Lists.
Foam::CompactListList::clone
autoPtr< CompactListList< T, Container > > clone() const
Clone.
Definition: CompactListListI.H:105