CompactListListI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2019 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 #include "ListOps.H"
27 #include "SubList.H"
28 
29 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
30 
31 template<class T, class Container>
33 :
34  size_(0)
35 {}
36 
37 
38 template<class T, class Container>
40 (
41  const label mRows,
42  const label nData
43 )
44 :
45  size_(mRows),
46  offsets_(mRows+1, 0),
47  m_(nData)
48 {}
49 
50 
51 template<class T, class Container>
53 (
54  const label mRows,
55  const label nData,
56  const T& t
57 )
58 :
59  size_(mRows),
60  offsets_(mRows+1, 0),
61  m_(nData, t)
62 {}
63 
64 
65 template<class T, class Container>
68 {
70  (
72  );
73 }
74 
75 
76 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
77 
78 template<class T, class Container>
81 {
82  return NullObjectRef<CompactListList<T, Container>>();
83 }
84 
85 
86 template<class T, class Container>
88 {
89  return size_;
90 }
91 
92 
93 template<class T, class Container>
95 {
96  return !size_;
97 }
98 
99 
100 template<class T, class Container>
101 inline const Foam::List<Foam::label>&
103 {
104  return offsets_;
105 }
106 
107 
108 template<class T, class Container>
110 {
111  return offsets_;
112 }
113 
114 
115 template<class T, class Container>
117 const
118 {
119  return m_;
120 }
121 
122 
123 template<class T, class Container>
125 {
126  return m_;
127 }
128 
129 
130 template<class T, class Container>
132 (
133  const label i,
134  const label j
135 ) const
136 {
137  return offsets_[i] + j;
138 }
139 
140 
141 template<class T, class Container>
143 const
144 {
145  if (i < 0 || i >= m_.size())
146  {
148  << "Index " << i << " outside 0.." << m_.size()
149  << abort(FatalError);
150  }
151 
152  return findLower(offsets_, i+1);
153 }
154 
155 
156 template<class T, class Container>
158 (
159  const label row,
160  const label i
161 ) const
162 {
163  return i - index(row, 0);
164 }
165 
166 
167 template<class T, class Container>
169 {
170  this->setSize(mRows);
171 }
172 
173 
174 template<class T, class Container>
176 (
177  const label mRows,
178  const label nData
179 )
180 {
181  this->setSize(mRows, nData);
182 }
183 
184 
185 template<class T, class Container>
187 (
188  const label mRows,
189  const label nData,
190  const T& t
191 )
192 {
193  this->setSize(mRows, nData, t);
194 }
195 
196 
197 template<class T, class Container>
199 (
200  const labelUList& rowSizes
201 )
202 {
203  this->setSize(rowSizes);
204 }
205 
206 
207 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
208 
209 template<class T, class Container>
210 inline Foam::UList<T> Foam::CompactListList<T, Container>::operator[]
211 (
212  const label i
213 )
214 {
215  label start = offsets_[i];
216  return UList<T>(m_.begin() + start, offsets_[i+1] - start);
217 }
218 
219 
220 template<class T, class Container>
221 inline const Foam::UList<T>
222 Foam::CompactListList<T, Container>::operator[]
223 (
224  const label i
225 ) const
226 {
227  label start = offsets_[i];
228  return UList<T>
229  (
230  const_cast<T*>(m_.begin() + start),
231  offsets_[i+1] - start
232  );
233 }
234 
235 
236 template<class T, class Container>
238 (
239  const label i,
240  const label j
241 )
242 {
243  return m_[index(i, j)];
244 }
245 
246 
247 template<class T, class Container>
249 (
250  const label i,
251  const label j
252 ) const
253 {
254  return m_[index(i, j)];
255 }
256 
257 
258 template<class T, class Container>
259 inline void Foam::CompactListList<T, Container>::operator=
260 (
262 )
263 {
264  transfer(cll);
265 }
266 
267 
268 template<class T, class Container>
270 {
271  m_ = t;
272 }
273 
274 
275 // ************************************************************************* //
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:59
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:323
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: HashTable.H:59
const List< T > & m() const
Return the packed matrix of data.
Various functions to operate on Lists.
void transfer(CompactListList< T, Container > &)
Transfer the contents of the argument CompactListList.
label size() const
Return the primary size, i.e. the number of rows.
CompactListList()
Null constructor.
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
void resize(const label mRows)
Reset size of CompactListList.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
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:60
A packed storage unstructured matrix of objects of type <T> using an offset table for access...
void setSize(const label mRows)
Reset size of CompactListList.
autoPtr< CompactListList< T, Container > > clone() const
Clone.
void operator=(CompactListList< T, Container > &&)
Move assignment operator.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
static const CompactListList< T, Container > & null()
Return a null CompactListList.
friend Ostream & operator(Ostream &, const CompactListList< T, Container > &)
const List< label > & offsets() const
Return the offset table (= size()+1)
label index(const label row, const label col) const
Return index into m.
label whichRow(const label index) const
Get row for index into m.
label findLower(const ListType &, typename ListType::const_reference, const label stary, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:52
bool empty() const
Return true if the number of rows is zero.