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