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-2015 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  << "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>
170 {
171  return xferMove(*this);
172 }
173 
174 
175 template<class T, class Container>
177 {
178  this->setSize(nRows);
179 }
180 
181 
182 template<class T, class Container>
184 (
185  const label nRows,
186  const label nData
187 )
188 {
189  this->setSize(nRows, nData);
190 }
191 
192 
193 template<class T, class Container>
195 (
196  const label nRows,
197  const label nData,
198  const T& t
199 )
200 {
201  this->setSize(nRows, nData, t);
202 }
203 
204 
205 template<class T, class Container>
207 (
208  const labelUList& rowSizes
209 )
210 {
211  this->setSize(rowSizes);
212 }
213 
214 
215 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
216 
217 template<class T, class Container>
219 (
220  const label i
221 )
222 {
223  label start = offsets_[i];
224  return UList<T>(m_.begin() + start, offsets_[i+1] - start);
225 }
226 
227 
228 template<class T, class Container>
229 inline const Foam::UList<T>
231 (
232  const label i
233 ) const
234 {
235  label start = offsets_[i];
236  return UList<T>
237  (
238  const_cast<T*>(m_.begin() + start),
239  offsets_[i+1] - start
240  );
241 }
242 
243 
244 template<class T, class Container>
246 (
247  const label i,
248  const label j
249 )
250 {
251  return m_[index(i, j)];
252 }
253 
254 
255 template<class T, class Container>
257 (
258  const label i,
259  const label j
260 ) const
261 {
262  return m_[index(i, j)];
263 }
264 
265 
266 template<class T, class Container>
268 {
269  m_ = t;
270 }
271 
272 
273 // ************************************************************************* //
Foam::CompactListList::offsets
const List< label > & offsets() const
Return the offset table (= size()+1)
Definition: CompactListListI.H:102
Foam::CompactListList::m
const List< T > & m() const
Return the packed matrix of data.
Definition: CompactListListI.H:116
setSize
points setSize(newPointi)
SubList.H
Foam::CompactListList::whichRow
label whichRow(const label index) const
Get row for index into m.
Definition: CompactListListI.H:142
Foam::CompactListList
A packed storage unstructured matrix of objects of type <T> using an offset table for access.
Definition: polyTopoChange.H:91
Foam::CompactListList::operator=
void operator=(const T &)
Assignment of all entries to the given value.
Definition: CompactListListI.H:267
Foam::CompactListList::empty
bool empty() const
Return true if the number of rows is zero.
Definition: CompactListListI.H:94
Foam::Xfer
A simple container for copying or transferring objects of type <T>.
Definition: Xfer.H:85
Foam::CompactListList::resize
void resize(const label nRows)
Reset size of CompactListList.
Definition: CompactListListI.H:176
Foam::CompactListList::whichColumn
label whichColumn(const label row, const label index) const
Get column index (j) given above row.
Definition: CompactListListI.H:158
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:59
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:55
Foam::findLower
label findLower(const ListType &, typename ListType::const_reference, const label start, const BinaryOp &bop)
Find last element < given value in sorted list and return index,.
Foam::CompactListList::null
static const CompactListList< T, Container > & null()
Return a null CompactListList.
Definition: CompactListListI.H:80
Foam::FatalError
error FatalError
Foam::abort
errorManip< error > abort(error &err)
Definition: errorManip.H:131
Foam::CompactListList::index
label index(const label row, const label col) const
Return index into m.
Definition: CompactListListI.H:132
Foam::graphRow
Definition: graphRow.H:48
Foam::autoPtr
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:117
FatalErrorInFunction
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:318
Foam::xferMove
Xfer< T > xferMove(T &)
Construct by transferring the contents of the arg.
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:59
Foam::UList
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
Foam::CompactListList::size
label size() const
Return the primary size, i.e. the number of rows.
Definition: CompactListListI.H:87
Foam::CompactListList::CompactListList
CompactListList()
Null constructor.
Definition: CompactListListI.H:32
Foam::CompactListList::xfer
Xfer< CompactListList< T, Container > > xfer()
Transfer the contents to the Xfer container.
Definition: CompactListListI.H:169
ListOps.H
Various functions to operate on Lists.
Foam::CompactListList::clone
autoPtr< CompactListList< T, Container > > clone() const
Clone.
Definition: CompactListListI.H:67