84 #ifndef Foam_UPtrList_H 85 #define Foam_UPtrList_H 96 template<
class T>
class PtrList;
97 template<
class T>
class UPtrList;
98 template<
class T> Ostream& operator<<(Ostream& os, const UPtrList<T>& list);
147 class const_iterator;
156 template<
class Compare>
169 return (a &&
b) ?
comp(*a, *
b) : !
b;
187 const T*
const a =
values.get(ai);
190 return (a &&
b) ? (*a < *
b) : !
b;
206 bool operator()(
const label ai,
const label bi)
const 208 const T*
const a =
values.get(ai);
211 return (a &&
b) ? (*
b < *a) : !a;
222 inline explicit
UPtrList(const label len);
267 inline const
T&
front() const;
273 inline const
T&
back() const;
278 inline const
T*
test(const label i) const;
283 inline const
T*
get(const label i) const;
288 inline
T*
get(const label i);
293 const
T*
set(const label i)
const {
return this->
get(i); }
306 inline void resize(
const label newLen);
336 inline T*
set(
const label i,
T* ptr);
356 inline const T&
at(
const label i)
const;
360 inline T&
at(
const label i);
376 const
T*
operator()(const label i)
const {
return this->
get(i); }
396 template<
bool Const>
class Iterator;
399 friend class Iterator<true>;
402 friend class Iterator<false>;
416 using list_type =
typename std::conditional
457 return *
reinterpret_cast<const Iterator<Any>*
>(
this);
476 return (
pos_ == iter.pos_);
482 return (
pos_ != iter.pos_);
492 class iterator :
public Iterator<false>
537 class const_iterator :
public Iterator<true>
670 template<
class T,
class Compare>
reference val() const
Reference to the object.
list_type * list_
The parent being iterated.
const T & operator[](const label i) const
Return const reference to the element at given position. FatalError for bounds problem or nullptr...
const T * test(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
label key() const noexcept
The iterator position/index within the list.
T & last()
Return reference to the last element of the list.
T & reference
A non-const reference to the value_type.
constexpr iterator() noexcept=default
Default construct - an end iterator.
typename std::conditional< Const, const UPtrList< T >, UPtrList< T > >::type list_type
The list container type.
T & back()
Reference to the last element of the list.
void swap(UPtrList< T > &list) noexcept
Swap content.
void append(T *ptr)
Append an element to the end of the list.
iterator & operator++()
Move to the next non-nullptr entry.
A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementati...
FOAM_DEPRECATED_FOR(2022-09, "get(), set() or test() methods") const T *operator()(const label i) const
Deprecated(2022-09) - same as get()
void reorder(const labelUList &oldToNew, const bool check=false)
Reorder elements. Reordering must be unique (ie, shuffle).
const_iterator & operator++()
Move to the next non-nullptr entry.
constexpr UPtrList() noexcept=default
Default construct.
label count() const noexcept
The number of non-nullptr entries in the list.
T ** begin_ptr() noexcept
Iterator to begin of raw pointers traversal (use with caution)
T & first()
Reference to the first element of the list.
const T * get(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
const T & at(const label i) const
Return const reference to the element at given position. FatalError for bounds problem or nullptr...
T & front()
Reference to the first element of the list.
const UPtrList< T > & values
reference operator()() const
Legacy call operator: reference to the object.
Forward iterator with const access.
greater(const UPtrList< T > &list)
label pos_
The position within the list.
Forward iterator with non-const access.
Internally used base for iterator and const_iterator.
label capacity() const noexcept
Size of the underlying storage.
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.
void free()
Nullify all entries. Does not change the list size.
constexpr Iterator() noexcept
Default construct. Also the same as the end iterator.
T value_type
Type of values the list contains.
reference operator*() const
Reference to the object.
const T & const_reference
A const reference to the value_type.
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
void push_back(T *ptr)
Append an element to the end of the list.
less(const UPtrList< T > &list)
void sort(UList< T > &list)
Sort the list.
pointer operator->() const
Pointer to the referenced object.
label size() const noexcept
The number of entries in the list.
void checkNonNull() const
Check and raise FatalError if any nullptr exists in the list.
label count_nonnull() const noexcept
The number of non-nullptr entries in the list.
void transfer(UPtrList< T > &list)
Transfer contents into this list and annul the argument.
reference val() const
Reference to the object.
bool operator()(const label ai, const label bi) const
Compare dereferenced pointer locations for reverse sort.
T ** end_ptr() noexcept
Iterator beyond end of raw pointers traversal (use with caution)
friend Ostream & operator(Ostream &os, const UPtrList< T > &list)
Write UPtrList to Ostream.
void resize(const label newLen)
Change the size of the list. Any new entries are nullptr.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
bool operator==(const Iterator< Any > &iter) const noexcept
Compare hash-entry element pointers.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
bool operator()(const T *const a, const T *const b) const
Compare dereferenced pointers.
static void check(const int retVal, const char *what)
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
void trimTrailingNull()
Reduce addressable list size to ignore any trailing null pointers.
void operator=(const UPtrList< T > &list)
Copy assignment (shallow copies addresses)
const UPtrList< T > & values
label find_next(label pos) const
The next non-null entry after the specified position.
bool empty() const noexcept
True if the list is empty (ie, size() is zero)
iterator begin()
Return iterator to begin traversal of non-nullptr entries.
A list of pointers to objects of type <T>, with allocation/deallocation management of the pointers...
iterator end() noexcept
Return iterator beyond end of UPtrList traversal.
reference operator()() const
Legacy call operator: reference to the object.
const_iterator cend() const noexcept
Return const_iterator beyond end of UPtrList traversal.
bool good() const noexcept
True if iterator points to a non-null entry.
reference operator*() const
Reference to the object.
const_iterator & operator=(const const_iterator &)=default
Copy assignment.
pointer operator->() const
Pointer to the referenced object.
void clear()
Set list size to zero.
void setSize(const label n)
Alias for resize()
const_iterator cbegin() const
Return const_iterator to begin traversal of non-nullptr entries.
bool operator!=(const Iterator< Any > &iter) const noexcept
void resize_null(const label newLen)
Set the list to the given size and set all entries to nullptr.
label squeezeNull()
Squeeze out nullptr entries in the list of pointers after which any null pointers will be at the end ...
Detail::PtrListDetail< T > ptrs_
The list of pointers.
void setAddressableSize(const label n) noexcept
Adjust addressable size.
A UPtrList compare binary predicate for reverse sort order.
value_compare(const Compare &cmp)
friend class Iterator< false >
Allow iterator access to internals.
const T * set(const label i) const
Return const pointer to element (can be nullptr), or nullptr for out-of-range access (ie...
const_iterator()=default
Default construct (end iterator)
void sortOrder(const labelUList &order, const bool check=false)
Reorder elements according to new order mapping (newToOld). Reordering must be unique (ie...
void increment()
Increment to the next non-null position.
A UPtrList compare binary predicate for normal sort order. Null entries (if any) sort to the end...