Various utility functions to work on Lists. More...
Classes | |
struct | appendEqOp |
List helper to append y elements onto the end of x. More... | |
struct | greater |
A list compare binary predicate for reverse sort. More... | |
struct | less |
A list compare binary predicate for normal sort. More... | |
struct | unionEqOp |
List helper to add y unique elements to x. More... | |
struct | uniqueEqOp |
List helper to append y unique elements onto the end of x. More... | |
Functions | |
void | identity (labelUList &map, label start=0) |
Fill an identity map with (map[i] == i) More... | |
template<class ListType , class UnaryPredicate > | |
label | count_if (const ListType &input, const UnaryPredicate &pred, const label start=0) |
Count the number of matching entries. More... | |
template<class ListType , class UnaryPredicate > | |
label | find_if (const ListType &input, const UnaryPredicate &pred, const label start=0) |
Find index of the first occurrence that satisfies the predicate. More... | |
template<class ListType , class UnaryPredicate > | |
label | find (const ListType &input, const UnaryPredicate &pred, const label start=0) |
Same as ListOps::find_if. More... | |
template<class ListType , class UnaryPredicate > | |
bool | found_if (const ListType &input, const UnaryPredicate &pred, const label start=0) |
True if there is a value in the list that satisfies the predicate. More... | |
template<class ListType , class UnaryPredicate > | |
bool | found (const ListType &input, const UnaryPredicate &pred, const label start=0) |
Same as found_if. More... | |
template<class ListType , class UnaryPredicate > | |
labelList | findIndices (const ListType &input, const UnaryPredicate &pred, label start=0) |
Linear search to find all occurences of given element. More... | |
template<class T > | |
void | setValue (UList< T > &list, const labelUList &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T > | |
void | setValue (UList< T > &list, const labelHashSet &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T > | |
void | setValue (UList< T > &list, const UList< bool > &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T > | |
void | setValue (UList< T > &list, const bitSet &locations, const T &val) |
Set various locations of the list with a specified value. More... | |
template<class T , class T2 , class UnaryOperation > | |
List< T > | create (const UList< T2 > &input, const UnaryOperation &op) |
Create a List from a List of a dissimilar type, using the entire list. More... | |
template<class T , class InputIterator , class UnaryOperation > | |
List< T > | create (InputIterator first, InputIterator last, const UnaryOperation &op) |
Create a List from an iterator range [first,last) of a dissimilar type. More... | |
template<class T > | |
List< T > | createWithValue (const label len, const labelUList &locations, const T &val, const T &deflt=T()) |
Create a List filled with default values and various locations with another specified value. More... | |
template<class T > | |
List< T > | createWithValue (const label len, const labelHashSet &locations, const T &val, const T &deflt=T()) |
Create a List filled with default values and various locations with another specified value. More... | |
template<class T > | |
List< T > | createWithValue (const label len, const UList< bool > &locations, const T &val, const T &deflt=T()) |
Create a List filled with default values and various locations with another specified value. More... | |
template<class T > | |
List< T > | createWithValue (const label len, const bitSet &locations, const T &val, const T &deflt=T()) |
Create a List filled with default values and various locations with another specified value. More... | |
template<class T > | |
List< T > | createWithValue (const label len, const label index, const T &val, const T &deflt=T()) |
Create a List filled with default values and one specified value, which is copy assigned at the specified index. More... | |
template<class T > | |
List< T > | createWithValue (const label len, const label index, T &&val, const T &deflt=T()) |
Create a List filled with default values and one specified value, which is move assigned at the specified index. More... | |
|
inline |
Fill an identity map with (map[i] == i)
Optionally with an alternative start index, so that (map[i] == i+start)
Definition at line 783 of file ListOps.H.
References Foam::identity().
label Foam::ListOps::count_if | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
const label | start = 0 |
||
) |
Count the number of matching entries.
When start is specified, any occurrences before start are ignored. Linear search. Like std::count_if but works with list indexing
Referenced by cellMapper::cellMapper(), faceMapper::faceMapper(), and pointMapper::pointMapper().
label Foam::ListOps::find_if | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
const label | start = 0 |
||
) |
Find index of the first occurrence that satisfies the predicate.
When start is specified, any occurrences before start are ignored. Linear search. Like std::find_if but works with list indexing.
Referenced by find(), found_if(), and Foam::MatrixTools::pinv().
label Foam::ListOps::find | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
const label | start = 0 |
||
) |
Same as ListOps::find_if.
Definition at line 827 of file ListOps.H.
References find_if(), and Foam::input().
Referenced by distribution::add(), HashTable< const regIOobject * >::at(), IOstreamOption::compressionEnum(), IndirectListBase< T, labelRange >::contains(), scalars::contains(), CircularBuffer< T >::contains(), FixedList< point, 2 >::contains(), string::contains(), UList< Foam::vector >::contains(), HashPtrTable< exprResult >::erase(), HashTable< const regIOobject * >::erase(), objectRegistry::erase(), FixedList< point, 2 >::find(), UList< Foam::vector >::find(), isoSurfaceParams::getFilterType(), HashTable< const regIOobject * >::operator()(), HashPtrTable< exprResult >::release(), HashPtrTable< exprResult >::remove(), string::removeRepeated(), string::replace(), string::replaceAll(), regExpPosix::search(), HashPtrTable< exprResult >::set(), cellTable::setName(), simpleObjectRegistry::setNamedValue(), and simpleObjectRegistry::setValues().
bool found_if | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
const label | start = 0 |
||
) |
True if there is a value in the list that satisfies the predicate.
When start is specified, any occurrences before start are ignored. Linear search.
Definition at line 1172 of file ListOpsTemplates.C.
References find_if(), and Foam::input().
Referenced by found().
bool Foam::ListOps::found | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
const label | start = 0 |
||
) |
Same as found_if.
Definition at line 858 of file ListOps.H.
References found_if(), and Foam::input().
Referenced by starcdWriter::write(), writeObjects::write(), areaWrite::write(), and starcdWriter::writeTemplate().
labelList Foam::ListOps::findIndices | ( | const ListType & | input, |
const UnaryPredicate & | pred, | ||
label | start = 0 |
||
) |
Linear search to find all occurences of given element.
void setValue | ( | UList< T > & | list, |
const labelUList & | locations, | ||
const T & | val | ||
) |
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1233 of file ListOpsTemplates.C.
References UList< T >::size().
void setValue | ( | UList< T > & | list, |
const labelHashSet & | locations, | ||
const T & | val | ||
) |
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1254 of file ListOpsTemplates.C.
References UList< T >::size().
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1275 of file ListOpsTemplates.C.
References Foam::BitOps::count(), stdFoam::end(), Foam::min(), and UList< T >::size().
Set various locations of the list with a specified value.
list | the list to modify |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
Definition at line 1298 of file ListOpsTemplates.C.
References bitSet::find_first(), bitSet::find_next(), Foam::pos(), and UList< T >::size().
List<T> Foam::ListOps::create | ( | InputIterator | first, |
InputIterator | last, | ||
const UnaryOperation & | op | ||
) |
Create a List from an iterator range [first,last) of a dissimilar type.
Uses std::distance for the size.
first | the begin of the iterator range |
last | the end of the iterator range |
op | the unary conversion operator, which can be used to convert to other types. |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const labelUList & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const labelHashSet & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const UList< bool > & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const bitSet & | locations, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and various locations with another specified value.
len | the length of the list |
locations | where to apply the specified value An out-of-range index is silently ignored. |
val | the value to set at the specified locations |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const label | index, | ||
const T & | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and one specified value, which is copy assigned at the specified index.
len | the length of the list |
index | where to apply the specified value. An out-of-range index is silently ignored. |
val | the value to copy assign at the specified index |
deflt | the initialization default value |
List<T> Foam::ListOps::createWithValue | ( | const label | len, |
const label | index, | ||
T && | val, | ||
const T & | deflt = T() |
||
) |
Create a List filled with default values and one specified value, which is move assigned at the specified index.
len | the length of the list |
index | where to apply the specified value. An out-of-range index is silently ignored. |
val | the value to move assign at the specified index |
deflt | the initialization default value |
For example,