FreeFOAM The Cross-Platform CFD Toolkit
CompactListList_devI.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 #include <OpenFOAM/ListOps.H>
27 #include <OpenFOAM/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 *reinterpret_cast< CompactListList_dev<T, Container>* >(0);
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>
142 inline Foam::label Foam::CompactListList_dev<T, Container>::whichRow(const label i)
143 const
144 {
145  if (i < 0 || i >= m_.size())
146  {
148  (
149  "CompactListList_dev<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 UList<label>& 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_.size() ? &m_[start] : NULL), 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  (m_.size() ? const_cast<T*>(&m_[start]) : NULL),
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 // ************************ vim: set sw=4 sts=4 et: ************************ //