IndirectList.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) 2011-2016 OpenFOAM Foundation
9 Copyright (C) 2017-2022 OpenCFD Ltd.
10-------------------------------------------------------------------------------
11License
12 This file is part of OpenFOAM.
13
14 OpenFOAM is free software: you can redistribute it and/or modify it
15 under the terms of the GNU General Public License as published by
16 the Free Software Foundation, either version 3 of the License, or
17 (at your option) any later version.
18
19 OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22 for more details.
23
24 You should have received a copy of the GNU General Public License
25 along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26
27Class
28 Foam::IndirectList
29
30Description
31 A List with indirect addressing.
32
33See also
34 Foam::UIndirectList for a version without addressing allocation.
35
36Class
37 Foam::UIndirectList
38
39Description
40 A List with indirect addressing.
41 Like IndirectList but does not store addressing
42
43 Note the const_cast of the list values. This is so we can use it both
44 on const and non-const lists. Alternative would be to have a const_
45 variant etc.
46
47SourceFiles
48 IndirectListI.H
49
50\*---------------------------------------------------------------------------*/
51
52#ifndef Foam_IndirectList_H
53#define Foam_IndirectList_H
54
55#include "List.H"
56#include "IndirectListBase.H"
58
59// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
60
61namespace Foam
62{
63
64// Forward Declarations
65template<class T> class IndirectList;
66template<class T> class UIndirectList;
68// Common list types
71
72
73/*---------------------------------------------------------------------------*\
74 Class UIndirectList Declaration
75\*---------------------------------------------------------------------------*/
77template<class T>
78class UIndirectList
79:
80 public IndirectListBase<T, labelUList>
81{
82public:
83
84 // Constructors
86 //- Shallow copy values and addressing
87 UIndirectList(const UList<T>& values, const labelUList& addr)
88 :
90 {}
92 //- Copy construct (shallow copy values and addressing)
94 :
95 UIndirectList<T>(list.values(), list.addressing())
96 {}
97
98
99 // Member Operators
100
101 //- Use standard assignment operations
102 using IndirectListBase<T, labelUList>::operator=;
104 //- Deep copy values, Fatal if list sizes are not identical
105 void operator=(const UIndirectList<T>& rhs)
106 {
107 this->copyList(rhs);
108 }
109};
110
111
112/*---------------------------------------------------------------------------*\
113 Class IndirectList Declaration
114\*---------------------------------------------------------------------------*/
116template<class T>
117class IndirectList
118:
119 private IndirectListAddressing<labelList>,
120 public UIndirectList<T>
121{
122public:
123
124 // Constructors
125
126 //- Copy construct addressing, shallow copy values reference
127 inline IndirectList(const UList<T>& values, const labelUList& addr);
128
129 //- Move construct addressing, shallow copy values reference
130 inline IndirectList(const UList<T>& values, labelList&& addr);
131
132 //- Zero-sized addressing, shallow copy values reference
133 inline IndirectList(const UList<T>& values, const Foam::zero);
134
135 //- Copy construct addressing, shallow copy values reference
136 inline IndirectList(const IndirectList<T>& list);
137
138 //- Move construct addressing, shallow copy values reference
139 inline IndirectList(IndirectList<T>&& list);
140
141 //- Copy construct addressing, shallow copy values reference
142 inline explicit IndirectList(const UIndirectList<T>& list);
143
144
145 // Static Functions
146
147 //- Return an IndirectList comprising entries with \em positions
148 //- that satisfy the condition predicate.
149 //
150 // The condition predicate can be considered a type of \em mask
151 // for any given position.
152 // A boolList, bitSet, labelRange or labelHashSet all satisfy
153 // the requirements for use as position condition predicates.
154 //
155 // \param values The source list values
156 // \param select Accept/reject predicate based on \em position.
157 // \param invert Invert (negate) the selection logic
158 template<class UnaryCondition>
160 (
161 const UList<T>& values,
162 const UnaryCondition& select,
163 const bool invert = false
164 );
165
166 //- Return an IndirectList comprising entries with \em values
167 //- that satisfy the predicate.
168 //
169 // \param values The source list values
170 // \param pred Predicate used to test the \em value
171 // \param invert Invert (negate) the selection logic
172 template<class UnaryPredicate>
174 (
175 const UList<T>& values,
176 const UnaryPredicate& pred,
177 const bool invert = false
178 );
179
180 //- Return an IndirectList with duplicate entries filtered out.
181 // Preserves the original input order, unless sorted = true
182 //
183 // \param values The source list values
184 // \param sorted Retain sorted order instead of original order
185 static IndirectList<T> uniq
186 (
187 const UList<T>& values,
188 const bool sorted = false
189 );
190
191
192 // Member Functions
193
194 //- The list addressing
196
197
198 // Member Operators
199
200 //- Assignment operator
201 using UIndirectList<T>::operator=;
203 //- Deep copy values, Fatal if list sizes are not identical
204 void operator=(const IndirectList<T>& rhs)
205 {
206 this->copyList(rhs);
207 }
208};
209
210
211// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
212
213} // End namespace Foam
214
215// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
216
217#include "IndirectListI.H"
218
219// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
220
221#endif
222
223// ************************************************************************* //
A class for storing list addressing (labels, slices etc), which are normally to used by IndirectList....
const Addr & addressing() const noexcept
Const access to the addressing.
Base for lists with indirect addressing, templated on the list contents type and the addressing type....
void copyList(const ListType &rhs)
Deep copy values from the list.
const labelUList & addressing() const noexcept
The addressing used for the list.
const UList< T > & values() const noexcept
The list of values (without addressing)
A List with indirect addressing.
Definition: IndirectList.H:119
void operator=(const IndirectList< T > &rhs)
Deep copy values, Fatal if list sizes are not identical.
Definition: IndirectList.H:202
static IndirectList< T > uniq(const UList< T > &values, const bool sorted=false)
Return an IndirectList with duplicate entries filtered out.
static IndirectList< T > subset_if(const UList< T > &values, const UnaryPredicate &pred, const bool invert=false)
static IndirectList< T > subset(const UList< T > &values, const UnaryCondition &select, const bool invert=false)
A List with indirect addressing. Like IndirectList but does not store addressing.
Definition: IndirectList.H:79
UIndirectList(const UList< T > &values, const labelUList &addr)
Shallow copy values and addressing.
Definition: IndirectList.H:85
UIndirectList(const UIndirectList< T > &list)
Copy construct (shallow copy values and addressing)
Definition: IndirectList.H:91
void operator=(const UIndirectList< T > &rhs)
Deep copy values, Fatal if list sizes are not identical.
Definition: IndirectList.H:103
A 1D vector of objects of type <T>, where the size of the vector is known and can be used for subscri...
Definition: UList.H:94
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
Definition: zero.H:63
const volScalarField & T
Namespace for OpenFOAM.
UIndirectList< bool > boolUIndList
UIndirectList of bools.
Definition: IndirectList.H:67
labelList invert(const label len, const labelUList &map)
Create an inverse one-to-one mapping.
Definition: ListOps.C:36
UIndirectList< label > labelUIndList
UIndirectList of labels.
Definition: IndirectList.H:68