FreeFOAM The Cross-Platform CFD Toolkit
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) 1991-2010 OpenCFD Ltd.
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 
27 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
28 
29 template<class T>
31 {}
32 
33 
34 template<class T>
36 (
37  const label nRows,
38  const label nData
39 )
40 :
41  offsets_(nRows, 0),
42  m_(nData)
43 {}
44 
45 
46 template<class T>
48 (
49  const label nRows,
50  const label nData,
51  const T& t
52 )
53 :
54  offsets_(nRows, 0),
55  m_(nData, t)
56 {}
57 
58 
59 template<class T>
62 {
64 }
65 
66 
67 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
68 
69 template<class T>
71 {
72  return *reinterpret_cast< CompactListList<T>* >(0);
73 }
74 
75 
76 template<class T>
77 inline Foam::label Foam::CompactListList<T>::size() const
78 {
79  return offsets_.size();
80 }
81 
82 
83 template<class T>
85 {
86  return offsets_.empty();
87 }
88 
89 
90 template<class T>
92 {
93  return offsets_;
94 }
95 
96 
97 template<class T>
99 {
100  return offsets_;
101 }
102 
103 
104 template<class T>
106 {
107  return m_;
108 }
109 
110 
111 template<class T>
113 {
114  return m_;
115 }
116 
117 
118 template<class T>
119 inline Foam::label Foam::CompactListList<T>::index
120 (
121  const label i,
122  const label j
123 ) const
124 {
125  if (i == 0)
126  {
127  return j;
128  }
129  else
130  {
131  return offsets_[i-1] + j;
132  }
133 }
134 
135 
136 template<class T>
137 inline Foam::label Foam::CompactListList<T>::whichRow(const label i) const
138 {
139  if (i < 0 || i >= m_.size())
140  {
142  (
143  "CompactListList<T>::whichRow(const label) const"
144  ) << "Index " << i << " outside 0.." << m_.size()
145  << abort(FatalError);
146  }
147 
148  forAll(offsets_, rowI)
149  {
150  if (i < offsets_[rowI])
151  {
152  return rowI;
153  }
154  }
155 
156  return -1;
157 }
158 
159 
160 template<class T>
161 inline Foam::label Foam::CompactListList<T>::whichColumn
162 (
163  const label row,
164  const label i
165 ) const
166 {
167  return i - index(row, 0);
168 }
169 
170 
171 template<class T>
173 {
174  return xferMove(*this);
175 }
176 
177 
178 template<class T>
179 inline void Foam::CompactListList<T>::resize(const label nRows)
180 {
181  this->setSize(nRows);
182 }
183 
184 
185 template<class T>
187 (
188  const label nRows,
189  const label nData
190 )
191 {
192  this->setSize(nRows, nData);
193 }
194 
195 
196 template<class T>
198 (
199  const label nRows,
200  const label nData,
201  const T& t
202 )
203 {
204  this->setSize(nRows, nData, t);
205 }
206 
207 
208 template<class T>
209 inline void Foam::CompactListList<T>::resize(const UList<label>& rowSizes)
210 {
211  this->setSize(rowSizes);
212 }
213 
214 
215 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
216 
217 template<class T>
219 (
220  const label i
221 )
222 {
223  if (i == 0)
224  {
225  return UList<T>(m_.begin(), offsets_[i]);
226  }
227  else
228  {
229  return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
230  }
231 }
232 
233 
234 template<class T>
236 (
237  const label i
238 ) const
239 {
240  if (i == 0)
241  {
242  return UList<T>(m_.begin(), offsets_[i]);
243  }
244  else
245  {
246  return UList<T>(&m_[offsets_[i-1]], offsets_[i] - offsets_[i-1]);
247  }
248 }
249 
250 
251 template<class T>
253 (
254  const label i,
255  const label j
256 )
257 {
258  return m_[index(i, j)];
259 }
260 
261 
262 template<class T>
264 (
265  const label i,
266  const label j
267 ) const
268 {
269  return m_[index(i, j)];
270 }
271 
272 
273 template<class T>
275 {
276  m_ = t;
277 }
278 
279 
280 // ************************ vim: set sw=4 sts=4 et: ************************ //