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