UPtrList.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011-2016 OpenFOAM Foundation
9  Copyright (C) 2018-2023 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 Class
28  Foam::UPtrList
29 
30 Description
31  A list of pointers to objects of type <T>, without allocation/deallocation
32  management of the pointers - this is to be done elsewhere.
33  The operator[] returns a reference to the object (not the pointer).
34 
35  The iterators are similar to bitSet in that they skip nullptr entries,
36  and also return a value (like the list operator[] does).
37 
38  When traversing lists, it possible to test the validity directly:
39  \code
40  forAll(interfaces, i)
41  {
42  if (interfaces.test(i))
43  {
44  // Interface is set, do something
45  const auto& intf = interfaces[i];
46  ...
47  }
48  }
49  \endcode
50  The lists can also be traversed with a for-range
51  (in OpenFOAM-v2212 and earlier this would have failed on nullptr entries):
52  \code
53  for (const auto& intf : interfaces)
54  {
55  // Do something
56  ...
57  }
58  \endcode
59 
60  It is also possible to traverse with non-null entries
61  and use key/val access (like HashTable naming):
62  \code
63  forAllConstIters(interfaces, iter)
64  {
65  Info<< "entry " << iter.key() << " : " << iter.val() << nl;
66  }
67  \endcode
68 
69 Note
70  The class definition is such that it contains a list of pointers, but
71  itself does not inherit from a list of pointers since this would
72  wreak havoc later with inheritance resolution.
73 
74 See Also
75  Foam::PtrList
76  Foam::PtrDynList
77 
78 SourceFiles
79  UPtrListI.H
80  UPtrList.C
81 
82 \*---------------------------------------------------------------------------*/
83 
84 #ifndef Foam_UPtrList_H
85 #define Foam_UPtrList_H
86 
87 #include "PtrListDetail.H"
88 #include <iterator>
89 
90 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
91 
92 namespace Foam
93 {
94 
95 // Forward Declarations
96 template<class T> class PtrList;
97 template<class T> class UPtrList;
98 template<class T> Ostream& operator<<(Ostream& os, const UPtrList<T>& list);
99 
100 /*---------------------------------------------------------------------------*\
101  Class UPtrList Declaration
102 \*---------------------------------------------------------------------------*/
103 
104 template<class T>
105 class UPtrList
106 {
107 protected:
108 
109  // Protected Member Data
110 
111  //- The list of pointers
113 
114 
115  // Protected Member Functions
116 
117  //- Adjust addressable size
118  inline void setAddressableSize(const label n) noexcept;
119 
120  //- The next non-null entry after the specified position
121  inline label find_next(label pos) const;
122 
123 
124  // Constructors
125 
126  //- Low-level move construct
127  inline explicit UPtrList(Detail::PtrListDetail<T>&& ptrs) noexcept;
128 
129 
130 public:
131 
132  // STL type definitions
133 
134  //- Type of values the list contains
135  typedef T value_type;
136 
137  //- A non-const reference to the value_type
138  typedef T& reference;
139 
140  //- A const reference to the value_type
141  typedef const T& const_reference;
142 
143  //- Forward iterator with non-const access
144  class iterator;
146  //- Forward iterator with const access
147  class const_iterator;
148 
149 
150  // Public Classes
151 
152  //- A wrapper for a binary comparison of values that interjects
153  //- pointer dereferencing with null pointer guards.
154  // It will also sort any null pointers to the end
155  // (eg, rubbish that can be truncated)
156  template<class Compare>
157  struct value_compare
158  {
159  const Compare& comp;
160 
161  value_compare(const Compare& cmp)
162  :
163  comp(cmp)
164  {}
165 
166  //- Compare dereferenced pointers
167  bool operator()(const T* const a, const T* const b) const
168  {
169  return (a && b) ? comp(*a, *b) : !b;
170  }
171  };
172 
173  //- A UPtrList compare binary predicate for normal sort order.
174  //- Null entries (if any) sort to the end.
175  struct less
176  {
178 
179  less(const UPtrList<T>& list)
180  :
181  values(list)
182  {}
183 
184  //- Compare dereferenced pointer locations for normal sort.
185  bool operator()(const label ai, const label bi) const
186  {
187  const T* const a = values.get(ai);
188  const T* const b = values.get(bi);
189 
190  return (a && b) ? (*a < *b) : !b;
191  }
192  };
193 
194  //- A UPtrList compare binary predicate for reverse sort order.
195  // Null entries (if any) sort to the end.
196  struct greater
197  {
198  const UPtrList<T>& values;
200  greater(const UPtrList<T>& list)
201  :
202  values(list)
203  {}
204 
205  //- Compare dereferenced pointer locations for reverse sort
206  bool operator()(const label ai, const label bi) const
207  {
208  const T* const a = values.get(ai);
209  const T* const b = values.get(bi);
210 
211  return (a && b) ? (*b < *a) : !a;
212  }
213  };
214 
215 
216  // Constructors
217 
218  //- Default construct
219  constexpr UPtrList() noexcept = default;
220 
221  //- Construct with specified size and set all entries to \c nullptr
222  inline explicit UPtrList(const label len);
224  //- Copy construct (shallow copies addresses)
225  inline UPtrList(const UPtrList<T>& list);
226 
227  //- Move construct
228  inline UPtrList(UPtrList<T>&& list) noexcept;
229 
230  //- Construct as shallow copy or re-use as specified
231  inline UPtrList(UPtrList<T>& list, bool reuse);
232 
233  //- Shallow copy from PtrList.
234  // The argument is non-const to reflect that the UPtrList can change
235  // the values (not the addresses) within the original list.
236  explicit UPtrList(PtrList<T>& list);
237 
238  //- Construct from UList of pointers (shallow copy)
239  inline explicit UPtrList(const UList<T*>& list);
240 
241  //- Construct from UList, taking the address of each list element
242  // The argument is non-const to reflect that the UPtrList can change
243  // the values of the original list.
244  inline explicit UPtrList(UList<T>& list);
245 
246 
247  // Member Functions
248 
249  // Access
250 
251  //- True if the list is empty (ie, size() is zero)
252  inline bool empty() const noexcept;
253 
254  //- The number of entries in the list
255  inline label size() const noexcept;
256 
257  //- Size of the underlying storage.
258  inline label capacity() const noexcept;
259 
260  //- The number of non-null entries in the list
261  inline label count() const noexcept;
262 
263  //- Reference to the first element of the list
264  inline T& front();
265 
266  //- Reference to first element of the list
267  inline const T& front() const;
268 
269  //- Reference to the last element of the list
270  inline T& back();
271 
272  //- Reference to the last element of the list
273  inline const T& back() const;
274 
275  //- Return const pointer to element (can be nullptr),
276  //- or nullptr for out-of-range access (ie, \em with bounds checking).
277  // The return value can be tested as a bool.
278  inline const T* test(const label i) const;
279 
280  //- Return const pointer to element (can be nullptr),
281  //- or nullptr for out-of-range access (ie, \em with bounds checking).
282  // The return value can be tested as a bool.
283  inline const T* get(const label i) const;
284 
285  //- Return pointer to element (can be nullptr),
286  //- or nullptr for out-of-range access (ie, \em with bounds checking).
287  // The return value can be tested as a bool.
288  inline T* get(const label i);
289 
290  //- Return const pointer to element (can be nullptr),
291  //- or nullptr for out-of-range access (ie, \em with bounds checking).
292  // The return value can be tested as a bool.
293  const T* set(const label i) const { return this->get(i); }
294 
295 
296  // Edit
297 
298  //- Set list size to zero.
299  inline void clear();
300 
301  //- Nullify all entries. Does not change the list size.
302  inline void free();
303 
304  //- Change the size of the list.
305  //- Any new entries are \c nullptr.
306  inline void resize(const label newLen);
307 
308  //- Set the list to the given size
309  //- and set \em all entries to \c nullptr.
310  inline void resize_null(const label newLen);
311 
312  //- Squeeze out nullptr entries in the list of pointers after which
313  //- any null pointers will be at the end of the list
314  // \return the number of non-null entries
315  label squeezeNull();
316 
317  //- Reduce addressable list size to ignore any trailing null pointers.
318  // The reduces the effective list length without reallocation
319  void trimTrailingNull();
320 
321  //- Append an element to the end of the list
322  inline void push_back(T* ptr);
323 
324  //- Move append another list to the end of this list.
325  inline void push_back(UPtrList<T>&& other);
326 
327  //- Swap content
328  inline void swap(UPtrList<T>& list) noexcept;
329 
330  //- Transfer contents into this list and annul the argument
331  inline void transfer(UPtrList<T>& list);
332 
333  //- Set element to specified pointer and return the old list element,
334  //- which can be a nullptr.
335  // No-op if the new pointer value is identical to the current content.
336  inline T* set(const label i, T* ptr);
337 
338  //- Reorder elements.
339  //- Reordering must be unique (ie, shuffle).
340  // Optionally check that all pointers have been set.
341  void reorder(const labelUList& oldToNew, const bool check = false);
342 
343  //- Reorder elements according to new order mapping (newToOld).
344  //- Reordering must be unique (ie, shuffle).
345  // Optionally check that all pointers have been set.
346  void sortOrder(const labelUList& order, const bool check = false);
347 
348 
349  // Checks
350 
351  //- Check and raise FatalError if any nullptr exists in the list
352  inline void checkNonNull() const;
353 
354  //- Return const reference to the element at given position.
355  //- FatalError for bounds problem or nullptr.
356  inline const T& at(const label i) const;
357 
358  //- Return reference to the element at given position.
359  //- FatalError for bounds problem or nullptr.
360  inline T& at(const label i);
361 
362 
363  // Member Operators
364 
365  //- Return const reference to the element at given position.
366  //- FatalError for bounds problem or nullptr. Same as at().
367  inline const T& operator[](const label i) const;
368 
369  //- Return reference to the element at given position.
370  //- FatalError for bounds problem or nullptr. Same as at().
371  inline T& operator[](const label i);
372 
373  //- Deprecated(2022-09) - same as get()
374  // \deprecated(2022-09) - use get(), set() or test() methods
375  FOAM_DEPRECATED_FOR(2022-09, "get(), set() or test() methods")
376  const T* operator()(const label i) const { return this->get(i); }
377 
378  //- Copy assignment (shallow copies addresses)
379  inline void operator=(const UPtrList<T>& list);
380 
381  //- Move assignment
382  inline void operator=(UPtrList<T>&& list);
383 
384 
385  // IOstream Operators
386 
387  //- Write UPtrList to Ostream
388  friend Ostream& operator<< <T>(Ostream& os, const UPtrList<T>& list);
389 
390 
391 protected:
392 
393  // Iterators and helpers
394 
395  //- Internally used base for iterator and const_iterator
396  template<bool Const> class Iterator;
397 
398  //- Allow iterator access to internals
399  friend class Iterator<true>;
400 
401  //- Allow iterator access to internals
402  friend class Iterator<false>;
403 
404 
405  //- The iterator base for UPtrList (internal use only).
406  // Iterates non-nullptr entries.
407 
408  template<bool Const>
409  class Iterator
410  {
411  public:
412 
413  // Typedefs
414 
415  //- The list container type
416  using list_type = typename std::conditional
417  <
418  Const,
419  const UPtrList<T>,
421  >::type;
422 
423 
424  protected:
425 
426  // Protected Data
427 
428  //- The parent being iterated
429  // Uses pointer for default copy/assignment
430  list_type* list_;
431 
432  //- The position within the list
433  label pos_;
434 
435  // Friendship with UPtrList, for begin constructor
436  friend class UPtrList;
437 
438 
439  // Protected Constructors
440 
441  //- Default construct. Also the same as the end iterator
442  inline constexpr Iterator() noexcept;
443 
444  //- Construct begin iterator
445  inline explicit Iterator(list_type* list);
446 
447 
448  // Protected Member Functions
449 
450  //- Increment to the next non-null position
451  inline void increment();
452 
453  //- Permit explicit cast to the other (const/non-const) iterator
454  template<bool Any>
455  explicit operator const Iterator<Any>&() const
456  {
457  return *reinterpret_cast<const Iterator<Any>*>(this);
458  }
459 
460 
461  public:
462 
463  // Member Functions/Operators
464 
465  //- True if iterator points to a non-null entry
466  bool good() const noexcept { return (list_ && pos_ >= 0); }
467 
468  //- The iterator position/index within the list
469  label key() const noexcept { return pos_; }
470 
471  //- Compare hash-entry element pointers.
472  // Independent of const/non-const access
473  template<bool Any>
474  bool operator==(const Iterator<Any>& iter) const noexcept
475  {
476  return (pos_ == iter.pos_);
477  }
478 
479  template<bool Any>
480  bool operator!=(const Iterator<Any>& iter) const noexcept
481  {
482  return (pos_ != iter.pos_);
483  }
484  };
485 
486 
487 public:
488 
489  // Iterators
490 
491  //- Forward iterator with non-const access
492  class iterator : public Iterator<false>
493  {
494  public:
495  // using iterator_category = std::forward_iterator_tag;
496  // using difference_type = label;
497  using pointer = T*;
498  using reference = T&;
499 
500 
501  // Constructors
502 
503  //- Default construct - an end iterator
504  constexpr iterator() noexcept = default;
505 
506  //- Copy construct from similar access type
507  explicit iterator(const Iterator<false>& iter)
508  :
509  Iterator<false>(iter)
510  {}
511 
512 
513  // Member Functions/Operators
514 
515  //- Pointer to the referenced object (failsafe)
516  inline pointer get() const;
517 
518  //- Reference to the object
519  inline reference val() const;
520 
521  //- Pointer to the referenced object
522  pointer operator->() const { return this->get(); }
523 
524  //- Reference to the object
525  reference operator*() const { return this->val(); }
526 
527  //- Legacy call operator: reference to the object
528  reference operator()() const { return this->val(); }
529 
530  //- Move to the next non-nullptr entry
531  inline iterator& operator++();
532  inline iterator operator++(int);
533  };
534 
535 
536  //- Forward iterator with const access
537  class const_iterator : public Iterator<true>
538  {
539  public:
540  // using iterator_category = std::forward_iterator_tag;
541  // using difference_type = label;
542  using pointer = const T*;
543  using reference = const T&;
544 
545 
546  // Generated Methods
547 
548  //- Default construct (end iterator)
549  const_iterator() = default;
550 
551  //- Copy construct
552  const_iterator(const const_iterator&) = default;
553 
554  //- Copy assignment
556 
557 
558  // Constructors
559 
560  //- Copy construct from any access type
561  template<bool Any>
562  const_iterator(const Iterator<Any>& iter)
563  :
564  Iterator<true>(static_cast<const Iterator<Any>&>(iter))
565  {}
566 
567  //- Implicit conversion from dissimilar access type
568  const_iterator(const iterator& iter)
569  :
570  const_iterator(reinterpret_cast<const const_iterator&>(iter))
571  {}
573 
574  // Member Functions/Operators
576  //- Pointer to the referenced object (failsafe)
577  inline pointer get() const;
578 
579  //- Reference to the object
580  inline reference val() const;
581 
582  //- Pointer to the referenced object
583  pointer operator->() const { return this->get(); }
584 
585  //- Reference to the object
586  reference operator*() const { return this->val(); }
587 
588  //- Legacy call operator: reference to the object
589  reference operator()() const { return this->val(); }
590 
591  //- Move to the next non-nullptr entry
592  inline const_iterator& operator++();
593  inline const_iterator operator++(int);
594  };
595 
596 
597  //- Iterator to begin of raw pointers traversal (use with caution)
598  T** begin_ptr() noexcept { return ptrs_.begin(); }
599 
600  //- Iterator beyond end of raw pointers traversal (use with caution)
601  T** end_ptr() noexcept { return ptrs_.end(); }
603 
604  //- Return iterator to begin traversal of non-nullptr entries.
605  inline iterator begin();
606 
607  //- Return iterator beyond end of UPtrList traversal
608  inline iterator end() noexcept;
609 
610  //- Return const_iterator to begin traversal of non-nullptr entries.
611  inline const_iterator cbegin() const;
612 
613  //- Return const_iterator beyond end of UPtrList traversal
614  inline const_iterator cend() const noexcept;
616  //- Return const_iterator to begin traversal of non-nullptr entries.
617  inline const_iterator begin() const;
618 
619  //- Return const_iterator beyond end of UPtrList traversal
620  inline const_iterator end() const noexcept;
621 
622 
623  // Housekeeping
624 
625  //- Alias for resize()
626  void setSize(const label n) { this->resize(n); }
627 
628  //- Reference to the first element of the list
629  //FOAM_DEPRECATED_FOR(2022-10, "front()")
630  T& first() { return front(); }
631 
632  //- Return reference to first element of the list
633  //FOAM_DEPRECATED_FOR(2022-10, "front()")
634  const T& first() const { return front(); }
635 
636  //- Return reference to the last element of the list
637  //FOAM_DEPRECATED_FOR(2022-10, "back()")
638  T& last() { return back(); }
639 
640  //- Return reference to the last element of the list
641  //FOAM_DEPRECATED_FOR(2022-10, "back()")
642  const T& last() const{ return back(); }
643 
644  //- Append an element to the end of the list
645  //FOAM_DEPRECATED_FOR(2022-10, "push_back()")
646  void append(T* ptr) { this->push_back(ptr); }
647 
648  //- Move append another list to the end of this list.
649  //FOAM_DEPRECATED_FOR(2022-10, "push_back()")
650  void append(UPtrList<T>&& other) { this->push_back(std::move(other)); }
651 };
652 
654 // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
655 
656 //- Inplace (stable) sorting of pointer list.
657 // This sort function includes null pointer guards and will also sort
658 // any null pointers to the end (eg, rubbish that can be truncated)
659 template<class T>
660 void sort(UPtrList<T>& list);
661 
662 //- Inplace (stable) sorting of pointer list using given comparator,
663 //- which compares objects, not pointers.
664 // This sort function includes null pointer guards and will also sort
665 // any null pointers to the end (eg, rubbish that can be truncated)
666 template<class T, class Compare>
667 void sort(UPtrList<T>& list, const Compare& comp);
668 
669 
670 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
671 
672 } // End namespace Foam
673 
674 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
675 
676 #include "UPtrListI.H"
677 
678 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
679 
680 #ifdef NoRepository
681  #include "UPtrList.C"
682 #endif
683 
684 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
685 
686 #endif
687 
688 // ************************************************************************* //
reference val() const
Reference to the object.
Definition: UPtrListI.H:387
list_type * list_
The parent being iterated.
Definition: UPtrList.H:567
const T & operator[](const label i) const
Return const reference to the element at given position. FatalError for bounds problem or nullptr...
Definition: UPtrListI.H:289
const T * test(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: UPtrListI.H:127
label key() const noexcept
The iterator position/index within the list.
Definition: UPtrList.H:620
T & last()
Return reference to the last element of the list.
Definition: UPtrList.H:861
T & reference
A non-const reference to the value_type.
Definition: UPtrList.H:145
constexpr iterator() noexcept=default
Default construct - an end iterator.
typename std::conditional< Const, const UPtrList< T >, UPtrList< T > >::type list_type
The list container type.
Definition: UPtrList.H:555
T & back()
Reference to the last element of the list.
Definition: UPtrListI.H:237
void swap(UPtrList< T > &list) noexcept
Swap content.
Definition: UPtrListI.H:209
void append(T *ptr)
Append an element to the end of the list.
Definition: UPtrList.H:875
iterator & operator++()
Move to the next non-nullptr entry.
Definition: UPtrListI.H:360
A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementati...
Definition: PtrListDetail.H:57
FOAM_DEPRECATED_FOR(2022-09, "get(), set() or test() methods") const T *operator()(const label i) const
Deprecated(2022-09) - same as get()
Definition: UPtrList.H:492
void reorder(const labelUList &oldToNew, const bool check=false)
Reorder elements. Reordering must be unique (ie, shuffle).
Definition: UPtrList.C:79
const_iterator & operator++()
Move to the next non-nullptr entry.
Definition: UPtrListI.H:395
constexpr UPtrList() noexcept=default
Default construct.
T ** begin_ptr() noexcept
Iterator to begin of raw pointers traversal (use with caution)
Definition: UPtrList.H:796
T & first()
Reference to the first element of the list.
Definition: UPtrList.H:847
const T * get(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: UPtrListI.H:134
const T & at(const label i) const
Return const reference to the element at given position. FatalError for bounds problem or nullptr...
Definition: UPtrListI.H:148
T & front()
Reference to the first element of the list.
Definition: UPtrListI.H:223
const UPtrList< T > & values
Definition: UPtrList.H:197
reference operator()() const
Legacy call operator: reference to the object.
Definition: UPtrList.H:783
Forward iterator with const access.
Definition: UPtrList.H:711
greater(const UPtrList< T > &list)
Definition: UPtrList.H:225
label pos_
The position within the list.
Definition: UPtrList.H:572
Forward iterator with non-const access.
Definition: UPtrList.H:648
Internally used base for iterator and const_iterator.
Definition: UPtrList.H:521
label capacity() const noexcept
Size of the underlying storage.
Definition: UPtrListI.H:113
dimensionedScalar pos(const dimensionedScalar &ds)
fileName::Type type(const fileName &name, const bool followLink=true)
Return the file type: DIRECTORY or FILE, normally following symbolic links.
Definition: POSIX.C:799
void free()
Nullify all entries. Does not change the list size.
Definition: UPtrListI.H:202
constexpr Iterator() noexcept
Default construct. Also the same as the end iterator.
Definition: UPtrListI.H:307
T value_type
Type of values the list contains.
Definition: UPtrList.H:140
reference operator*() const
Reference to the object.
Definition: UPtrList.H:693
const T & const_reference
A const reference to the value_type.
Definition: UPtrList.H:150
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
void push_back(T *ptr)
Append an element to the end of the list.
Definition: UPtrListI.H:265
less(const UPtrList< T > &list)
Definition: UPtrList.H:199
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:296
pointer operator->() const
Pointer to the referenced object.
Definition: UPtrList.H:688
label size() const noexcept
The number of entries in the list.
Definition: UPtrListI.H:106
void checkNonNull() const
Check and raise FatalError if any nullptr exists in the list.
Definition: UPtrListI.H:280
void transfer(UPtrList< T > &list)
Transfer contents into this list and annul the argument.
Definition: UPtrListI.H:216
reference val() const
Reference to the object.
Definition: UPtrListI.H:352
bool operator()(const label ai, const label bi) const
Compare dereferenced pointer locations for reverse sort.
Definition: UPtrList.H:233
T ** end_ptr() noexcept
Iterator beyond end of raw pointers traversal (use with caution)
Definition: UPtrList.H:801
friend Ostream & operator(Ostream &os, const UPtrList< T > &list)
Write UPtrList to Ostream.
void resize(const label newLen)
Change the size of the list. Any new entries are nullptr.
Definition: UPtrListI.H:251
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: HashTable.H:106
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:105
bool operator==(const Iterator< Any > &iter) const noexcept
Compare hash-entry element pointers.
Definition: UPtrList.H:628
An Ostream is an abstract base class for all output systems (streams, files, token lists...
Definition: Ostream.H:56
const direction noexcept
Definition: Scalar.H:258
OBJstream os(runTime.globalPath()/outputName)
bool operator()(const T *const a, const T *const b) const
Compare dereferenced pointers.
Definition: UPtrList.H:185
static void check(const int retVal, const char *what)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void trimTrailingNull()
Reduce addressable list size to ignore any trailing null pointers.
Definition: UPtrList.C:62
void operator=(const UPtrList< T > &list)
Copy assignment (shallow copies addresses)
Definition: UPtrListI.H:465
const UPtrList< T > & values
Definition: UPtrList.H:223
label find_next(label pos) const
The next non-null entry after the specified position.
Definition: UPtrListI.H:32
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
Definition: UPtrListI.H:99
iterator begin()
Return iterator to begin traversal of non-nullptr entries.
Definition: UPtrListI.H:416
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
Definition: List.H:55
iterator end() noexcept
Return iterator beyond end of UPtrList traversal.
Definition: UPtrListI.H:440
reference operator()() const
Legacy call operator: reference to the object.
Definition: UPtrList.H:698
label n
const_iterator cend() const noexcept
Return const_iterator beyond end of UPtrList traversal.
Definition: UPtrListI.H:456
bool good() const noexcept
True if iterator points to a non-null entry.
Definition: UPtrList.H:615
reference operator*() const
Reference to the object.
Definition: UPtrList.H:778
const_iterator & operator=(const const_iterator &)=default
Copy assignment.
pointer operator->() const
Pointer to the referenced object.
Definition: UPtrList.H:773
void clear()
Set list size to zero.
Definition: UPtrListI.H:195
void setSize(const label n)
Alias for resize()
Definition: UPtrList.H:840
const_iterator cbegin() const
Return const_iterator to begin traversal of non-nullptr entries.
Definition: UPtrListI.H:432
bool operator!=(const Iterator< Any > &iter) const noexcept
Definition: UPtrList.H:634
void resize_null(const label newLen)
Set the list to the given size and set all entries to nullptr.
Definition: UPtrListI.H:258
label squeezeNull()
Squeeze out nullptr entries in the list of pointers after which any null pointers will be at the end ...
Definition: UPtrList.C:38
Detail::PtrListDetail< T > ptrs_
The list of pointers.
Definition: UPtrList.H:109
void setAddressableSize(const label n) noexcept
Adjust addressable size.
Definition: UPtrListI.H:25
A UPtrList compare binary predicate for reverse sort order.
Definition: UPtrList.H:221
label count() const noexcept
The number of non-null entries in the list.
Definition: UPtrListI.H:120
Namespace for OpenFOAM.
value_compare(const Compare &cmp)
Definition: UPtrList.H:177
friend class Iterator< false >
Allow iterator access to internals.
Definition: UPtrList.H:531
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
Definition: UPtrList.H:366
const_iterator()=default
Default construct (end iterator)
void sortOrder(const labelUList &order, const bool check=false)
Reorder elements according to new order mapping (newToOld). Reordering must be unique (ie...
Definition: UPtrList.C:128
void increment()
Increment to the next non-null position.
Definition: UPtrListI.H:333
A UPtrList compare binary predicate for normal sort order. Null entries (if any) sort to the end...
Definition: UPtrList.H:195