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 -------------------------------------------------------------------------------
10 License
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 
26 InNamespace
27  Foam
28 
29 Description
30  Functions to operate on Pointer Lists.
31 
32 Namespace
33  Foam::PtrListOps
34 
35 Description
36  Various utility functions to operate on Pointer Lists.
37 
38 SourceFiles
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 
52 namespace Foam
53 {
54 
55 //- Return (stable) sort order for the list
56 template<class T>
57 labelList sortedOrder(const UPtrList<T>& list);
58 
59 //- Generate (stable) sort order for the list
60 template<class T>
61 void sortedOrder(const UPtrList<T>& list, labelList& order);
62 
63 //- Generate (stable) sort order for the list,
64 //- using the specified list compare predicate
65 template<class T, class ListComparePredicate>
66 void sortedOrder
67 (
68  const UPtrList<T>& list,
69  labelList& order,
70  const ListComparePredicate& comp
71 );
72 
73 
74 //- Inplace shuffle of pointer list.
75 template<class T>
76 void shuffle(UPtrList<T>& list);
77 
78 
79 /*---------------------------------------------------------------------------*\
80  Namespace PtrListOps Declaration
81 \*---------------------------------------------------------------------------*/
82 
83 namespace 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
93 template<class ReturnType, class T, class AccessOp>
94 List<ReturnType> get
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
111 template<class T, class UnaryMatchPredicate>
112 List<word> names
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)
121 template<class T>
122 List<word> names(const UPtrList<T>& list);
123 
124 
125 //- Find first list item with 'name()' that matches, -1 on failure
126 template<class T, class UnaryMatchPredicate>
127 label firstMatching
128 (
129  const UPtrList<T>& list,
130  const UnaryMatchPredicate& matcher
131 );
132 
133 
134 //- Extract list indices for all items with 'name()' that matches
135 template<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 // ************************************************************************* //
labelList findMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Extract list indices for all items with &#39;name()&#39; that matches.
List< word > names(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
List of names generated by calling name() for each list item and filtered for matches.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
Various functions to operate on Lists.
List< label > labelList
A List of labels.
Definition: List.H:62
void shuffle(UList< T > &list)
Randomise the list order.
Definition: UList.C:328
Namespace for OpenFOAM.
label firstMatching(const UPtrList< T > &list, const UnaryMatchPredicate &matcher)
Find first list item with &#39;name()&#39; that matches, -1 on failure.