UIndirectListI.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2011-2026 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 // * * * * * * * * * * * * * * * * Constructors * * * * * * * * * * * * * * //
27 
28 template<class T>
30 (
31  const UList<T>& completeList,
32  const UList<label>& addr
33 )
34 :
35  completeList_(const_cast<UList<T>&>(completeList)),
36  addressing_(addr)
37 {}
38 
39 
40 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
41 
42 template<class T>
44 {
45  return addressing_.size();
46 }
47 
48 
49 template<class T>
50 inline bool Foam::UIndirectList<T>::empty() const
51 {
52  return addressing_.empty();
53 }
54 
55 
56 template<class T>
58 {
59  return completeList_[addressing_.first()];
60 }
61 
62 
63 template<class T>
64 inline const T& Foam::UIndirectList<T>::first() const
65 {
66  return completeList_[addressing_.first()];
67 }
68 
69 
70 template<class T>
72 {
73  return completeList_[addressing_.last()];
74 }
75 
76 
77 template<class T>
78 inline const T& Foam::UIndirectList<T>::last() const
79 {
80  return completeList_[addressing_.last()];
81 }
82 
83 
84 template<class T>
86 {
87  return addressing_.fcIndex(i);
88 }
89 
90 
91 template<class T>
93 {
94  return addressing_.rcIndex(i);
95 }
96 
97 
98 template<class T>
100 {
101  return completeList_;
102 }
103 
104 
105 template<class T>
107 {
108  return addressing_;
109 }
110 
111 
112 // * * * * * * * * * * * * * * * Member Operators * * * * * * * * * * * * * //
113 
114 template<class T>
116 {
117  List<T> result(size());
118 
119  forAll(*this, i)
120  {
121  result[i] = operator[](i);
122  }
123 
124  return result;
125 }
126 
127 
128 template<class T>
130 {
131  return completeList_[addressing_[i]];
132 }
133 
134 
135 template<class T>
136 inline const T& Foam::UIndirectList<T>::operator[](const label i) const
137 {
138  return completeList_[addressing_[i]];
139 }
140 
141 
142 template<class T>
144 {
145  if (addressing_.size() != ae.size())
146  {
148  << "Addressing and list of addressed elements "
149  "have different sizes: "
150  << addressing_.size() << " " << ae.size()
151  << abort(FatalError);
152  }
153 
154  forAll(addressing_, i)
155  {
156  completeList_[addressing_[i]] = ae[i];
157  }
158 }
159 
160 
161 template<class T>
163 {
164  if (addressing_.size() != ae.size())
165  {
167  << "Addressing and list of addressed elements "
168  "have different sizes: "
169  << addressing_.size() << " " << ae.size()
170  << abort(FatalError);
171  }
172 
173  forAll(addressing_, i)
174  {
175  completeList_[addressing_[i]] = ae[i];
176  }
177 }
178 
179 
180 template<class T>
182 {
183  forAll(addressing_, i)
184  {
185  completeList_[addressing_[i]] = t;
186  }
187 }
188 
189 
190 template<class T>
192 {
193  if (addressing_.size() != ae.size())
194  {
195  return false;
196  }
197 
198  forAll(addressing_, i)
199  {
200  if (completeList_[addressing_[i]] != ae[i])
201  {
202  return false;
203  }
204  }
205 
206  return true;
207 }
208 
209 
210 template<class T>
212 {
213  return !(*this == ae);
214 }
215 
216 
217 // * * * * * * * * * * * * * * * * STL iterator * * * * * * * * * * * * * * //
218 
219 template<class T>
221 (
222  UList<T>& l,
224 )
225 :
226  l_(l),
227  i_(i)
228 {}
229 
230 
231 template<class T>
233 (
234  const iterator& iter
235 ) const
236 {
237  return i_ == iter.i_;
238 }
239 
240 
241 template<class T>
243 (
244  const iterator& iter
245 ) const
246 {
247  return i_ != iter.i_;
248 }
249 
250 
251 template<class T>
253 {
254  return l_[*i_];
255 }
256 
257 
258 template<class T>
260 {
261  return operator*();
262 }
263 
264 
265 template<class T>
268 {
269  ++i_;
270  return *this;
271 }
272 
273 
274 template<class T>
277 {
278  iterator tmp = *this;
279  ++i_;
280  return tmp;
281 }
282 
283 
284 template<class T>
287 {
288  --i_;
289  return *this;
290 }
291 
292 
293 template<class T>
294 inline typename Foam::UIndirectList<T>::iterator
296 {
297  iterator tmp = *this;
298  --i_;
299  return tmp;
300 }
301 
302 
303 template<class T>
304 inline typename Foam::UIndirectList<T>::iterator
306 {
307  i_ += n;
308  return *this;
309 }
310 
311 
312 template<class T>
313 inline typename Foam::UIndirectList<T>::iterator
315 {
316  i_ -= n;
317  return *this;
318 }
319 
320 
321 template<class T>
322 inline typename Foam::UIndirectList<T>::iterator
324 {
325  typename UIndirectList<T>::iterator tmp = *this;
326  return tmp += n;
327 }
328 
329 
330 template<class T>
331 inline typename Foam::UIndirectList<T>::iterator
333 {
334  typename UIndirectList<T>::iterator tmp = *this;
335  return tmp -= n;
336 }
337 
338 
339 template<class T>
341 (
342  const typename UIndirectList<T>::iterator& iter
343 ) const
344 {
345  return i_ - iter.i_;
346 }
347 
348 
349 template<class T>
351 {
352  return *(*this + n);
353 }
354 
355 
356 template<class T>
358 (
359  const iterator& iter
360 ) const
361 {
362  return i_ < iter.i_;
363 }
364 
365 
366 template<class T>
368 (
369  const iterator& iter
370 ) const
371 {
372  return i_ > iter.i_;
373 }
374 
375 
376 template<class T>
378 (
379  const iterator& iter
380 ) const
381 {
382  return i_ <= iter.i_;
383 }
384 
385 
386 template<class T>
388 (
389  const iterator& iter
390 ) const
391 {
392  return i_ >= iter.i_;
393 }
394 
395 
396 template<class T>
397 inline typename Foam::UIndirectList<T>::iterator
399 {
400  return iterator(completeList_, addressing_.begin());
401 }
402 
403 
404 template<class T>
405 inline typename Foam::UIndirectList<T>::iterator
407 {
408  return iterator(completeList_, addressing_.end());
409 }
410 
411 
412 // * * * * * * * * * * * * * * * STL const_iterator * * * * * * * * * * * * //
413 
414 template<class T>
416 (
417  const UList<T>& l,
419 )
420 :
421  l_(l),
422  i_(i)
423 {}
424 
425 
426 template<class T>
428 (
429  const const_iterator& iter
430 ) const
431 {
432  return i_ == iter.i_;
433 }
434 
435 
436 template<class T>
438 (
439  const const_iterator& iter
440 ) const
441 {
442  return i_ != iter.i_;
443 }
444 
445 
446 template<class T>
448 {
449  return l_[*i_];
450 }
451 
452 
453 template<class T>
455 {
456  return operator*();
457 }
458 
459 
460 template<class T>
463 {
464  ++i_;
465  return *this;
466 }
467 
468 
469 template<class T>
472 {
473  const_iterator tmp = *this;
474  ++i_;
475  return tmp;
476 }
477 
478 
479 template<class T>
482 {
483  --i_;
484  return *this;
485 }
486 
487 
488 template<class T>
491 {
492  const_iterator tmp = *this;
493  --i_;
494  return tmp;
495 }
496 
497 
498 template<class T>
501 {
502  i_ += n;
503  return *this;
504 }
505 
506 
507 template<class T>
510 {
511  i_ -= n;
512  return *this;
513 }
514 
515 
516 template<class T>
519 {
520  typename UIndirectList<T>::const_iterator tmp = *this;
521  return tmp += n;
522 }
523 
524 
525 template<class T>
528 {
529  typename UIndirectList<T>::const_iterator tmp = *this;
530  return tmp -= n;
531 }
532 
533 
534 template<class T>
536 (
537  const typename UIndirectList<T>::const_iterator& iter
538 ) const
539 {
540  return i_ - iter.i_;
541 }
542 
543 
544 template<class T>
546 (
547  const label n
548 )
549 {
550  return *(*this + n);
551 }
552 
553 
554 template<class T>
556 (
557  const const_iterator& iter
558 ) const
559 {
560  return i_ < iter.i_;
561 }
562 
563 
564 template<class T>
566 (
567  const const_iterator& iter
568 ) const
569 {
570  return i_ > iter.i_;
571 }
572 
573 
574 template<class T>
576 (
577  const const_iterator& iter
578 ) const
579 {
580  return i_ <= iter.i_;
581 }
582 
583 
584 template<class T>
586 (
587  const const_iterator& iter
588 ) const
589 {
590  return i_ >= iter.i_;
591 }
592 
593 
594 template<class T>
597 {
598  return const_iterator(completeList_, addressing_.begin());
599 }
600 
601 
602 template<class T>
605 {
606  return const_iterator(completeList_, addressing_.end());
607 }
608 
609 
610 template<class T>
613 {
614  return const_iterator(completeList_, addressing_.begin());
615 }
616 
617 
618 template<class T>
621 {
622  return const_iterator(completeList_, addressing_.end());
623 }
624 
625 
626 // ************************************************************************* //
label n
#define forAll(list, i)
Loop across all elements in list.
Definition: UList.H:449
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: List.H:91
An STL-conforming const_iterator.
const_iterator(const UList< T > &, const UList< label >::const_iterator &)
Construct for a given UList and addressing iterator.
const_iterator operator-=(const label)
const_iterator operator-(const label) const
const_iterator operator+=(const label)
const_iterator operator+(const label) const
An STL-conforming iterator.
iterator operator-(const label) const
iterator operator+(const label) const
iterator(UList< T > &, const UList< label >::const_iterator &)
Construct for a given UList and addressing iterator.
iterator operator+=(const label)
iterator operator-=(const label)
A List with indirect addressing.
Definition: UIndirectList.H:61
UIndirectList(const UList< T > &, const UList< label > &)
Construct given the complete list and the addressing array.
T & first()
Return the first element of the list.
label rcIndex(const label i) const
Return the reverse circular index, i.e. the previous index.
const_iterator cbegin() const
Return an const_iterator to begin traversing the UIndirectList.
label size() const
Return the number of elements in the list.
label fcIndex(const label i) const
Return the forward circular index, i.e. the next index.
const_iterator cend() const
Return an const_iterator to end traversing the UIndirectList.
bool empty() const
Return true if the list is empty (ie, size() is zero).
const UList< T > & completeList() const
Return the complete list.
bool operator==(const UIndirectList< T > &) const
Equality comparison. Compares element-by-element.
T & operator[](const label)
Return non-const access to an element.
iterator begin()
Return an iterator to begin traversing the UIndirectList.
bool operator!=(const UIndirectList< T > &) const
Inequality comparison. Compares element-by-element.
void operator=(const UList< T > &)
Assignment to UList of addressed elements.
List< T > operator()() const
Return the addressed elements as a List.
iterator end()
Return an iterator to end traversing the UIndirectList.
T & last()
Return the last element of the list.
const List< label > & addressing() const
Return the list addressing.
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:74
label size() const
Return the number of elements in the UList.
Definition: UListI.H:311
iterator begin()
Return an iterator to begin traversing the UList.
Definition: UListI.H:216
iterator end()
Return an iterator to end traversing the UList.
Definition: UListI.H:224
A class for managing temporary objects.
Definition: tmp.H:55
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Definition: error.H:334
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
errorManip< error > abort(error &err)
Definition: errorManip.H:131
tmp< DimensionedField< Type, GeoMesh, Field > > operator*(const DimensionedField< Type, GeoMesh, PrimitiveField1 > &df1, const DimensionedField< scalar, GeoMesh, PrimitiveField2 > &df2)
error FatalError
void T(GeometricField< Type, GeoMesh, PrimitiveField1 > &gf, const GeometricField< Type, GeoMesh, PrimitiveField2 > &gf1)