Loading...
Searching...
No Matches
PtrListDetail< T > Class Template Reference

A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementation detail and should not normally be used other than by OpenFOAM container classes. More...

#include <PtrListDetail.H>

Inherits List< T * >.

Collaboration diagram for PtrListDetail< T >:

Public Member Functions

constexpr PtrListDetail () noexcept
 Default construct.
 PtrListDetail (const label len)
 Construct with specified size, each element initialized to nullptr.
 PtrListDetail (const UList< T * > &list)
 Copy a list of pointers.
 PtrListDetail (const PtrListDetail< T > &list)
 Copy construct (shallow copies addresses).
 PtrListDetail (PtrListDetail< T > &&list) noexcept
 Move construct.
 PtrListDetail (PtrListDetail< T > &list, bool reuse)
 Copy or move (reuse) construct as specified.
const Tget (const label i) const
 Return const pointer to element or nullptr for out-of-range access.
Tget (const label i)
 Return pointer to element or nullptr for out-of-range access.
label count_nonnull () const noexcept
 The number of non-nullptr entries in the list.
void checkNonNull () const
 FatalError if any null exists in the list.
label find_first () const
 Locate the first entry that is non-null.
label find_first_not () const
 Locate the first entry that is null, -1 if there are none (or empty list).
label find_next (label pos) const
 Locate the next non-null entry, starting one beyond the specified position.
label find_next_not (label pos) const
 Locate the next null entry, starting one beyond the specified position.
void free ()
 Delete allocated entries and reassign to nullptr. Does not affect the list size.
template<class... Args>
PtrListDetail< Tclone (Args &&... args) const
 Make a copy by cloning each of the list pointers.
void resize (const label newLen)
 Reset size of list.
void resize_null (const label newLen)
 Set the list to the given size and set all entries to nullptr.
void setAddressableSize (const label n) noexcept
 Set addressed size to be inconsistent with allocated storage.
OstreamprintAddresses (Ostream &os, label maxLen=-1) const
 Write pointer values to Ostream (debugging only).
Ostreamwrite (Ostream &os, const bool trimNull=false) const
 Write output, optionally silently trimming nullptrs.
void operator= (const PtrListDetail< T > &list)
 Copy assignment (shallow copies addresses).
void operator= (PtrListDetail< T > &&list)
 Move assignment.
void operator= (std::nullptr_t)
 Assign all entries to nullptr (without deleting).
void setSize (const label)=delete
void setSize (const label, const T &)=delete
void setSize (const label, const T *)=delete
void resize_nocopy (const label)=delete
template<class... Args>
Foam::Detail::PtrListDetail< Tclone (Args &&... args) const
Public Member Functions inherited from List< T * >
void resize (const label len)
autoPtr< List< T > > clone () const
 Clone.
 ~List ()
 Destructor.
void clear ()
 Clear the list, i.e. set size to zero.
void resize_copy (label count, const label len)
 Change allocated size of list, retaining the first count elements.
void resize_fill (const label len, const T &val)
 Adjust allocated size of list and set val for all elements.
void resize_nocopy (const label len)
 Adjust allocated size of list without necessarily.
void transfer (List< T > &list)
 Transfer the contents of the argument List into this list and annul the argument list.
TnewElmt (const label i)
 Return subscript-checked element of UList and resizing the list if required.
Templace_back (Args &&... args)
 Construct an element at the end of the list, return reference to the new list element.
void push_back (const T &val)
 Append an element at the end of the list.
label push_uniq (const T &val)
 Append an element if not already in the list.
void pop_back (label n=1)
 Reduce size by 1 or more elements. Can be called on an empty list.
void operator= (const UList< T > &list)
 Assignment to UList operator. Takes linear time.
IstreamreadList (Istream &is)
 Read List from Istream, discarding contents of existing List.
void shallowCopy (const UList< T > &)=delete
 No shallowCopy permitted.
bool set (const label i, bool val=true)
 A bitSet::set() method for a list of bool.
void append (const T &val)
 Append an element at the end of the list.
label appendUniq (const T &val)
 Same as push_uniq().
void setSize (label n)
 Alias for resize().
Public Member Functions inherited from UList< T >
 UList (const UList< T > &) noexcept=default
 Copy construct, shallow copy.
 UList (UList< T > &&) noexcept=default
 Move construct, shallow copy.
UList< T > & operator= (const UList< T > &)=delete
 No copy assignment (default: shallow copy).
UList< T > & operator= (UList< T > &&) noexcept=default
 Move assignment, shallow copy.
constexpr UList () noexcept
 Default construct, zero-sized and nullptr.
 UList (T *__restrict__ ptr, const label len) noexcept
 Construct from components.
 UList (SubList< T > &&) noexcept
 Move construct from a SubList, shallow copy.
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 list.
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 of the list.
const TfcValue (const label i) const
 Return forward circular value (ie, next value in the list).
TfcValue (const label i)
 Return forward circular value (ie, next value in the list).
const TrcValue (const label i) const
 Return reverse circular value (ie, previous value in the list).
TrcValue (const label i)
 Return reverse circular value (ie, previous value in the list).
const Tcdata () const noexcept
 Return pointer to the underlying array serving as data storage.
Tdata () noexcept
 Return pointer to the underlying array serving as data storage.
const char * cdata_bytes () const noexcept
 Return pointer to the underlying array serving as data storage,.
char * data_bytes () noexcept
 Return pointer to the underlying array serving as data storage,.
Tfront ()
 Access first element of the list, position [0].
const Tfront () const
 Access first element of the list.
Tback ()
 Access last element of the list, position [size()-1].
const Tback () const
 Access last element of the list, position [size()-1].
std::streamsize size_bytes () const noexcept
 Number of contiguous bytes for the List data.
std::streamsize byteSize () const
 Number of contiguous bytes for the List data, runtime FatalError if type is not contiguous.
void checkStart (const label start) const
 Check start is within valid range [0,size).
void checkSize (const label size) const
 Check size is within valid range [0,size].
void checkRange (const label start, const label len) const
 Check that start and length define a valid range.
void checkIndex (const label i) const
 Check index is within valid range [0,size).
bool uniform () const
 True if all entries have identical values, and list is non-empty.
bool contains (const T &val) const
 True if the value is contained in the list.
bool contains (const T &val, label pos, label len=-1) const
 Is the value contained in the list?
label find (const T &val) const
 Find index of the first occurrence of the value.
label find (const T &val, label pos, label len=-1) const
 Find index of the first occurrence of the value.
label rfind (const T &val, label pos=-1) const
 Find index of the last occurrence of the value.
void moveFirst (const label i)
 Move element to the first position.
void moveLast (const label i)
 Move element to the last position.
void swapFirst (const label i)
 Swap element with the first element. Fatal on an empty list.
void swapLast (const label i)
 Swap element with the last element. Fatal on an empty list.
void shallowCopy (T *__restrict__ ptr, const label len) noexcept
 Copy the pointer and size.
void shallowCopy (std::nullptr_t) noexcept
 Copy nullptr and zero size.
void shallowCopy (const UList< T > &list) noexcept
 Copy the pointer and size held by the given UList.
void deepCopy (const UList< T > &list)
 Copy elements of the given UList. Sizes must match!
template<class Addr>
void deepCopy (const IndirectListBase< T, Addr > &list)
 Copy elements of the given indirect list. Sizes must match!
SubList< Tslice (const label pos, label len=-1)
 Return SubList slice (non-const access) - no range checking.
const SubList< Tslice (const label pos, label len=-1) const
 Return SubList slice (const access) - no range checking.
SubList< Tslice (const labelRange &range)
 Return SubList slice (non-const access) - with range checking.
const SubList< Tslice (const labelRange &range) const
 Return SubList slice (const access) - with range checking.
Toperator[] (const label i)
 Return element of UList.
const Toperator[] (const label i) const
 Return element of constant UList.
 operator const Foam::List< T > & () const
 Allow cast to a const List<T>&.
void operator= (const T &val)
 Assignment of all entries to the given value.
void operator= (Foam::zero)
 Assignment of all entries to zero.
iterator begin () noexcept
 Return an iterator to begin traversing the UList.
iterator end () noexcept
 Return an iterator to end traversing the UList.
iterator begin (const label i) noexcept
 Return iterator at offset i from begin, clamped to [0,size] range.
const_iterator cbegin () const noexcept
 Return const_iterator to begin traversing the constant UList.
const_iterator cend () const noexcept
 Return const_iterator to end traversing the constant UList.
const_iterator begin () const noexcept
 Return const_iterator to begin traversing the constant UList.
const_iterator end () const noexcept
 Return const_iterator to end traversing the constant UList.
const_iterator cbegin (const label i) const noexcept
 Return const_iterator at offset i from begin, clamped to [0,size] range.
const_iterator begin (const label i) const noexcept
 Return const_iterator at offset i from begin, clamped to [0,size] range.
reverse_iterator rbegin ()
 Return reverse_iterator to begin reverse traversing the UList.
reverse_iterator rend ()
 Return reverse_iterator to end reverse traversing the UList.
const_reverse_iterator crbegin () const
 Return const_reverse_iterator to begin reverse traversing the UList.
const_reverse_iterator crend () const
 Return const_reverse_iterator to end reverse traversing the UList.
const_reverse_iterator rbegin () const
 Return const_reverse_iterator to begin reverse traversing the UList.
const_reverse_iterator rend () const
 Return const_reverse_iterator to end reverse traversing the UList.
bool empty () const noexcept
 True if List is empty (ie, size() is zero).
label size () const noexcept
 The number of elements in the container.
label capacity () const noexcept
 Size of the underlying storage.
void swap (UList< T > &list) noexcept
 Swap content with another UList of the same type in constant time.
bool operator== (const UList< T > &list) const
 Equality operation on ULists of the same type.
bool operator!= (const UList< T > &list) const
 The opposite of the equality operation. Takes linear time.
bool operator< (const UList< T > &list) const
 Compare two ULists lexicographically. Takes linear time.
bool operator> (const UList< T > &list) const
 Compare two ULists lexicographically. Takes linear time.
bool operator<= (const UList< T > &list) const
 Return true if !(a > b). Takes linear time.
bool operator>= (const UList< T > &list) const
 Return true if !(a < b). Takes linear time.
IstreamreadList (Istream &is)
 Read List contents from Istream.
void writeEntry (const word &keyword, Ostream &os) const
 Write the List as a dictionary entry with keyword.
OstreamwriteList (Ostream &os, const label shortLen=0) const
 Write List, with line-breaks in ASCII when length exceeds shortLen.
template<class TypeT = T, class = std::enable_if_t<stdFoam::is_bool_v<TypeT>>>
bool all () const
 True if all entries are 'true' or if the list is empty.
template<class TypeT = T, class = std::enable_if_t<stdFoam::is_bool_v<TypeT>>>
bool any () const
 True if any entries are 'true'.
template<class TypeT = T, class = std::enable_if_t<stdFoam::is_bool_v<TypeT>>>
bool none () const
 True if no entries are 'true'.
template<class TypeT = T, class = std::enable_if_t<stdFoam::is_bool_v<TypeT>>>
bool test (const label i) const
 Test bool value at specified position, always false for out-of-range access.
template<class TypeT = T, class = std::enable_if_t<stdFoam::is_bool_v<TypeT>>>
bool get (const label i) const
 Return bool value at specified position, always false for out-of-range access.
template<class TypeT = T, class = std::enable_if_t<stdFoam::is_bool_v<TypeT>>>
bool unset (const label i)
 Unset the bool entry at specified position, always false for out-of-range access.
template<class TypeT = T, class = std::enable_if_t<stdFoam::is_char_v<TypeT>>>
std::string_view view () const
 Return a string_view of the charList. Content is non-modifiable.
Tfirst ()
 Access first element of the list, position [0].
const Tfirst () const
 Access first element of the list.
Tlast ()
 Access last element of the list, position [size()-1].
const Tlast () const
 Access last element of the list, position [size()-1].
bool found (const T &val, label pos=0) const
 Same as contains().
auto expr () const
 Wrap value as expression.
template<typename E>
void operator= (const Expression::ListExpression< E > &expr)
 Assign values from expression.

Additional Inherited Members

Public Types inherited from List< T * >
typedef SubList< TsubList
 Declare type of subList.
Public Types inherited from UList< T >
typedef T value_type
 The value type the list contains.
typedef Tpointer
 The pointer type for non-const access to value_type items.
typedef const Tconst_pointer
 The pointer type for const access to value_type items.
typedef Treference
 The type used for storing into value_type objects.
typedef const Tconst_reference
 The type used for reading from constant value_type objects.
typedef Titerator
 Random access iterator for traversing a UList.
typedef const Tconst_iterator
 Random access iterator for traversing a UList.
typedef label size_type
 The type to represent the size of a UList.
typedef label difference_type
 The difference between iterator objects.
typedef std::reverse_iterator< iteratorreverse_iterator
 Reverse iterator (non-const access).
typedef std::reverse_iterator< const_iteratorconst_reverse_iterator
 Reverse iterator (const access).
using is_List = void
 Have unique tag.
Static Public Member Functions inherited from List< T * >
static const List< T > & null () noexcept
 Return a null List (reference to a nullObject). Behaves like an empty List.
Static Public Member Functions inherited from UList< T >
static const UList< T > & null () noexcept
 Return a null UList (reference to a nullObject). Behaves like an empty UList.
static constexpr label max_size () noexcept
 The size of the largest possible UList.
Protected Member Functions inherited from UList< T >
void setAddressableSize (const label n) noexcept
 Set addressed size to be inconsistent with allocated storage.
void size (const label n)
 Older name for setAddressableSize.
void writeEntry (Ostream &os) const
 Write the UList with its compound type.
labelRange validateRange (const labelRange &requestedRange) const
 Return a validated (start,size) subset range, which means that it always addresses a valid section of the list.
void fill_uniform (const T &val)
 Assign all entries to the given value.
void fill_uniform (Foam::zero)
 Assign all entries to zero.

Detailed Description

template<class T>
class Foam::Detail::PtrListDetail< T >

A rudimentary list of pointers used for PtrList, UPtrList, etc. This class is considered implementation detail and should not normally be used other than by OpenFOAM container classes.

It stores a list of pointers, but makes leaves memory management to the caller or sub-class. The free() method can be used explicitly as required.

Source files

Definition at line 57 of file PtrListDetail.H.

Constructor & Destructor Documentation

◆ PtrListDetail() [1/6]

template<class T>
PtrListDetail ( )
inlineconstexprnoexcept

Default construct.

Definition at line 24 of file PtrListDetailI.H.

References Foam::noexcept, and Foam::T().

Referenced by clone(), operator=(), operator=(), PtrListDetail(), PtrListDetail(), and PtrListDetail().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ PtrListDetail() [2/6]

template<class T>
PtrListDetail ( const label len)
inlineexplicit

Construct with specified size, each element initialized to nullptr.

Definition at line 31 of file PtrListDetailI.H.

References Foam::T().

Here is the call graph for this function:

◆ PtrListDetail() [3/6]

template<class T>
PtrListDetail ( const UList< T * > & list)
inlineexplicit

Copy a list of pointers.

The caller is responsible for memory management.

Definition at line 38 of file PtrListDetailI.H.

References Foam::T(), and UList< T >::UList().

Here is the call graph for this function:

◆ PtrListDetail() [4/6]

template<class T>
PtrListDetail ( const PtrListDetail< T > & list)
inline

Copy construct (shallow copies addresses).

Definition at line 48 of file PtrListDetailI.H.

References PtrListDetail(), and Foam::T().

Here is the call graph for this function:

◆ PtrListDetail() [5/6]

template<class T>
PtrListDetail ( PtrListDetail< T > && list)
inlinenoexcept

Move construct.

Definition at line 58 of file PtrListDetailI.H.

References Foam::noexcept, and PtrListDetail().

Here is the call graph for this function:

◆ PtrListDetail() [6/6]

template<class T>
PtrListDetail ( PtrListDetail< T > & list,
bool reuse )
inline

Copy or move (reuse) construct as specified.

Definition at line 68 of file PtrListDetailI.H.

References PtrListDetail(), and Foam::T().

Here is the call graph for this function:

Member Function Documentation

◆ get() [1/2]

template<class T>
const T * get ( const label i) const
inline

Return const pointer to element or nullptr for out-of-range access.

Definition at line 81 of file PtrListDetailI.H.

References UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ get() [2/2]

template<class T>
T * get ( const label i)
inline

Return pointer to element or nullptr for out-of-range access.

Definition at line 88 of file PtrListDetailI.H.

References UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ count_nonnull()

template<class T>
Foam::label count_nonnull ( ) const
noexcept

The number of non-nullptr entries in the list.

Definition at line 26 of file PtrListDetail.C.

References n, Foam::noexcept, and Foam::T().

Referenced by write().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ checkNonNull()

template<class T>
void checkNonNull ( ) const
inline

FatalError if any null exists in the list.

Definition at line 135 of file PtrListDetailI.H.

References Foam::abort(), Foam::FatalError, FatalErrorInFunction, find_first_not(), and Foam::nl.

Referenced by UPtrList< T >::reorder(), and UPtrList< T >::sortOrder().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_first()

template<class T>
Foam::label find_first ( ) const

Locate the first entry that is non-null.

Returns
the location or -1 if there are no bits set.
Note
Method name as per bitSet

Definition at line 43 of file PtrListDetail.C.

References find_next().

Here is the call graph for this function:

◆ find_first_not()

template<class T>
Foam::label find_first_not ( ) const

Locate the first entry that is null, -1 if there are none (or empty list).

Returns
the location or -1 if the list is empty or all entries are non-null.
Note
Method name as per bitSet, symmetry with find_first()

Definition at line 50 of file PtrListDetail.C.

References find_next_not().

Referenced by checkNonNull().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_next()

template<class T>
Foam::label find_next ( label pos) const

Locate the next non-null entry, starting one beyond the specified position.

Returns
the location or -1 if remaining entries are null.
Note
Method name as per bitSet

Definition at line 57 of file PtrListDetail.C.

References Foam::pos(), and UList< T >::size().

Referenced by find_first().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ find_next_not()

template<class T>
Foam::label find_next_not ( label pos) const

Locate the next null entry, starting one beyond the specified position.

Returns
the location or -1 if remaining entries are non-null.
Note
Method name as per bitSet

Definition at line 75 of file PtrListDetail.C.

References Foam::pos(), and UList< T >::size().

Referenced by find_first_not().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ free()

template<class T>
void free ( )

Delete allocated entries and reassign to nullptr. Does not affect the list size.

Definition at line 93 of file PtrListDetail.C.

References UList< T >::size().

Here is the call graph for this function:

◆ clone() [1/2]

template<class T>
template<class... Args>
PtrListDetail< T > clone ( Args &&... args) const

Make a copy by cloning each of the list pointers.

References args, n, os(), and PtrListDetail().

Here is the call graph for this function:

◆ resize()

template<class T>
void resize ( const label newLen)
inline

Reset size of list.

New entries are initialized to nullptr.

Definition at line 105 of file PtrListDetailI.H.

References List< T >::clear(), List< T >::resize(), UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ resize_null()

template<class T>
void resize_null ( const label newLen)
inline

Set the list to the given size and set all entries to nullptr.

Definition at line 120 of file PtrListDetailI.H.

References List< T >::clear(), List< T >::operator=(), List< T >::resize_nocopy(), and Foam::T().

Here is the call graph for this function:

◆ setAddressableSize()

template<class T>
void setAddressableSize ( const label n)
inlinenoexcept

Set addressed size to be inconsistent with allocated storage.

Use with care

Definition at line 95 of file PtrListDetailI.H.

References n, and UList< T >::setAddressableSize().

Here is the call graph for this function:

◆ printAddresses()

template<class T>
Foam::Ostream & printAddresses ( Ostream & os,
label maxLen = -1 ) const

Write pointer values to Ostream (debugging only).

Optionally allow addressing beyond the regular range

Definition at line 28 of file PtrListDetailIO.C.

References token::BEGIN_LIST, UList< T >::cdata(), token::END_LIST, FUNCTION_NAME, Foam::indent(), Foam::min(), Foam::name(), Foam::nl, os(), and UList< T >::size().

Here is the call graph for this function:

◆ write()

template<class T>
Foam::Ostream & write ( Ostream & os,
const bool trimNull = false ) const

Write output, optionally silently trimming nullptrs.

Definition at line 67 of file PtrListDetailIO.C.

References Foam::abort(), token::BEGIN_LIST, count_nonnull(), Foam::decrIndent(), token::END_LIST, Foam::FatalError, FatalErrorInFunction, FUNCTION_NAME, Foam::incrIndent(), Foam::indent(), Foam::nl, os(), UList< T >::size(), and Foam::T().

Here is the call graph for this function:

◆ operator=() [1/3]

template<class T>
void operator= ( const PtrListDetail< T > & list)
inline

Copy assignment (shallow copies addresses).

Definition at line 151 of file PtrListDetailI.H.

References List< T >::operator=(), and PtrListDetail().

Here is the call graph for this function:

◆ operator=() [2/3]

template<class T>
void operator= ( PtrListDetail< T > && list)
inline

Move assignment.

Definition at line 161 of file PtrListDetailI.H.

References PtrListDetail(), and List< T >::transfer().

Here is the call graph for this function:

◆ operator=() [3/3]

template<class T>
void operator= ( std::nullptr_t )
inline

Assign all entries to nullptr (without deleting).

Definition at line 171 of file PtrListDetailI.H.

References List< T >::operator=(), and Foam::T().

Here is the call graph for this function:

◆ setSize() [1/3]

template<class T>
void setSize ( const label )
delete

◆ setSize() [2/3]

template<class T>
void setSize ( const label ,
const T &  )
delete

References Foam::T().

Here is the call graph for this function:

◆ setSize() [3/3]

template<class T>
void setSize ( const label ,
const T *  )
delete

References Foam::T().

Here is the call graph for this function:

◆ resize_nocopy()

template<class T>
void resize_nocopy ( const label )
delete

◆ clone() [2/2]

template<class T>
template<class... Args>
Foam::Detail::PtrListDetail< T > clone ( Args &&... args) const

Definition at line 109 of file PtrListDetail.C.


The documentation for this class was generated from the following files: