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 UList reference to a nullObject
187  inline static const UList<T>& null();
188 
189 
190  // Public Classes
192  //- A list compare binary predicate for normal sort
193  struct less
194  {
195  const UList<T>& values;
197  less(const UList<T>& list)
198  :
199  values(list)
200  {}
202  bool operator()(const label a, const label b) const
203  {
204  return (values[a] < values[b]);
205  }
206  };
207 
208  //- A list compare binary predicate for reverse sort
209  struct greater
210  {
211  const UList<T>& values;
212 
213  greater(const UList<T>& list)
214  :
215  values(list)
216  {}
217 
218  bool operator()(const label a, const label b) const
219  {
220  return (values[b] < values[a]);
221  }
222  };
223 
225  // Generated Methods
226 
227  //- Copy construct
228  UList(const UList<T>&) = default;
229 
230 
231  // Constructors
232 
233  //- Default construct, zero-sized and nullptr
234  inline constexpr UList() noexcept;
235 
236  //- Construct from components
237  inline UList(T* __restrict__ v, const label len) noexcept;
238 
239 
240  // Member Functions
241 
242  // Access
243 
244  //- The forward circular index. The next index in the list
245  //- which returns to the first at the end of the list
246  inline label fcIndex(const label i) const noexcept;
247 
248  //- The reverse circular index. The previous index in the list
249  //- which returns to the last at the beginning of the list
250  inline label rcIndex(const label i) const noexcept;
251 
252  //- Return forward circular value (ie, next value in the list)
253  inline const T& fcValue(const label i) const;
254 
255  //- Return forward circular value (ie, next value in the list)
256  inline T& fcValue(const label i);
257 
258  //- Return reverse circular value (ie, previous value in the list)
259  inline const T& rcValue(const label i) const;
261  //- Return reverse circular value (ie, previous value in the list)
262  inline T& rcValue(const label i);
263 
264  //- Return pointer to the underlying array serving as data storage.
265  inline const T* cdata() const noexcept;
266 
267  //- Return pointer to the underlying array serving as data storage.
268  inline T* data() noexcept;
269 
270  //- Return pointer to the underlying array serving as data storage,
271  // reinterpreted as byte data
272  // \note Only meaningful for contiguous data
273  inline const char* cdata_bytes() const noexcept;
274 
275  //- Return pointer to the underlying array serving as data storage,
276  // reinterpreted as byte data
277  // \note Only meaningful for contiguous data
278  inline char* data_bytes() noexcept;
279 
280  //- Access first element of the list, position [0]
281  inline T& front();
282 
283  //- Access first element of the list
284  inline const T& front() const;
285 
286  //- Access last element of the list, position [size()-1]
287  inline T& back();
288 
289  //- Access last element of the list, position [size()-1]
290  inline const T& back() const;
291 
292  //- Number of contiguous bytes for the List data.
293  // \note Only meaningful for contiguous data
294  inline std::streamsize size_bytes() const noexcept;
295 
296  //- Number of contiguous bytes for the List data,
297  //- runtime FatalError if type is not contiguous
298  std::streamsize byteSize() const;
299 
300 
301  // Check
302 
303  //- Check start is within valid range [0,size)
304  inline void checkStart(const label start) const;
305 
306  //- Check size is within valid range [0,size]
307  inline void checkSize(const label size) const;
308 
309  //- Check that start and length define a valid range
310  inline void checkRange(const label start, const label len) const;
311 
312  //- Check index is within valid range [0,size)
313  inline void checkIndex(const label i) const;
314 
315  //- True if all entries have identical values, and list is non-empty
316  inline bool uniform() const;
317 
318 
319  // Search
320 
321  //- True if the value is contained in the list.
322  inline bool contains(const T& val) const;
323 
324  //- Is the value contained in the list?
325  // \param val The value to search for
326  // \param pos The first position to examine (no-op if -ve)
327  // \param len The length of the search region (-ve until the end)
328  // \return true if found.
329  inline bool contains(const T& val, label pos, label len = -1) const;
330 
331  //- Find index of the first occurrence of the value.
332  // \param val The value to search for
333  // \return position in list or -1 if not found.
334  label find(const T& val) const;
335 
336  //- Find index of the first occurrence of the value.
337  // \param val The value to search for
338  // \param pos The first position to examine (no-op if -ve)
339  // \param len The length of the search region (-ve until the end)
340  // \return position in list or -1 if not found.
341  label find(const T& val, label pos, label len = -1) const;
342 
343  //- Find index of the last occurrence of the value.
344  // Any occurrences after the end pos are ignored.
345  // Linear search.
346  // \return position in list or -1 if not found.
347  label rfind(const T& val, label pos = -1) const;
348 
349 
350  // Edit
351 
352  //- Move element to the first position.
353  void moveFirst(const label i);
354 
355  //- Move element to the last position.
356  void moveLast(const label i);
357 
358  //- Swap element with the first element. Fatal on an empty list.
359  void swapFirst(const label i);
360 
361  //- Swap element with the last element. Fatal on an empty list.
362  void swapLast(const label i);
363 
364 
365  // Copy
366 
367  //- Copy the pointer and size
368  inline void shallowCopy(T* __restrict__ ptr, const label len) noexcept;
369 
370  //- Copy the pointer and size held by the given UList
371  inline void shallowCopy(const UList<T>& list) noexcept;
372 
373  //- Copy elements of the given UList. Sizes must match!
374  void deepCopy(const UList<T>& list);
375 
376  //- Copy elements of the given indirect list. Sizes must match!
377  template<class Addr>
378  void deepCopy(const IndirectListBase<T, Addr>& list);
379 
380 
381  // Other Access
382 
383  //- Return SubList slice (non-const access) - no range checking
384  SubList<T> slice(const label pos, label len = -1);
385 
386  //- Return SubList slice (const access) - no range checking
387  const SubList<T> slice(const label pos, label len = -1) const;
388 
389  //- Return SubList slice (non-const access) - with range checking.
390  // The range is subsetted with the list size itself to ensure that the
391  // result always addresses a valid section of the list.
392  SubList<T> slice(const labelRange& range);
393 
394  //- Return SubList slice (const access) - with range checking.
395  // The range is subsetted with the list size itself to ensure that the
396  // result always addresses a valid section of the list.
397  const SubList<T> slice(const labelRange& range) const;
398 
399 
400  // Member Operators
401 
402  //- Return element of UList
403  inline T& operator[](const label i);
404 
405  //- Return element of constant UList
406  // \note bool specialization adds lazy evaluation so reading an
407  // out-of-range element returns false without ill-effects
408  inline const T& operator[](const label i) const;
409 
410  //- Allow cast to a const List<T>&
411  inline operator const Foam::List<T>&() const;
412 
413  //- Assignment of all entries to the given value
414  inline void operator=(const T& val);
415 
416  //- Assignment of all entries to zero
417  void operator=(const Foam::zero);
418 
419 
420  // Random access iterator (non-const)
421 
422  //- Return an iterator to begin traversing the UList
423  inline iterator begin() noexcept;
424 
425  //- Return an iterator to end traversing the UList
426  inline iterator end() noexcept;
427 
428  //- Return iterator at offset i from begin,
429  //- clamped to [0,size] range
430  inline iterator begin(const label i) noexcept;
431 
432 
433  // Random access iterator (const)
434 
435  //- Return const_iterator to begin traversing the constant UList
436  inline const_iterator cbegin() const noexcept;
437 
438  //- Return const_iterator to end traversing the constant UList
439  inline const_iterator cend() const noexcept;
440 
441  //- Return const_iterator to begin traversing the constant UList
442  inline const_iterator begin() const noexcept;
443 
444  //- Return const_iterator to end traversing the constant UList
445  inline const_iterator end() const noexcept;
446 
447  //- Return const_iterator at offset i from begin,
448  //- clamped to [0,size] range
449  inline const_iterator cbegin(const label i) const noexcept;
450 
451  //- Return const_iterator at offset i from begin,
452  //- clamped to [0,size] range
453  inline const_iterator begin(const label i) const noexcept;
454 
455 
456  // Reverse iterators (non-const)
457 
458  //- Return reverse_iterator to begin reverse traversing the UList
459  inline reverse_iterator rbegin();
460 
461  //- Return reverse_iterator to end reverse traversing the UList
462  inline reverse_iterator rend();
463 
464 
465  // Reverse iterators (const)
466 
467  //- Return const_reverse_iterator to begin reverse traversing the UList
468  inline const_reverse_iterator crbegin() const;
469 
470  //- Return const_reverse_iterator to end reverse traversing the UList
471  inline const_reverse_iterator crend() const;
472 
473  //- Return const_reverse_iterator to begin reverse traversing the UList
474  inline const_reverse_iterator rbegin() const;
475 
476  //- Return const_reverse_iterator to end reverse traversing the UList
477  inline const_reverse_iterator rend() const;
478 
479 
480  // STL member functions
481 
482  //- True if List is empty (ie, size() is zero)
483  bool empty() const noexcept { return !size_; }
484 
485  //- The number of elements in the container
486  label size() const noexcept { return size_; }
487 
488  //- Size of the underlying storage.
489  label capacity() const noexcept { return size_; }
490 
491  //- The size of the largest possible UList
492  static constexpr label max_size() noexcept { return labelMax; }
493 
494  //- Swap content with another UList of the same type in constant time
495  inline void swap(UList<T>& list) noexcept;
496 
497 
498  // STL member operators
499 
500  //- Equality operation on ULists of the same type.
501  // Returns true when the ULists are element-wise equal
502  // (using UList::value_type::operator==). Takes linear time
503  bool operator==(const UList<T>& list) const;
504 
505  //- The opposite of the equality operation. Takes linear time
506  bool operator!=(const UList<T>& list) const;
507 
508  //- Compare two ULists lexicographically. Takes linear time
509  bool operator<(const UList<T>& list) const;
510 
511  //- Compare two ULists lexicographically. Takes linear time
512  bool operator>(const UList<T>& list) const;
513 
514  //- Return true if !(a > b). Takes linear time
515  bool operator<=(const UList<T>& list) const;
516 
517  //- Return true if !(a < b). Takes linear time
518  bool operator>=(const UList<T>& list) const;
519 
520 
521  // Reading/writing
522 
523  //- Read List contents from Istream.
524  // The List must have the proper size before calling
525  Istream& readList(Istream& is);
526 
527  //- Write the List as a dictionary entry with keyword
528  void writeEntry(const word& keyword, Ostream& os) const;
529 
530  //- Write List, with line-breaks in ASCII when length exceeds shortLen.
531  // Using '0' suppresses line-breaks entirely.
532  Ostream& writeList(Ostream& os, const label shortLen=0) const;
533 
534 
535  // IOstream Operators
536 
537  //- Use the readList() method to read contents from Istream.
538  friend Istream& operator>> <T>
539  (
540  Istream& os,
541  UList<T>& list
542  );
543 
544 
545  // Special Methods
546 
547  //- Test \c bool value at specified position,
548  //- always false for out-of-range access.
549  // \note Method name compatibility with bitSet, HashSet
550  template<class TypeT = T>
551  typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
552  inline test(const label i) const
553  {
554  return (i >= 0 && i < size_ && v_[i]);
555  }
556 
557  //- Return \c bool value at specified position,
558  //- always false for out-of-range access.
559  // \note Method name compatibility with bitSet
560  template<class TypeT = T>
561  typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
562  inline get(const label i) const
563  {
564  return (i >= 0 && i < size_ && v_[i]);
565  }
566 
567  //- Unset the \c bool entry at specified position,
568  //- always false for out-of-range access.
569  // \return True if value changed and was not out-of-range
570  // \note Method name compatibility with bitSet
571  template<class TypeT = T>
572  typename std::enable_if<std::is_same<bool, TypeT>::value, bool>::type
573  inline unset(const label i)
574  {
575  if (i >= 0 && i < size_ && v_[i])
576  {
577  v_[i] = false;
578  return true;
579  }
580  return false;
581  }
582 
583 
584  // Hashing
585 
586  //- Hashing functor for UList
587  struct hasher
588  {
589  inline unsigned operator()
590  (
591  const UList<T>& obj,
592  unsigned seed=0
593  ) const
594  {
595  if (is_contiguous<T>::value)
596  {
597  return Foam::Hasher(obj.cdata(), obj.size_bytes(), seed);
598  }
599 
600  Foam::Hash<T> op;
601  for (const T& val : obj)
602  {
603  seed = op(val, seed);
604  }
605  return seed;
606  }
607  };
608 
609  //- Deprecated(2021-04) hashing functor. Use hasher()
610  // \deprecated(2021-04) - use hasher() functor
611  template<class Unused=bool>
612  struct Hash : UList<T>::hasher
613  {
614  FOAM_DEPRECATED_FOR(2021-04, "hasher()") Hash() {}
615  };
616 
617 
618  // Housekeeping
619 
620  //- Access first element of the list, position [0]
621  //FOAM_DEPRECATED_FOR(2022-10, "front()")
622  T& first() { return front(); }
623 
624  //- Access first element of the list
625  //FOAM_DEPRECATED_FOR(2022-10, "front()")
626  const T& first() const { return front(); };
627 
628  //- Access last element of the list, position [size()-1]
629  //FOAM_DEPRECATED_FOR(2022-10, "back()")
630  T& last() { return back(); }
631 
632  //- Access last element of the list, position [size()-1]
633  //FOAM_DEPRECATED_FOR(2022-10, "back()")
634  const T& last() const { return back(); };
635 
636  //- Same as contains()
637  bool found(const T& val, label pos = 0) const
638  {
639  return this->contains(val, pos);
640  }
641 };
642 
643 
644 // * * * * * * * * * * * * Template Specializations * * * * * * * * * * * * //
645 
646 //- Character list writeEntry
647 template<>
648 void UList<char>::writeEntry(Ostream& os) const;
649 
650 //- Character list assign zero - avoids Foam::zero casting ambiguities
651 template<>
653 
654 
655 // * * * * * * * * * * * * * * * IOstream Operators * * * * * * * * * * * * //
656 
657 //- Read List contents from Istream, list must have the proper size!
658 template<class T>
659 Istream& operator>>(Istream& is, UList<T>& list)
660 {
661  return list.readList(is);
662 }
663 
664 
665 //- Write List to Ostream, as per UList::writeList() with default length.
666 // The default short-length is given by Detail::ListPolicy::short_length
667 template<class T>
668 Ostream& operator<<(Ostream& os, const UList<T>& list)
669 {
670  return list.writeList(os, Detail::ListPolicy::short_length<T>::value);
671 }
672 
673 //- Write std::vector to Ostream. ASCII only, no line-breaks
674 template<class T>
675 Ostream& operator<<(Ostream& os, const std::vector<T>& list);
677 
678 // * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * * //
679 
680 //- Fill an identity map with (map[i] == i), works like std::iota().
681 // Optionally with an alternative start index, so that (map[i] == i+start)
682 void identity(UList<int32_t>& map, int32_t start = 0);
683 
684 //- Fill an identity map with (map[i] == i), works like std::iota().
685 // Optionally with an alternative start index, so that (map[i] == i+start)
686 void identity(UList<int64_t>& map, int64_t start = 0);
687 
688 //- Sort the list
689 template<class T>
690 void sort(UList<T>& list);
691 
692 //- Sort the list with the specified comparator
693 template<class T, class Compare>
694 void sort(UList<T>& list, const Compare& comp);
695 
696 //- Stable sort the list
697 template<class T>
698 void stableSort(UList<T>& list);
699 
700 //- Stable sort the list with the specified comparator
701 template<class T, class Compare>
702 void stableSort(UList<T>& list, const Compare& comp);
703 
704 //- Randomise the list order
705 template<class T>
706 void shuffle(UList<T>& list);
707 
708 //- Reverse the first n elements of the list
709 template<class T>
710 inline void reverse(UList<T>& list, const label n);
711 
712 //- Reverse all elements of the list
713 template<class T>
714 inline void reverse(UList<T>& list);
715 
716 
717 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
718 
719 //- Hashing for List data
720 template<class T>
721 struct Hash<UList<T>> : UList<T>::hasher {};
722 
723 
724 //- Object access operator or list access operator (default is pass-through)
725 //- \sa ListListOps::combine()
726 template<class T>
727 struct accessOp
728 {
729  const T& operator()(const T& obj) const { return obj; }
730 };
731 
732 
733 //- Test if object is empty, typically using its empty() method.
734 template<class T>
735 struct emptyOp
736 {
737  bool operator()(const T& obj) const { return obj.empty(); }
738 };
739 
740 
741 //- Extract size (as label) from an object, typically using its size() method.
742 template<class T>
743 struct sizeOp
744 {
745  label operator()(const T& obj) const { return obj.size(); }
746 };
747 
748 
749 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
750 
751 } // End namespace Foam
752 
753 
754 // * * * * * * * * * * * * * * * Global Functions * * * * * * * * * * * * * //
755 
756 // Does not need std::swap or Foam::Swap() specialization
757 // since UList is MoveConstructible and MoveAssignable
758 
759 
760 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
761 
762 #include "UListI.H"
763 
764 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
765 
766 #ifdef NoRepository
767  #include "UList.C"
768  #include "UListIO.C"
769  #include "stdVectorIO.C"
770 #endif
771 
772 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
773 
774 #endif
775 
776 // ************************************************************************* //
void swap(UList< T > &list) noexcept
Swap content with another UList of the same type in constant time.
Definition: UListI.H:505
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:449
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:796
FOAM_DEPRECATED_FOR(2021-04, "hasher()") Hash()
Definition: UList.H:842
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:1026
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:249
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:470
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:666
T * data() noexcept
Return pointer to the underlying array serving as data storage.
Definition: UListI.H:272
T & front()
Access first element of the list, position [0].
Definition: UListI.H:237
T & first()
Access first element of the list, position [0].
Definition: UList.H:853
Object access operator or list access operator (default is pass-through)
Definition: UList.H:1004
bool found(const T &val, label pos=0) const
Same as contains()
Definition: UList.H:879
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:498
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:300
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:286
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:491
const char * cdata_bytes() const noexcept
Return pointer to the underlying array serving as data storage,.
Definition: UListI.H:279
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:97
reverse_iterator rbegin()
Return reverse_iterator to begin reverse traversing the UList.
Definition: UListI.H:456
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:477
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:242
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:111
label capacity() const noexcept
Size of the underlying storage.
Definition: UList.H:676
SubList< T > slice(const label pos, label len=-1)
Return SubList slice (non-const access) - no range checking.
Definition: SubList.H:246
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:520
std::reverse_iterator< iterator > reverse_iterator
Reverse iterator (non-const access)
Definition: UList.H:206
bool operator()(const T &obj) const
Definition: UList.H:1016
iterator begin() noexcept
Return an iterator to begin traversing the UList.
Definition: UListI.H:391
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:671
const UList< T > & values
Definition: UList.H:260
OBJstream os(runTime.globalPath()/outputName)
T & reference
The type used for storing into value_type objects.
Definition: UList.H:176
static const UList< T > & null()
Return a UList reference to a nullObject.
Definition: UListI.H:90
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:769
static constexpr label max_size() noexcept
The size of the largest possible UList.
Definition: UList.H:681
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:867
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:167
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:267
void shallowCopy(T *__restrict__ ptr, const label len) noexcept
Copy the pointer and size.
Definition: UListI.H:316
greater(const UList< T > &list)
Definition: UList.H:262
T & back()
Access last element of the list, position [size()-1].
Definition: UListI.H:251
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:405
void checkSize(const label size) const
Check size is within valid range [0,size].
Definition: UListI.H:153
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:265
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:435
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:104
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:139
const T & operator()(const T &obj) const
Definition: UList.H:1006
void checkIndex(const label i) const
Check index is within valid range [0,size)
Definition: UListI.H:196
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:125
std::streamsize size_bytes() const noexcept
Number of contiguous bytes for the List data.
Definition: UListI.H:293
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:244
bool operator>(const UList< T > &list) const
Compare two ULists lexicographically. Takes linear time.
Definition: UList.C:273