FixedListI.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-2016 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 "UList.H"
27 #include "SLList.H"
28 #include "contiguous.H"
29 
30 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
31 
32 template<class T, unsigned Size>
34 {}
35 
36 
37 template<class T, unsigned Size>
39 {
40  for (unsigned i=0; i<Size; i++)
41  {
42  v_[i] = v[i];
43  }
44 }
45 
46 
47 template<class T, unsigned Size>
49 {
50  for (unsigned i=0; i<Size; i++)
51  {
52  v_[i] = t;
53  }
54 }
55 
56 
57 template<class T, unsigned Size>
59 {
60  checkSize(lst.size());
61 
62  for (unsigned i=0; i<Size; i++)
63  {
64  v_[i] = lst[i];
65  }
66 }
67 
68 
69 template<class T, unsigned Size>
71 {
72  checkSize(lst.size());
73 
74  label i = 0;
75  for
76  (
77  typename SLList<T>::const_iterator iter = lst.begin();
78  iter != lst.end();
79  ++iter
80  )
81  {
82  operator[](i++) = iter();
83  }
84 }
85 
86 
87 template<class T, unsigned Size>
89 {
90  for (unsigned i=0; i<Size; i++)
91  {
92  v_[i] = lst[i];
93  }
94 }
95 
96 
97 template<class T, unsigned Size>
100 {
102 }
103 
104 
105 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
106 
107 template<class T, unsigned Size>
109 {
110  return NullObjectRef<FixedList<T, Size>>();
111 }
112 
113 
114 template<class T, unsigned Size>
116 {
117  return (i == Size-1 ? 0 : i+1);
118 }
119 
120 
121 template<class T, unsigned Size>
123 {
124  return (i ? i-1 : Size-1);
125 }
126 
127 
128 template<class T, unsigned Size>
129 inline void Foam::FixedList<T, Size>::checkStart(const label start) const
130 {
131  if (start < 0 || (start && unsigned(start) >= Size))
132  {
134  << "start " << start << " out of range 0 ... " << (Size-1)
135  << abort(FatalError);
136  }
137 }
138 
139 
140 template<class T, unsigned Size>
141 inline void Foam::FixedList<T, Size>::checkSize(const label size) const
142 {
143  if (size < 0 || unsigned(size) > Size)
144  {
146  << "size " << size << " out of range 0 ... " << (Size)
147  << abort(FatalError);
148  }
149 }
150 
151 
152 template<class T, unsigned Size>
153 inline void Foam::FixedList<T, Size>::checkIndex(const label i) const
154 {
155  if (i < 0 || unsigned(i) >= Size)
156  {
158  << "index " << i << " out of range 0 ... " << (Size-1)
159  << abort(FatalError);
160  }
161 }
162 
163 
164 template<class T, unsigned Size>
166 {
167  #ifdef FULLDEBUG
168  checkSize(s);
169  #endif
170 }
171 
172 template<class T, unsigned Size>
174 {
175  #ifdef FULLDEBUG
176  checkSize(s);
177  #endif
178 }
179 
180 template<class T, unsigned Size>
182 {
183  for (unsigned i=0; i<Size; i++)
184  {
185  v_[i] = lst[i];
186  }
187 }
188 
189 
190 template<class T, unsigned Size>
191 inline const T*
193 {
194  return v_;
195 }
196 
197 
198 template<class T, unsigned Size>
199 inline T*
201 {
202  return v_;
203 }
204 
205 
206 template<class T, unsigned Size>
208 {
209  return v_[0];
210 }
211 
212 
213 template<class T, unsigned Size>
214 inline const T& Foam::FixedList<T, Size>::first() const
215 {
216  return v_[0];
217 }
218 
219 
220 template<class T, unsigned Size>
222 {
223  return v_[Size-1];
224 }
225 
226 
227 template<class T, unsigned Size>
228 inline const T& Foam::FixedList<T, Size>::last() const
229 {
230  return v_[Size-1];
231 }
232 
233 
234 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
235 
236 template<class T, unsigned Size>
238 {
239  #ifdef FULLDEBUG
240  checkIndex(i);
241  #endif
242  return v_[i];
243 }
244 
245 
246 template<class T, unsigned Size>
247 inline const T& Foam::FixedList<T, Size>::operator[](const label i) const
248 {
249  #ifdef FULLDEBUG
250  checkIndex(i);
251  #endif
252  return v_[i];
253 }
254 
255 
256 template<class T, unsigned Size>
257 inline void Foam::FixedList<T, Size>::operator=(const T lst[Size])
258 {
259  for (unsigned i=0; i<Size; i++)
260  {
261  v_[i] = lst[i];
262  }
263 }
264 
265 template<class T, unsigned Size>
267 {
268  checkSize(lst.size());
269 
270  for (unsigned i=0; i<Size; i++)
271  {
272  v_[i] = lst[i];
273  }
274 }
275 
276 template<class T, unsigned Size>
278 {
279  checkSize(lst.size());
280 
281  label i = 0;
282  for
283  (
284  typename SLList<T>::const_iterator iter = lst.begin();
285  iter != lst.end();
286  ++iter
287  )
288  {
289  operator[](i++) = iter();
290  }
291 }
292 
293 template<class T, unsigned Size>
295 {
296  for (unsigned i=0; i<Size; i++)
297  {
298  v_[i] = t;
299  }
300 }
301 
302 
303 // * * * * * * * * * * * * * * STL Member Functions * * * * * * * * * * * * //
304 
305 template<class T, unsigned Size>
308 {
309  return v_;
310 }
311 
312 
313 template<class T, unsigned Size>
316 {
317  return v_;
318 }
319 
320 
321 template<class T, unsigned Size>
324 {
325  return v_;
326 }
327 
328 
329 template<class T, unsigned Size>
332 {
333  return &v_[Size];
334 }
335 
336 
337 template<class T, unsigned Size>
340 {
341  return &v_[Size];
342 }
343 
344 
345 template<class T, unsigned Size>
348 {
349  return &v_[Size];
350 }
351 
352 
353 template<class T, unsigned Size>
356 {
357  return &v_[Size-1];
358 }
359 
360 
361 template<class T, unsigned Size>
364 {
365  return &v_[Size-1];
366 }
367 
368 
369 template<class T, unsigned Size>
372 {
373  return &v_[Size-1];
374 }
375 
376 
377 template<class T, unsigned Size>
380 {
381  return &v_[-1];
382 }
383 
384 
385 template<class T, unsigned Size>
388 {
389  return &v_[-1];
390 }
391 
392 
393 template<class T, unsigned Size>
396 {
397  return &v_[-1];
398 }
399 
400 
401 template<class T, unsigned Size>
403 {
404  return Size;
405 }
406 
407 
408 template<class T, unsigned Size>
410 {
411  return Size;
412 }
413 
414 
415 template<class T, unsigned Size>
417 {
418  return false;
419 }
420 
421 
422 template<class T, unsigned Size>
423 template<class HashT>
425 (
426  const FixedList<T, Size>& lst,
427  unsigned seed
428 ) const
429 {
430  if (contiguous<T>())
431  {
432  // Hash directly
433  return Hasher(lst.v_, sizeof(lst.v_), seed);
434  }
435  else
436  {
437  // Hash incrementally
438  unsigned val = seed;
439 
440  for (unsigned i=0; i<Size; i++)
441  {
442  val = HashT()(lst[i], val);
443  }
444 
445  return val;
446  }
447 }
448 
449 
450 // ************************************************************************* //
reverse_iterator rbegin()
Return reverse_iterator to begin reverse traversing the FixedList.
Definition: FixedListI.H:355
static const FixedList< T, Size > & null()
Return a null FixedList.
Definition: FixedListI.H:108
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
A 1D vector of objects of type <T> with a fixed size <Size>.
Definition: FixedList.H:53
error FatalError
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:319
void checkIndex(const label i) const
Check index i is within valid range (0 ... size-1).
Definition: FixedListI.H:153
const iterator & end()
Definition: LList.H:273
Template function to specify if the data of a type are contiguous.
const_iterator cbegin() const
Return const_iterator to begin traversing the constant FixedList.
Definition: FixedListI.H:323
An STL-conforming const_iterator.
Definition: SLListBase.H:210
bool empty() const
Return true if the FixedList is empty (ie, size() is zero).
Definition: FixedListI.H:416
friend Ostream & operator(Ostream &, const FixedList< T, Size > &)
reverse_iterator rend()
Return reverse_iterator to end reverse traversing the FixedList.
Definition: FixedListI.H:379
gmvFile<< "tracers "<< particles.size()<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().x()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().y()<< " ";}gmvFile<< nl;forAllConstIter(Cloud< passiveParticle >, particles, iter){gmvFile<< iter().position().z()<< " ";}gmvFile<< nl;forAll(lagrangianScalarNames, i){word name=lagrangianScalarNames[i];IOField< scalar > s(IOobject(name, runTime.timeName(), cloud::prefix, mesh, IOobject::MUST_READ, IOobject::NO_WRITE))
label size() const
Return number of elements in list.
Definition: SLListBaseI.H:67
void operator=(const T v[Size])
Assignment from array operator. Takes linear time.
Definition: FixedListI.H:257
const T * const_iterator
Random access iterator for traversing FixedList.
Definition: FixedList.H:261
T & operator[](const label)
Return element of FixedList.
Definition: FixedListI.H:237
const_iterator cend() const
Return const_iterator to end traversing the constant FixedList.
Definition: FixedListI.H:347
void transfer(const FixedList< T, Size > &)
Copy (not transfer) the argument contents.
Definition: FixedListI.H:181
T & first()
Return the first element of the list.
Definition: FixedListI.H:207
label max_size() const
Return size of the largest possible FixedList.
Definition: FixedListI.H:409
T & last()
Return the last element of the list.
Definition: FixedListI.H:221
Non-intrusive singly-linked list.
Definition: SLList.H:47
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
Definition: FixedListI.H:115
errorManip< error > abort(error &err)
Definition: errorManip.H:131
label size() const
Return the number of elements in the FixedList.
Definition: FixedListI.H:402
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
void resize(const label)
Dummy resize function.
Definition: FixedListI.H:165
T * iterator
Random access iterator for traversing FixedList.
Definition: FixedList.H:249
iterator end()
Return an iterator to end traversing the FixedList.
Definition: FixedListI.H:331
iterator begin()
Return an iterator to begin traversing the FixedList.
Definition: FixedListI.H:307
void checkSize(const label size) const
Check size is within valid range (0 ... size).
Definition: FixedListI.H:141
const volScalarField & T
FixedList()
Null constructor.
Definition: FixedListI.H:33
label size() const
Return the number of elements in the UList.
Definition: UListI.H:299
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins&#39;s 96-bit mixer hashing function (lookup3)
Definition: Hasher.C:476
const_reverse_iterator crbegin() const
Return const_reverse_iterator to begin reverse traversing FixedList.
Definition: FixedListI.H:371
T * data()
Return a pointer to the first data element,.
Definition: FixedListI.H:200
void checkStart(const label start) const
Check start is within valid range (0 ... size-1).
Definition: FixedListI.H:129
void setSize(const label)
Dummy setSize function.
Definition: FixedListI.H:173
An auto-pointer similar to the STL auto_ptr but with automatic casting to a reference to the type and...
Definition: PtrList.H:53
const_reverse_iterator crend() const
Return const_reverse_iterator to end reverse traversing FixedList.
Definition: FixedListI.H:395
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
Definition: FixedListI.H:122
const T * cdata() const
Return a const pointer to the first data element,.
Definition: FixedListI.H:192
autoPtr< FixedList< T, Size > > clone() const
Clone.
Definition: FixedListI.H:99