PtrListOps.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) 2019-2022 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
11 This file is part of OpenFOAM.
12
13 OpenFOAM is free software: you can redistribute it and/or modify it
14 under the terms of the GNU General Public License as published by
15 the Free Software Foundation, either version 3 of the License, or
16 (at your option) any later version.
17
18 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21 for more details.
22
23 You should have received a copy of the GNU General Public License
24 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26InNamespace
27 Foam
28
29Description
30 Functions to operate on Pointer Lists.
31
32Namespace
33 Foam::PtrListOps
34
35Description
36 Various utility functions to operate on Pointer Lists.
37
38SourceFiles
39 PtrListOpsTemplates.C
40
41\*---------------------------------------------------------------------------*/
42
43#ifndef Foam_PtrListOps_H
44#define Foam_PtrListOps_H
45
46#include "predicates.H"
47#include "PtrList.H"
48#include "ListOps.H"
49
50// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
51
52namespace Foam
53{
54
55//- Return (stable) sort order for the list
56template<class T>
58
59//- Generate (stable) sort order for the list
60template<class T>
61void sortedOrder(const UPtrList<T>& list, labelList& order);
62
63//- Generate (stable) sort order for the list,
64//- using the specified list compare predicate
65template<class T, class ListComparePredicate>
66void sortedOrder
67(
68 const UPtrList<T>& list,
69 labelList& order,
70 const ListComparePredicate& comp
71);
72
73
74//- Inplace shuffle of pointer list.
75template<class T>
76void shuffle(UPtrList<T>& list);
77
78
79/*---------------------------------------------------------------------------*\
80 Namespace PtrListOps Declaration
81\*---------------------------------------------------------------------------*/
82
83namespace PtrListOps
84{
85
86//- List of values generated by applying the access operation
87//- to each list item.
88//
89// For example,
90// \code
91// PtrListOps::get(mesh.boundaryMesh(), nameOp<polyPatch>());
92// \endcode
93template<class ReturnType, class T, class AccessOp>
95(
96 const UPtrList<T>& list,
97 const AccessOp& aop
98);
99
100
101//- List of names generated by calling \c name() for each list item
102//- and filtered for matches
103//
104// For example,
105// \code
106// wordRes matches(...);
107// PtrListOps::names(mesh.boundaryMesh(), matches);
108//
109// PtrListOps::names(mesh.boundaryMesh(), predicates::always());
110// \endcode
111template<class T, class UnaryMatchPredicate>
113(
114 const UPtrList<T>& list,
115 const UnaryMatchPredicate& matcher
116);
117
118
119//- List of names generated by calling \c name() for each list item
120//- no filtering (ie, predicates::always)
121template<class T>
123
124
125//- Find first list item with 'name()' that matches, -1 on failure
126template<class T, class UnaryMatchPredicate>
128(
129 const UPtrList<T>& list,
130 const UnaryMatchPredicate& matcher
131);
132
133
134//- Extract list indices for all items with 'name()' that matches
135template<class T, class UnaryMatchPredicate>
137(
138 const UPtrList<T>& list,
139 const UnaryMatchPredicate& matcher
140);
141
142} // End namespace ListOps
143
144
145// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146
147} // End namespace Foam
148
149// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
150
151#ifdef NoRepository
152 #include "PtrListOpsTemplates.C"
153#endif
154
155// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
156
157#endif
158
159// ************************************************************************* //
Various functions to operate on Lists.
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:71
List< ReturnType > get(const UPtrList< T > &list, const AccessOp &aop)
labelList findMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Extract list indices for all items with 'name()' that matches.
label firstMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Find first list item with 'name()' that matches, -1 on failure.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Namespace for OpenFOAM.
void shuffle(UList< T > &list)
Randomise the list order.
Definition: UList.C:370
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.