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 | Copyright (C) 2011-2014 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 nRows,
42  const label nData
43 )
44 :
45  size_(nRows),
46  offsets_(nRows+1, 0),
47  m_(nData)
48 {}
49 
50 
51 template<class T, class Container>
53 (
54  const label nRows,
55  const label nData,
56  const T& t
57 )
58 :
59  size_(nRows),
60  offsets_(nRows+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  (
149  "CompactListList<T, Container>::whichRow(const label) const"
150  ) << "Index " << i << " outside 0.." << m_.size()
151  << abort(FatalError);
152  }
153 
154  return findLower(offsets_, i+1);
155 }
156 
157 
158 template<class T, class Container>
160 (
161  const label row,
162  const label i
163 ) const
164 {
165  return i - index(row, 0);
166 }
167 
168 
169 template<class T, class Container>
172 {
173  return xferMove(*this);
174 }
175 
176 
177 template<class T, class Container>
179 {
180  this->setSize(nRows);
181 }
182 
183 
184 template<class T, class Container>
186 (
187  const label nRows,
188  const label nData
189 )
190 {
191  this->setSize(nRows, nData);
192 }
193 
194 
195 template<class T, class Container>
197 (
198  const label nRows,
199  const label nData,
200  const T& t
201 )
202 {
203  this->setSize(nRows, nData, t);
204 }
205 
206 
207 template<class T, class Container>
209 (
210  const labelUList& rowSizes
211 )
212 {
213  this->setSize(rowSizes);
214 }
215 
216 
217 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
218 
219 template<class T, class Container>
221 (
222  const label i
223 )
224 {
225  label start = offsets_[i];
226  return UList<T>(m_.begin() + start, offsets_[i+1] - start);
227 }
228 
229 
230 template<class T, class Container>
231 inline const Foam::UList<T>
233 (
234  const label i
235 ) const
236 {
237  label start = offsets_[i];
238  return UList<T>
239  (
240  const_cast<T*>(m_.begin() + start),
241  offsets_[i+1] - start
242  );
243 }
244 
245 
246 template<class T, class Container>
248 (
249  const label i,
250  const label j
251 )
252 {
253  return m_[index(i, j)];
254 }
255 
256 
257 template<class T, class Container>
259 (
260  const label i,
261  const label j
262 ) const
263 {
264  return m_[index(i, j)];
265 }
266 
267 
268 template<class T, class Container>
270 {
271  m_ = t;
272 }
273 
274 
275 // ************************************************************************* //
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
label size() const
Return the primary size, i.e. the number of rows.
label index(const label row, const label col) const
Return index into m.
bool empty() const
Return true if the number of rows is zero.
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
void resize(const label nRows)
Reset size of CompactListList.
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
const List< label > & offsets() const
Return the offset table (= size()+1)
Various functions to operate on Lists.
static const CompactListList< T, Container > & null()
Return a null CompactListList.
Xfer< T > xferMove(T &)
Xfer< CompactListList< T, Container > > xfer()
Transfer the contents to the Xfer container.
void setSize(const label nRows)
Reset size of CompactListList.
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
CompactListList()
Null constructor.
label whichRow(const label index) const
Get row for index into m.
const List< T > & m() const
Return the packed matrix of data.
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,.
errorManip< error > abort(error &err)
Definition: errorManip.H:131
autoPtr< CompactListList< T, Container > > clone() const
Clone.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
Definition: error.H:314
A packed storage unstructured matrix of objects of type <T> using an offset table for access...
void operator=(const T &)
Assignment of all entries to the given value.
error FatalError
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
friend Ostream & operator(Ostream &, const CompactListList< T, Container > &)
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117