UList.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) 2017-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::UList
29 
30 Description
31  A 1D vector of objects of type <T>, where the size of the vector is
32  known and can be used for subscript bounds checking, etc.
33 
34  Storage is not allocated during construction or use but is supplied to
35  the constructor as an argument. This type of list is particularly useful
36  for lists that refer to parts of existing lists such as SubList.
37 
38 SourceFiles
39  UList.C
40  UListI.H
41  UListIO.C
42 
43 \*---------------------------------------------------------------------------*/
44 
45 #ifndef Foam_UList_H
46 #define Foam_UList_H
47 
48 #include "bool.H"
49 #include "label.H"
50 #include "uLabel.H"
51 #include "zero.H"
52 #include "one.H"
53 #include "contiguous.H"
54 #include "stdFoam.H"
55 #include "nullObject.H"
56 #include "Hash.H"
57 #include "ListPolicy.H"
58 
59 #include <iterator>
60 #include <vector> // i.e, std::vector
61 
62 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
63 
64 namespace Foam
65 {
66 
67 // Forward Declarations
68 class labelRange;
69 
70 template<class T> class List;
71 template<class T> class SubList;
72 template<class T> class UList;
73 template<class T> class IndirectList;
74 template<class T> class UIndirectList;
75 template<class T, class Addr> class IndirectListBase;
76 
77 template<class T> Istream& operator>>(Istream&, UList<T>&);
78 template<class T> Ostream& operator<<(Ostream&, const UList<T>&);
79 
80 // Common list types
81 typedef UList<bool> boolUList;
82 typedef UList<char> charUList;
83 typedef UList<label> labelUList;
84 
85 
86 /*---------------------------------------------------------------------------*\
87  Class UList Declaration
88 \*---------------------------------------------------------------------------*/
89 
90 template<class T>
91 class UList
92 {
93  // Private Data
94 
95  //- Number of elements in UList
96  label size_;
97 
98  //- Vector of values of type T
99  T* __restrict__ v_;
100 
101 
102 protected:
103 
104  // Protected Member Functions
105 
106  //- Set addressed size to be inconsistent with allocated storage.
107  // Use with care
108  inline void setAddressableSize(const label n) noexcept;
109 
110  //- Older name for setAddressableSize
111  FOAM_DEPRECATED_FOR(2021-01, "setAddressableSize(label) method")
112  void size(const label n) { this->setAddressableSize(n); }
113 
114  //- Write the UList with its compound type
115  void writeEntry(Ostream& os) const;
117  //- Return a validated (start,size) subset range, which means that it
118  //- always addresses a valid section of the list.
119  labelRange validateRange(const labelRange& requestedRange) const;
120 
121  //- Assign all entries to the given value
122  // Caution: method name subject to change
123  inline void fill_uniform(const T& val);
124 
125  //- Assign all entries to zero
126  // Caution: method name subject to change
127  inline void fill_uniform(const Foam::zero);
128 
129  //- No copy assignment (default: shallow copy)
130  //
131  // Assignment may need to be shallow (copy pointer)
132  // or deep (copy elements) depending on context or type of list.
133  // Disallow default assignment and provide separate 'shallowCopy' and
134  // 'deepCopy' member functions.
135  UList<T>& operator=(const UList<T>&) = delete;
136 
137 public:
138 
139  // STL type definitions
140 
141  //- The value type the list contains
142  typedef T value_type;
143 
144  //- The pointer type for non-const access to value_type items
145  typedef T* pointer;
146 
147  //- The pointer type for const access to value_type items
148  typedef const T* const_pointer;
149 
150  //- The type used for storing into value_type objects
151  typedef T& reference;
152 
153  //- The type used for reading from constant value_type objects.
154  typedef const T& const_reference;
155 
156  //- Random access iterator for traversing a UList
157  typedef T* iterator;
158 
159  //- Random access iterator for traversing a UList
160  typedef const T* const_iterator;
162  //- The type to represent the size of a UList
163  typedef label size_type;
164 
165  //- The difference between iterator objects
166  typedef label difference_type;
167 
168  //- Reverse iterator (non-const access)
169  typedef std::reverse_iterator<iterator> reverse_iterator;
170 
171  //- Reverse iterator (const access)
172  typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
173 
174 
175  // Related types
177  //- Declare friendship with the List class
178  friend class List<T>;
179 
180  //- Declare friendship with the SubList class
181  friend class SubList<T>;
182 
183 
184  // Static Functions
185 
186  //- Return a null UList (reference to a nullObject).
187  //- Behaves like an empty UList.
188  static const UList<T>& null() noexcept
189  {
190  return NullObjectRef<UList<T>>();
191  }
192 
193 
194  // Public Classes
195 
196  //- A list compare binary predicate for normal sort
197  struct less
198  {
199  const UList<T>& values;
200 
201  less(const UList<T>& list)
202  :
203  values(list)
204  {}
205 
206  bool operator()(const label a, const label b) const
207  {
208  return (values[a] < values[b]);
209  }
210  };
212  //- A list compare binary predicate for reverse sort
213  struct greater
214  {
215  const UList<T>& values;
216 
217  greater(const UList<T>& list)
218  :
219  values(list)
220  {}
221 
222  bool operator()(const label a, const label b) const
223  {
224  return (values[b] < values[a]);
225  }
226  };
227 
228 
229  // Generated Methods
230 
231  //- Copy construct
232  UList(const UList<T>&) = default;
234 
235  // Constructors
236 
237  //- Default construct, zero-sized and nullptr
238  inline constexpr UList() noexcept;
239 
240  //- Construct from components
241  inline UList(T* __restrict__ v, const label len) noexcept;
242 
243 
244  // Member Functions
245 
246  // Access
247 
248  //- The forward circular index. The next index in the list
249  //- which returns to the first at the end of the list
250  inline label fcIndex(const label i) const noexcept;
251 
252  //- The reverse circular index. The previous index in the list
253  //- which returns to the last at the beginning of the list
254  inline label rcIndex(const label i) const noexcept;
255 
256  //- Return forward circular value (ie, next value in the list)
257  inline const T& fcValue(const label i) const;
258 
259  //- Return forward circular value (ie, next value in the list)
260  inline T& fcValue(const label i);
261 
262  //- Return reverse circular value (ie, previous value in the list)
263  inline const T& rcValue(const label i) const;
265  //- Return reverse circular value (ie, previous value in the list)
266  inline T& rcValue(const label i);
267 
268  //- Return pointer to the underlying array serving as data storage.
269  inline const T* cdata() const noexcept;
270 
271  //- Return pointer to the underlying array serving as data storage.
272  inline T* data() noexcept;
273 
274  //- Return pointer to the underlying array serving as data storage,
275  // reinterpreted as byte data
276  // \note Only meaningful for contiguous data
277  inline const char* cdata_bytes() const noexcept;
278 
279  //- Return pointer to the underlying array serving as data storage,
280  // reinterpreted as byte data
281  // \note Only meaningful for contiguous data
282  inline char* data_bytes() noexcept;
283 
284  //- Access first element of the list, position [0]
285  inline T& front();
286 
287  //- Access first element of the list
288  inline const T& front() const;
289 
290  //- Access last element of the list, position [size()-1]
291  inline T& back();
292 
293  //- Access last element of the list, position [size()-1]
294  inline const T& back() const;
295 
296  //- Number of contiguous bytes for the List data.
297  // \note Only meaningful for contiguous data
298  inline std::streamsize size_bytes() const noexcept;
299 
300  //- Number of contiguous bytes for the List data,
301  //- runtime FatalError if type is not contiguous
302  std::streamsize byteSize() const;
303 
304 
305  // Check
306 
307  //- Check start is within valid range [0,size)
308  inline void checkStart(const label start) const;
309 
310  //- Check size is within valid range [0,size]
311  inline void checkSize(const label size) const;
312 
313  //- Check that start and length define a valid range
314  inline void checkRange(const label start, const label len) const;
315 
316  //- Check index is within valid range [0,size)
317  inline void checkIndex(const label i) const;
318 
319  //- True if all entries have identical values, and list is non-empty
320  inline bool uniform() const;
321 
322 
323  // Search
324 
325  //- True if the value is contained in the list.
326  inline bool contains(const T& val) const;
327 
328  //- Is the value contained in the list?
329  // \param val The value to search for
330  // \param pos The first position to examine (no-op if -ve)
331  // \param len The length of the search region (-ve until the end)
332  // \return true if found.
333  inline bool contains(const T& val, label pos, label len = -1) const;
334 
335  //- Find index of the first occurrence of the value.
336  // \param val The value to search for
337  // \return position in list or -1 if not found.
338  label find(const T& val) const;
339 
340  //- Find index of the first occurrence of the value.
341  // \param val The value to search for
342  // \param pos The first position to examine (no-op if -ve)
343  // \param len The length of the search region (-ve until the end)
344  // \return position in list or -1 if not found.
345  label find(const T& val, label pos, label len = -1) const;
346 
347  //- Find index of the last occurrence of the value.
348  // Any occurrences after the end pos are ignored.
349  // Linear search.
350  // \return position in list or -1 if not found.
351  label rfind(const T& val, label pos = -1) const;
352 
353 
354  // Edit
355 
356  //- Move element to the first position.
357  void moveFirst(const label i);
358 
359  //- Move element to the last position.
360  void moveLast(const label i);
361 
362  //- Swap element with the first element. Fatal on an empty list.
363  void swapFirst(const label i);
364 
365  //- Swap element with the last element. Fatal on an empty list.
366  void swapLast(const label i);
367 
368 
369  // Copy
370 
371  //- Copy the pointer and size
372  inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept;
373 
374  //- Copy nullptr and zero size
375  inline void shallowCopy(std::nullptr_t) noexcept;
376 
377  //- Copy the pointer and size held by the given UList
378  inline void shallowCopy(const UList<T>& list) noexcept;
379 
380  //- Copy elements of the given UList. Sizes must match!
381  void deepCopy(const UList<T>& list);
382 
383  //- Copy elements of the given indirect list. Sizes must match!
384  template<class Addr>
385  void deepCopy(const IndirectListBase<T, Addr>& list);
386 
387 
388  // Other Access
389 
390  //- Return SubList slice (non-const access) - no range checking
391  SubList<T> slice(const label pos, label len = -1);
392 
393  //- Return SubList slice (const access) - no range checking
394  const SubList<T> slice(const label pos, label len = -1) const;
395 
396  //- Return SubList slice (non-const access) - with range checking.
397  // The range is subsetted with the list size itself to ensure that the
398  // result always addresses a valid section of the list.
399  SubList<T> slice(const labelRange& range);
400 
401  //- Return SubList slice (const access) - with range checking.
402  // The range is subsetted with the list size itself to ensure that the
403  // result always addresses a valid section of the list.
404  const SubList<T> slice(const labelRange& range) const;
405 
406 
407  // Member Operators
408 
409  //- Return element of UList
410  inline T& operator[](const label i);
411 
412  //- Return element of constant UList
413  // \note bool specialization adds lazy evaluation so reading an
414  // out-of-range element returns false without ill-effects
415  inline const T& operator[](const label i) const;
416 
417  //- Allow cast to a const List<T>&
418  inline operator const Foam::List<T>&() const;
419 
420  //- Assignment of all entries to the given value
421  inline void operator=(const T& val);
422 
423  //- Assignment of all entries to zero
424  void operator=(const Foam::zero);
425 
426 
427  // Random access iterator (non-const)
428 
429  //- Return an iterator to begin traversing the UList
430  inline iterator begin() noexcept;
431 
432  //- Return an iterator to end traversing the UList
433  inline iterator end() noexcept;
434 
435  //- Return iterator at offset i from begin,
436  //- clamped to [0,size] range
437  inline iterator begin(const label i) noexcept;
438 
439 
440  // Random access iterator (const)
441 
442  //- Return const_iterator to begin traversing the constant UList
443  inline const_iterator cbegin() const noexcept;
444 
445  //- Return const_iterator to end traversing the constant UList
446  inline const_iterator cend() const noexcept;
447 
448  //- Return const_iterator to begin traversing the constant UList
449  inline const_iterator begin() const noexcept;
450 
451  //- Return const_iterator to end traversing the constant UList
452  inline const_iterator end() const noexcept;
453 
454  //- Return const_iterator at offset i from begin,
455  //- clamped to [0,size] range
456  inline const_iterator cbegin(const label i) const noexcept;
457 
458  //- Return const_iterator at offset i from begin,
459  //- clamped to [0,size] range
460  inline const_iterator begin(const label i) const noexcept;
461 
462 
463  // Reverse iterators (non-const)
464 
465  //- Return reverse_iterator to begin reverse traversing the UList
466  inline reverse_iterator rbegin();
467 
468  //- Return reverse_iterator to end reverse traversing the UList
469  inline reverse_iterator rend();
470 
471 
472  // Reverse iterators (const)
473 
474  //- Return const_reverse_iterator to begin reverse traversing the UList
475  inline const_reverse_iterator crbegin() const;
476 
477  //- Return const_reverse_iterator to end reverse traversing the UList
478  inline const_reverse_iterator crend() const;
479 
480  //- Return const_reverse_iterator to begin reverse traversing the UList
481  inline const_reverse_iterator rbegin() const;
482 
483  //- Return const_reverse_iterator to end reverse traversing the UList
484  inline const_reverse_iterator rend() const;
485 
486 
487  // STL member functions
488 
489  //- True if List is empty (ie, size() is zero)
490  bool empty() const noexcept { return !size_; }
491 
492  //- The number of elements in the container
493  label size() const noexcept { return size_; }
494 
495  //- Size of the underlying storage.
496  label capacity() const noexcept { return size_; }
497 
498  //- The size of the largest possible UList
499  static constexpr label max_size() noexcept { return labelMax; }
500 
501  //- Swap content with another UList of the same type in constant time
502  inline void swap(UList<T>& list) noexcept;
503 
504 
505  // STL member operators
506 
507  //- Equality operation on ULists of the same type.
508  // Returns true when the ULists are element-wise equal
509  // (using UList::value_type::operator==). Takes linear time
510  bool operator==(const UList<T>& list) const;
511 
512  //- The opposite of the equality operation. Takes linear time
513  bool operator!=(const UList<T>& list) const;
514 
515  //- Compare two ULists lexicographically. Takes linear time
516  bool operator<(const UList<T>& list) const;
517 
518  //- Compare two ULists lexicographically. Takes linear time
519  bool operator>(const UList<T>& list) const;
520 
521  //- Return true if !(a > b). Takes linear time
522  bool operator<=(const UList<T>& list) const;
523 
524  //- Return true if !(a < b). Takes linear time
525  bool operator>=(const UList<T>& list) const;
526 
527 
528  // Reading/writing
529 
530  //- Read List contents from Istream.
531  // The List must have the proper size before calling
532  Istream& readList(Istream& is);
533 
534  //- Write the List as a dictionary entry with keyword
535  void writeEntry(const word& keyword, Ostream& os) const;
536 
537  //- Write List, with line-breaks in ASCII when length exceeds shortLen.
538  // Using '0' suppresses line-breaks entirely.
539  Ostream& writeList(Ostream& os, const label shortLen=0) const;
540 
541 
542  // IOstream Operators
543 
544  //- Use the readList() method to read contents from Istream.
545  friend Istream& operator>> <T>
546  (
547  Istream& os,
548  UList<T>& list
549  );
550 
551 
552  // Special Methods
553 
554  //- Test \c bool value at specified position,
555  //- always false for out-of-range access.
556  // \note Method name compatibility with bitSet, HashSet
557  template<class TypeT = T>
558  typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
559  inline test(const label i) const
560  {
561  return (i >= 0 && i < size_ && v_[i]);
562  }
563 
564  //- Return \c bool value at specified position,
565  //- always false for out-of-range access.
566  // \note Method name compatibility with bitSet
567  template<class TypeT = T>
568  typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
569  inline get(const label i) const
570  {
571  return (i >= 0 && i < size_ && v_[i]);
572  }
573 
574  //- Unset the \c bool entry at specified position,
575  //- always false for out-of-range access.
576  // \return True if value changed and was not out-of-range
577  // \note Method name compatibility with bitSet
578  template<class TypeT = T>
579  typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
580  inline unset(const label i)
581  {
582  if (i >= 0 && i < size_ && v_[i])
583  {
584  v_[i] = false;
585  return true;
586  }
587  return false;
588  }
589 
590 
591  // Hashing
592 
593  //- Hashing functor for UList
594  struct hasher
595  {
596  inline unsigned operator()
597  (
598  const UList<T>& obj,
599  unsigned seed=0
600  ) const
601  {
602  if (is_contiguous<T>::value)
603  {
604  return Foam::Hasher(obj.cdata(), obj.size_bytes(), seed);
605  }
606 
607  Foam::Hash<T> op;
608  for (const T& val : obj)
609  {
610  seed = op(val, seed);
611  }
612  return seed;
613  }
614  };
615 
616  //- Deprecated(2021-04) hashing functor. Use hasher()
617  // \deprecated(2021-04) - use hasher() functor
618  template<class Unused=bool>
619  struct Hash : UList<T>::hasher
620  {
621  FOAM_DEPRECATED_FOR(2021-04, "hasher()") Hash() {}
622  };
623 
624 
625  // Housekeeping
626 
627  //- Access first element of the list, position [0]
628  //FOAM_DEPRECATED_FOR(2022-10, "front()")
629  T& first() { return front(); }
630 
631  //- Access first element of the list
632  //FOAM_DEPRECATED_FOR(2022-10, "front()")
633  const T& first() const { return front(); };
634 
635  //- Access last element of the list, position [size()-1]
636  //FOAM_DEPRECATED_FOR(2022-10, "back()")
637  T& last() { return back(); }
638 
639  //- Access last element of the list, position [size()-1]
640  //FOAM_DEPRECATED_FOR(2022-10, "back()")
641  const T& last() const { return back(); };
642 
643  //- Same as contains()
644  bool found(const T& val, label pos = 0) const
645  {
646  return this->contains(val, pos);
647  }
648 };
649 
650 
651 // * * * * * * * * * * * * Template Specializations * * * * * * * * * * * * //
652 
653 //- Character list writeEntry
654 template<>
655 void UList<char>::writeEntry(Ostream& os) const;
656 
657 //- Character list assign zero - avoids Foam::zero casting ambiguities
658 template<>
660 
661 
662 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
663 
664 //- Read List contents from Istream, list must have the proper size!
665 template<class T>
666 Istream& operator>>(Istream& is, UList<T>& list)
667 {
668  return list.readList(is);
669 }
670 
671 
672 //- Write List to Ostream, as per UList::writeList() with default length.
673 // The default short-length is given by Detail::ListPolicy::short_length
674 template<class T>
675 Ostream& operator<<(Ostream& os, const UList<T>& list)
676 {
677  return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
678 }
679 
680 //- Write std::vector to Ostream. ASCII only, no line-breaks
681 template<class T>
682 Ostream& operator<<(Ostream& os, const std::vector<T>& list);
683 
684 
685 // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
686 
687 //- Fill an identity map with (map[i] == i), works like std::iota().
688 // Optionally with an alternative start index, so that (map[i] == i+start)
689 void identity(UList<int32_t>& map, int32_t start = 0);
691 //- Fill an identity map with (map[i] == i), works like std::iota().
692 // Optionally with an alternative start index, so that (map[i] == i+start)
693 void identity(UList<int64_t>& map, int64_t start = 0);
694 
695 //- Sort the list
696 template<class T>
697 void sort(UList<T>& list);
698 
699 //- Sort the list with the specified comparator
700 template<class T, class Compare>
701 void sort(UList<T>& list, const Compare& comp);
702 
703 //- Stable sort the list
704 template<class T>
705 void stableSort(UList<T>& list);
706 
707 //- Stable sort the list with the specified comparator
708 template<class T, class Compare>
709 void stableSort(UList<T>& list, const Compare& comp);
710 
711 //- Randomise the list order
712 template<class T>
713 void shuffle(UList<T>& list);
714 
715 //- Reverse the first n elements of the list
716 template<class T>
717 inline void reverse(UList<T>& list, const label n);
718 
719 //- Reverse all elements of the list
720 template<class T>
721 inline void reverse(UList<T>& list);
722 
723 
724 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
725 
726 //- Hashing for List data
727 template<class T>
728 struct Hash<UList<T>> : UList<T>::hasher {};
729 
730 
731 //- Object access operator or list access operator (default is pass-through)
732 //- \sa ListListOps::combine()
733 template<class T>
734 struct accessOp
735 {
736  const T& operator()(const T& obj) const { return obj; }
737 };
738 
739 
740 //- Test if object is empty, typically using its empty() method.
741 template<class T>
742 struct emptyOp
743 {
744  bool operator()(const T& obj) const { return obj.empty(); }
745 };
746 
747 
748 //- Extract size (as label) from an object, typically using its size() method.
749 template<class T>
750 struct sizeOp
751 {
752  label operator()(const T& obj) const { return obj.size(); }
753 };
754 
755 
756 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
757 
758 } // End namespace Foam
759 
760 
761 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
762 
763 // Does not need std::swap or Foam::Swap() specialization
764 // since UList is MoveConstructible and MoveAssignable
765 
766 
767 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
768 
769 #include "UListI.H"
770 
771 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
772 
773 #ifdef NoRepository
774  #include "UList.C"
775  #include "UListIO.C"
776  #include "stdVectorIO.C"
777 #endif
779 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
780 
781 #endif
782 
783 // ************************************************************************* //
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
Definition: UListI.H:506
std::reverse_iterator< const_iterator > const_reverse_iterator
Reverse iterator (const access)
Definition: UList.H:211
const_iterator cend() const noexcept
Return const_iterator to end traversing the constant UList.
Definition: UListI.H:450
T * pointer
The pointer type for non-const access to value_type items.
Definition: UList.H:166
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type unset(const label i)
Unset the bool entry at specified position, always false for out-of-range access. ...
Definition: UList.H:805
FOAM_DEPRECATED_FOR(2021-04, "hasher()") Hash()
Definition: UList.H:851
void swapLast(const label i)
Swap element with the last element. Fatal on an empty list.
Definition: UList.C:84
label operator()(const T &obj) const
Definition: UList.H:1035
void swapFirst(const label i)
Swap element with the first element. Fatal on an empty list.
Definition: UList.C:72
Number of items before requiring line-breaks in the list output.
Definition: ListPolicy.H:57
bool operator()(const label a, const label b) const
Definition: UList.H:253
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:56
const_reverse_iterator crbegin() const
Return const_reverse_iterator to begin reverse traversing the UList.
Definition: UListI.H:471
A range or interval of labels defined by a start and a size.
Definition: labelRange.H:52
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
Definition: Istream.H:57
const T * const_pointer
The pointer type for const access to value_type items.
Definition: UList.H:171
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition: UList.H:675
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:265
T & front()
Access first element of the list, position [0].
Definition: UListI.H:230
T & first()
Access first element of the list, position [0].
Definition: UList.H:862
Object access operator or list access operator (default is pass-through)
Definition: UList.H:1013
bool found(const T &val, label pos=0) const
Same as contains()
Definition: UList.H:888
T * iterator
Random access iterator for traversing a UList.
Definition: UList.H:186
void stableSort(UList< T > &list)
Stable sort the list.
Definition: UList.C:312
labelRange validateRange(const labelRange &requestedRange) const
Return a validated (start,size) subset range, which means that it always addresses a valid section of...
Definition: UList.C:32
void setAddressableSize(const label n) noexcept
Set addressed size to be inconsistent with allocated storage.
Definition: UListI.H:499
Base for lists with indirect addressing, templated on the list contents type and the addressing type...
UList< bool > boolUList
A UList of bools.
Definition: UList.H:76
bool contains(const T &val) const
True if the value is contained in the list.
Definition: UListI.H:293
static bool less(const vector &x, const vector &y)
To compare normals.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:279
Istream & readList(Istream &is)
Read List contents from Istream.
Definition: UListIO.C:179
scalar range
UList< label > labelUList
A UList of labels.
Definition: UList.H:78
class FOAM_DEPRECATED_FOR(2017-05, "Foam::Enum") NamedEnum
Definition: NamedEnum.H:65
const_reverse_iterator crend() const
Return const_reverse_iterator to end reverse traversing the UList.
Definition: UListI.H:492
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:272
label difference_type
The difference between iterator objects.
Definition: UList.H:201
label fcIndex(const label i) const noexcept
The forward circular index. The next index in the list which returns to the first at the end of the l...
Definition: UListI.H:90
reverse_iterator rbegin()
Return reverse_iterator to begin reverse traversing the UList.
Definition: UListI.H:457
UList< T > & operator=(const UList< T > &)=delete
No copy assignment (default: shallow copy)
reverse_iterator rend()
Return reverse_iterator to end reverse traversing the UList.
Definition: UListI.H:478
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
Ostream & writeList(Ostream &os, const label shortLen=0) const
Write List, with line-breaks in ASCII when length exceeds shortLen.
Definition: UListIO.C:76
A List obtained as a section of another List.
Definition: SubList.H:50
const UList< T > & values
Definition: UList.H:246
void fill_uniform(const T &val)
Assign all entries to the given value.
Definition: UListI.H:46
const T & fcValue(const label i) const
Return forward circular value (ie, next value in the list)
Definition: UListI.H:104
label capacity() const noexcept
Size of the underlying storage.
Definition: UList.H:685
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
Definition: SubList.H:250
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i), works like std::iota() but returning a...
Definition: labelLists.C:44
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
void sort(UList< T > &list)
Sort the list.
Definition: UList.C:296
Istream & operator>>(Istream &, directionInfo &)
bool operator==(const UList< T > &list) const
Equality operation on ULists of the same type.
Definition: UList.C:238
bool operator!=(const UList< T > &list) const
The opposite of the equality operation. Takes linear time.
Definition: UList.C:252
label rfind(const T &val, label pos=-1) const
Find index of the last occurrence of the value.
Definition: UList.C:212
void reverse(UList< T > &list, const label n)
Reverse the first n elements of the list.
Definition: UListI.H:521
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator (non-const access)
Definition: UList.H:206
bool operator()(const T &obj) const
Definition: UList.H:1025
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:392
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
label find(const T &val) const
Find index of the first occurrence of the value.
Definition: UList.C:173
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
UList< char > charUList
A UList of chars.
Definition: UList.H:77
label size() const noexcept
The number of elements in the container.
Definition: UList.H:680
const UList< T > & values
Definition: UList.H:264
OBJstream os(runTime.globalPath()/outputName)
T & reference
The type used for storing into value_type objects.
Definition: UList.H:176
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
std::enable_if< std::is_same< bool, TypeT >::value, bool >::type test(const label i) const
Test bool value at specified position, always false for out-of-range access.
Definition: UList.H:778
static constexpr label max_size() noexcept
The size of the largest possible UList.
Definition: UList.H:690
void moveLast(const label i)
Move element to the last position.
Definition: UList.C:60
T & last()
Access last element of the list, position [size()-1].
Definition: UList.H:876
label size_type
The type to represent the size of a UList.
Definition: UList.H:196
void checkRange(const label start, const label len) const
Check that start and length define a valid range.
Definition: UListI.H:160
unsigned Hasher(const void *data, size_t len, unsigned seed=0)
Bob Jenkins&#39;s 96-bit mixer hashing function (lookup3)
Definition: Hasher.C:575
constexpr UList() noexcept
Default construct, zero-sized and nullptr.
Definition: UListI.H:28
const T * const_iterator
Random access iterator for traversing a UList.
Definition: UList.H:191
Hash function class. The default definition is for primitives. Non-primitives used to hash entries on...
Definition: Hash.H:47
std::streamsize byteSize() const
Number of contiguous bytes for the List data, runtime FatalError if type is not contiguous.
Definition: UList.C:160
bool operator()(const label a, const label b) const
Definition: UList.H:271
void shallowCopy(T *__restrict__ ptr, const label len) noexcept
Copy the pointer and size.
Definition: UListI.H:309
greater(const UList< T > &list)
Definition: UList.H:266
static const UList< T > & null() noexcept
Return a null UList (reference to a nullObject). Behaves like an empty UList.
Definition: UList.H:233
T & back()
Access last element of the list, position [size()-1].
Definition: UListI.H:244
Includes some standard C++ headers, defines global macros and templates used in multiple places by Op...
constexpr label labelMax
Definition: label.H:55
const T & const_reference
The type used for reading from constant value_type objects.
Definition: UList.H:181
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:57
const_iterator cbegin() const noexcept
Return const_iterator to begin traversing the constant UList.
Definition: UListI.H:406
void checkSize(const label size) const
Check size is within valid range [0,size].
Definition: UListI.H:146
label n
void writeEntry(Ostream &os) const
Write the UList with its compound type.
Definition: UListIO.C:30
const T * cdata() const noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:258
void deepCopy(const UList< T > &list)
Copy elements of the given UList. Sizes must match!
Definition: UList.C:98
iterator end() noexcept
Return an iterator to end traversing the UList.
Definition: UListI.H:436
label rcIndex(const label i) const noexcept
The reverse circular index. The previous index in the list which returns to the last at the beginning...
Definition: UListI.H:97
void shuffle(UList< T > &list)
Randomise the list order.
Definition: UList.C:328
void moveFirst(const label i)
Move element to the first position.
Definition: UList.C:48
void checkStart(const label start) const
Check start is within valid range [0,size)
Definition: UListI.H:132
const T & operator()(const T &obj) const
Definition: UList.H:1015
void checkIndex(const label i) const
Check index is within valid range [0,size)
Definition: UListI.H:189
T value_type
The value type the list contains.
Definition: UList.H:161
const T & rcValue(const label i) const
Return reverse circular value (ie, previous value in the list)
Definition: UListI.H:118
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
Definition: UListI.H:286
bool operator>=(const UList< T > &list) const
Return true if !(a < b). Takes linear time.
Definition: UList.C:287
System bool.
Namespace for OpenFOAM.
less(const UList< T > &list)
Definition: UList.H:248
bool operator>(const UList< T > &list) const
Compare two ULists lexicographically. Takes linear time.
Definition: UList.C:273