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 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 PtrListOps_H
44 #define PtrListOps_H
45 
46 #include "PtrList.H"
47 #include "ListOps.H"
48 
49 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
50 
51 namespace Foam
52 {
53 
54 //- Return (stable) sort order for the list
55 template<class T>
56 labelList sortedOrder(const UPtrList<T>& input);
57 
58 //- Generate (stable) sort order for the list
59 template<class T>
60 void sortedOrder(const UPtrList<T>& input, labelList& order);
61 
62 //- Generate (stable) sort order for the list,
63 //- using the specified list compare predicate
64 template<class T, class ListComparePredicate>
65 void sortedOrder
66 (
67  const UPtrList<T>& input,
68  labelList& order,
69  const ListComparePredicate& comp
70 );
71 
72 
73 //- Inplace (stable) sorting of pointer list.
74 template<class T>
75 void sort(UPtrList<T>& list);
76 
77 //- Inplace (stable) sorting of pointer list.
78 template<class T, class Compare>
79 void sort(UPtrList<T>& list, const Compare& comp);
80 
81 //- Inplace shuffle of pointer list.
82 template<class T>
83 void shuffle(UPtrList<T>& list);
84 
85 
86 /*---------------------------------------------------------------------------*\
87  Namespace PtrListOps Declaration
88 \*---------------------------------------------------------------------------*/
89 
90 namespace PtrListOps
91 {
92 
93 // Public Classes
94 
95 //- A UPtrList compare binary predicate for normal sort.
96 // Null entries sort to the end
97 template<class T>
98 struct less
99 {
101 
102  less(const UPtrList<T>& list)
103  :
104  values(list)
105  {}
106 
107  bool operator()(const label a, const label b) const
108  {
109  const T* const ptr1 = values(a);
110  const T* const ptr2 = values(b);
111 
112  return (ptr1 && ptr2) ? (*ptr1 < *ptr2) : !ptr2;
113  }
114 };
115 
116 
117 //- A UPtrList compare binary predicate for reverse sort.
118 // Null entries sort to the end
119 template<class T>
120 struct greater
121 {
123 
124  greater(const UPtrList<T>& list)
125  :
126  values(list)
127  {}
128 
129  bool operator()(const label a, const label b) const
130  {
131  const T* const ptr1 = values(a);
132  const T* const ptr2 = values(b);
133 
134  return (ptr1 && ptr2) ? (*ptr2 < *ptr1) : !ptr2;
135  }
136 };
137 
138 
139 } // End namespace ListOps
140 
141 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
142 
143 } // End namespace Foam
144 
145 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
146 
147 #ifdef NoRepository
148  #include "PtrListOpsTemplates.C"
149 #endif
150 
151 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
152 
153 #endif
154 
155 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:71
Foam::PtrListOps::less::less
less(const UPtrList< T > &list)
Definition: PtrListOps.H:102
Foam::PtrListOps::less
A UPtrList compare binary predicate for normal sort.
Definition: PtrListOps.H:98
Foam::PtrListOps::greater
A UPtrList compare binary predicate for reverse sort.
Definition: PtrListOps.H:120
Foam::constant::physicoChemical::b
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
Definition: createFields.H:27
Foam::T
void T(FieldField< Field, Type > &f1, const FieldField< Field, Type > &f2)
Definition: FieldFieldFunctions.C:58
Foam::sort
void sort(UList< T > &a)
Definition: UList.C:254
Foam::PtrListOps::greater::values
const UPtrList< T > & values
Definition: PtrListOps.H:122
Foam::UPtrList
A list of pointers to objects of type <T>, without allocation/deallocation management of the pointers...
Definition: UPtrList.H:62
PtrListOpsTemplates.C
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::PtrListOps::less::values
const UPtrList< T > & values
Definition: PtrListOps.H:100
Foam::shuffle
void shuffle(UList< T > &a)
Definition: UList.C:282
Foam::PtrListOps::less::operator()
bool operator()(const label a, const label b) const
Definition: PtrListOps.H:107
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition: IntRanges.C:55
Foam::PtrListOps::greater::operator()
bool operator()(const label a, const label b) const
Definition: PtrListOps.H:129
PtrList.H
Foam::PtrListOps::greater::greater
greater(const UPtrList< T > &list)
Definition: PtrListOps.H:124
ListOps.H
Various functions to operate on Lists.
Foam::sortedOrder
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.